Poetry with Poems inLoveLike

Poetic in Nature

SHA2-512 SHA3-512

How_EFTs_are_resold_as_a_file_with_internal_blockchain_of_sources_with_costing_with_Django_3.py

Author: Nathaniel Steven Henry Brown
Started: May 12, 2021
Last Edited: August 17, 2021
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.http import JsonResponse
from django.utils import timezone
import base64
import hashlib
import json

class EftPurchaseFile:
	eft_purchase = EftPurchase
	cache = ''
	response = JsonResponse({})
	sha512 = ''
	base64 = ''
	base64_decoded = ''
	base64_json = ''
	json = ''
	cost = ''
	eft_json = ''
	source_history = []

	def __init__(self, eft_purchase, db_collation=None):
		self.eft_purchase = eft_purchase

		self._base64_decode_and_assign_json()

		self._rebuild_sources()

		self._encode_base64()

		self._calculate_cost()

		self._build_json()

		self._build_response()

		self._build_cache()

	def _build_json(self):
		self.eft_json = {
			'source': settings.HTTPS_BASE_URL,
			'version': settings.EFT_CURRENT_VERSION,
			'sha512': self.sha512,
			'base64': self.base64,
			'cost': self.cost,
		}

	def _build_response(self):
		self.response = JsonResponse(self.eft_json)

	def _build_cache(self):
		self.cache = self.response.content.decode("utf-8")

	def _calculate_sha512(self):
		self.sha512 = hashlib.sha512(self.base64).hexdigest()

	def _encode_base64(self):
		self.base64 = base64.b64encode(self._get_json_as_text().encode('utf-8'))

		self._calculate_sha512()

		# Turn it back into a string
		self.base64 = self.base64.decode('utf-8')

	def _get_json_as_text(self):
		poem_json_text = json.dumps(self.json, cls=DjangoJSONEncoder)
		return poem_json_text

	def _calculate_cost(self):
		self.cost = len(self.base64) * settings.EFT_COST_PER_BYTE

	def _base64_decode_and_assign_json(self):
		self.base64_decoded = base64.b64decode(self.eft_purchase.base64).decode("utf-8") 
		self.base64_json = json.loads(self.base64_decoded)
		self.json = self.base64_json

	def _rebuild_sources(self):
		if self.base64_json.get('source_history'):
			self.source_history = self.base64_json['source_history']
		else:
			self.source_history = []

		source_history_record = {
			'source': self.eft_purchase.source,
			'cost': self.eft_purchase.cost,
			'sha512': self.eft_purchase.sha512,
			'created_on': timezone.now(),
		}

		self.source_history.append(source_history_record)
		
		self.json['source'] = settings.HTTPS_BASE_URL
		self.json['source_history'] = self.source_history


	def get_cache(self):
		return self.cache

	def get_response(self):
		return self.response

	def get_eft_purchase(self):
		return self.eft_purchase
Characters: 2530
Lines: 103
Words: 214

Views: 426

Changes Made

Revision #5
Body
40c40
< eft_json = {
---
> self.eft_json = {
47,48d46
<
< self.eft_json = eft_json
Revision #4
Body
32a33,36
> self._build_json()
>
> self._build_response()
>
35c39
< def _build_cache(self):
---
> def _build_json(self):
46c50,51
< response = JsonResponse(eft_json)
---
> def _build_response(self):
> self.response = JsonResponse(self.eft_json)
48,49c53,54
< self.cache = response.content.decode("utf-8")
< self.response = response
---
> def _build_cache(self):
> self.cache = self.response.content.decode("utf-8")
81,83c86,88
< \'source\': eft_purchase.source,
< \'cost\': eft_purchase.cost,
< \'sha512\': eft_purchase.sha512,
---
> \'source\': self.eft_purchase.source,
> \'cost\': self.eft_purchase.cost,
> \'sha512\': self.eft_purchase.sha512,
Revision #3
Body
12a13,20
> sha512 = \'\'
> base64 = \'\'
> base64_decoded = \'\'
> base64_json = \'\'
> json = \'\'
> cost = \'\'
> eft_json = \'\'
> source_history = []
16a25,69
> self._base64_decode_and_assign_json()
>
> self._rebuild_sources()
>
> self._encode_base64()
>
> self._calculate_cost()
>
> self._build_cache()
>
> def _build_cache(self):
> eft_json = {
> \'source\': settings.HTTPS_BASE_URL,
> \'version\': settings.EFT_CURRENT_VERSION,
> \'sha512\': self.sha512,
> \'base64\': self.base64,
> \'cost\': self.cost,
> }
>
> self.eft_json = eft_json
>
> response = JsonResponse(eft_json)
>
> self.cache = response.content.decode("utf-8")
> self.response = response
>
> def _calculate_sha512(self):
> self.sha512 = hashlib.sha512(self.base64).hexdigest()
>
> def _encode_base64(self):
> self.base64 = base64.b64encode(self._get_json_as_text().encode(\'utf-8\'))
>
> self._calculate_sha512()
>
> # Turn it back into a string
> self.base64 = self.base64.decode(\'utf-8\')
>
> def _get_json_as_text(self):
> poem_json_text = json.dumps(self.json, cls=DjangoJSONEncoder)
> return poem_json_text
>
> def _calculate_cost(self):
> self.cost = len(self.base64) * settings.EFT_COST_PER_BYTE
>
> def _base64_decode_and_assign_json(self):
20a74
> def _rebuild_sources(self):
38,58d91
< poem_json_text = json.dumps(self.json, cls=DjangoJSONEncoder)
< self.base64 = base64.b64encode(poem_json_text.encode(\'utf-8\'))
< self.sha512 = hashlib.sha512(self.base64).hexdigest()
< # Turn it back into a string
< self.base64 = self.base64.decode(\'utf-8\')
< self.cost = len(self.base64) * settings.EFT_COST_PER_BYTE
<
< eft_json = {
< \'source\': settings.HTTPS_BASE_URL,
< \'version\': settings.EFT_CURRENT_VERSION,
< \'sha512\': self.sha512,
< \'base64\': self.base64,
< \'cost\': self.cost,
< }
<
< self.eft_json = eft_json
<
< response = JsonResponse(eft_json)
<
< self.cache = response.content.decode("utf-8")
< self.response = response
Revision #2
Title

1c1
< <code><python>How EFT's are resold as a file with internal blockchain of sources with costing with Django 3</code></python>
---
> <full><code><python>How EFT's are resold as a file with internal blockchain of sources with costing with Django 3</code></python></full>
Revision #1
Title

1c1
< How EFT's are resold as a file with internal blockchain of sources with costing with Django 3
---
> <code><python>How EFT's are resold as a file with internal blockchain of sources with costing with Django 3</code></python>