def submit_master_page(request, workspace_id, module_id, previous_node_id): """ Function will generate the document which will be submitted for processing using the API. """ # Fetch our associated models. workspace = get_object_or_404(Workspace, pk=int_or_none(workspace_id)) module = get_object_or_404(Module, pk=int_or_none(module_id)) # Fetch the document type. document_type_id = module.get_document_type_id() document_type = DocumentType.objects.get(id=document_type_id) # Fetch the document associated with this Module. document, created = Document.objects.get_or_create( workspace=workspace, document_type=document_type, name=document_type.text) # Render the template. return render( request, 'tenant_workspace/module/master/submit/view.html', { 'page': str(workspace), 'workspace': workspace, 'module': module, 'last_node': module.get_last_node(), 'document': document })
def render_question_type_048(workspace, module, node, question, answer): """ DEPENDENCY: - QID: 49 | My target market is based on... - QID: 99 | Total Sales Volume """ # Fetch the dependency answer. q1_qid = int_or_none(question.dependency['q1_qid']) q1_answer = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) q2_qid = int_or_none(question.dependency['q2_qid']) q2_answer = QuestionAnswer.objects.get(question_id=q2_qid, workspace=workspace) # Render our template. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, 'picked_len': len(answer.content), 'q1_answer': q1_answer.content, 'q1_answer_len': len(q1_answer.content), 'q2_answer': q2_answer.content, }
def render_question_type_047(workspace, module, node, question, answer): """ DEPENDENCY: - QID: 32 | Product Categories - QID: 99 | Total Sales Volume """ # Fetch the dependency answer. q1_qid = int_or_none(question.dependency['q1_qid']) q1_answer = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) q2_qid = int_or_none(question.dependency['q2_qid']) q2_answer = QuestionAnswer.objects.get(question_id=q2_qid, workspace=workspace) # Render our template. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, 'q1_answer': q1_answer.content, 'q2_answer': q2_answer.content }
def test_int_or_none(self): # Case 1 of 2: value = int_or_none('3') self.assertEqual(value, 3) # Case 2 of 2: value = int_or_none('') self.assertIsNone(value)
def info_page(request, category_id, resource_id): curr_category = get_object_or_404(InfoResourceCategory, id=int_or_none(category_id)) curr_resource = get_object_or_404(InfoResource, id=int_or_none(resource_id)) return render(request, 'tenant_resource/client/resource/details/info/view.html',{ 'page': 'resource', 'resource': curr_resource, 'categories': InfoResourceCategory.objects.all(), 'tags': Tag.objects.all() })
def task_master_create_page(request): return render( request, 'tenant_task/create/view.html', { 'page': 'tasks', 'sub_page': 'create', 'type_of': int_or_none(request.GET.get('type_of')), 'default_me': int_or_none(request.GET.get('default_me')), 'all_profiles': Me.objects.all(), 'tags': Tag.objects.filter(is_program=True), 'inforesources': InfoResource.objects.all(), })
def start_master_page(request, workspace_id, module_id): workspace = get_object_or_404(Workspace, pk=int_or_none(workspace_id)) module = get_object_or_404(Module, pk=int_or_none(module_id)) # Render our template with our variables. return render( request, 'tenant_workspace/module/master/start/view.html', { 'page': str(workspace), 'workspace': workspace, 'module': module, 'first_node': module.get_first_node() })
def render_question_type_063(workspace, module, node, question, answer): """ Dependency: - Q99 | Total Sales Volume - Q100 """ # For this particular document and module, find the previous questions. q1_qid = int_or_none(question.dependency['q1_qid']) q2_qid = int_or_none(question.dependency['q2_qid']) q3_qid = int_or_none(question.dependency['q3_qid']) sales_volume = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) cogs_volume = QuestionAnswer.objects.get(question_id=q2_qid, workspace=workspace) total_sales = QuestionAnswer.objects.get(question_id=q3_qid, workspace=workspace) # Pre-process values. sales_volume_yr1_total = 0 if sales_volume.content[ 'yr1_total'] == None else sales_volume.content['yr1_total'] sales_volume_yr2_total = 0 if sales_volume.content[ 'yr2_total'] == None else sales_volume.content['yr2_total'] sales_volume_yr3_total = 0 if sales_volume.content[ 'yr3_total'] == None else sales_volume.content['yr3_total'] # Calculate Total COGS volume. total_cogs_volume = { 'yr1': cogs_volume.content['total_cogs_yr1'] * sales_volume_yr1_total, 'yr2': cogs_volume.content['total_cogs_yr2'] * sales_volume_yr2_total, 'yr3': cogs_volume.content['total_cogs_yr3'] * sales_volume_yr3_total } # Calculate gross profit. gross_profit = { 'yr1': total_sales.content['yr1_total'] - total_cogs_volume['yr1'], 'yr2': total_sales.content['yr2_total'] - total_cogs_volume['yr2'], 'yr3': total_sales.content['yr3_total'] - total_cogs_volume['yr3'] } # Save the answer content. answer.content = gross_profit answer.save() # Return result. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, }
def render_question_type_014(workspace, module, node, question, answer): """ DEPENDENCY: - template #001 | QTYPE_ID: 10 | geographic market - template #009 | QTYPE_ID: 11 | geographic market - template #011 | QTYPE_ID: 12 | naics """ picked = answer.content # For this particular document and module, find the previous questions. q1_qid = int_or_none(question.dependency['q1_qid']) q2_qid = int_or_none(question.dependency['q2_qid']) q3_qid = int_or_none(question.dependency['q3_qid']) a1_raw = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) a1 = a1_raw.content a2_raw = QuestionAnswer.objects.get(question_id=q2_qid, workspace=workspace) a2 = a2_raw.content a3_raw = QuestionAnswer.objects.get(question_id=q3_qid, workspace=workspace) a3 = a3_raw.content # 2. Generate geographic info. company_market = a2['var_1'] # 3. Generate industry. naics_id = int(a3['var_5']) naic_option = NAICSOption.objects.get(id=naics_id) companyindustry = naic_option.name # 3. Generate text. mission_statement = _( "To become the company of choice in %(companyindustry)s in the %(companymarket)s market." ) % { 'companyindustry': companyindustry, 'companymarket': company_market } # Render. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': picked, 'default_mission_statement': mission_statement }
def verify_pk(self, signed_id): """ Utility function will read the signed PK, get Django to verify the signature using SECRET_KEY, and return the plaintext PK value. """ pk_string = django_unsign(signed_id) return int_or_none(pk_string)
def detail_page(request, document_id): return render( request, 'tenant_review/detail/view.html', { 'page': 'review', 'document': get_object_or_404(Document, pk=int_or_none(document_id)) })
def handle(self, *args, **options): """ Function will get the inputted tenant name and doc_id and set the database to the tenant schema and begin processing for the particular document. """ schema_name = options['id'][0] doc_id = int_or_none(options['id'][1]) # the tenant metadata is stored. from django.db import connection # Connection will set it back to our tenant. connection.set_schema(schema_name, True) # Switch to Tenant. try: with transaction.atomic(): # Fetch our document. doc = Document.objects.get(id=doc_id) # Take our document and submit the answers to Docxpresso. self.begin_processing(schema_name, doc) except Document.DoesNotExist: raise CommandError(_('Cannot find document #%s.' % doc_id)) except Exception as e: raise CommandError(_('Unknown error occured: %s' % e))
def handle(self, *args, **options): """ Function will get the inputted tenant name and doc_id and set the database to the tenant schema and begin processing for the particular document. """ schema_name = options['id'][0] workspace_id = int_or_none(options['id'][1]) # the tenant metadata is stored. from django.db import connection # Connection will set it back to our tenant. connection.set_schema(schema_name, True) # Switch to Tenant. api = BizmulaAPI(settings.DOCXPRESSO_PUBLIC_KEY, settings.DOCXPRESSO_PRIVATE_KEY, settings.DOCXPRESSO_URL) self.begin_processing(workspace_id, api) # Return a success message to the console. self.stdout.write( self.style.SUCCESS( _('Finished processing stage 8 for workspace_id #%s.') % str(workspace_id)))
def calendar_create_page(request): return render( request, 'tenant_calendar/create/view.html', { 'page': 'calendar', 'all_profiles': Me.objects.all(), 'tags': Tag.objects.filter(is_program=True), 'type_of': int_or_none(request.GET.get('type_of')), 'constants': constants })
def get_by_pk_or_none(self, pk): """ Helper function which gets the HouseSection object by PK parameter or returns None result. """ try: return PublicOrganization.objects.get(pk=int_or_none(pk)) except PublicOrganization.DoesNotExist: return None
def finish_master_page(request, workspace_id, module_id): # Fetch our associated models. workspace = get_object_or_404(Workspace, pk=int_or_none(workspace_id)) module = get_object_or_404(Module, pk=int_or_none(module_id)) # Fetch the document associated with this Module. document_type_id = module.get_document_type_id() document = Document.objects.get(workspace=workspace, document_type_id=document_type_id) # Render the template. return render( request, 'tenant_workspace/module/master/finish/view.html', { 'page': str(workspace), 'workspace': workspace, 'module': module, 'last_node': module.get_last_node(), 'document': document })
def get_by_verifying_pk(self, signed_pk): """ Utility function will attempt to lookup our S3File object based on whether the PK was verified to be authenticate and the PK matches an object in our record. """ pk_string = django_unsign(signed_pk) pk = int_or_none(pk_string) try: return self.get(pk=pk) except S3File.DoesNotExist: return None
def finish_master_page(request, workspace_id, node_id=0): module = get_object_or_404(Module, stage_num=constants.ME_ONBOARDING_STAGE_NUM) node_id = int_or_none(node_id) node = module.get_node(node_id) return render( request, 'tenant_reception/workspace/master/finish_view.html', { 'page': 'workspace', 'workspace_id': workspace_id, 'module': module, 'node_current_position': node_id })
def start_master_page(request, workspace_id): workspace = get_object_or_404(Workspace, pk=int_or_none(workspace_id)) module = get_object_or_404(Module, stage_num=constants.ME_ONBOARDING_STAGE_NUM) first_node = module.get_first_node() return render( request, 'tenant_reception/workspace/master/start_view.html', { 'page': 'workspace', 'workspace': workspace, 'module': module, 'node_current_position': first_node['current_position'] })
def staff_category_details_page(request, category_id): category = get_object_or_404(InfoResourceCategory, id=int_or_none(category_id)) return render( request, 'tenant_resource/staff/category/details/view.html', { 'page': 'resource', 'category': category, 'inforesources': InfoResource.objects.filter(category=category, is_for_staff=True) })
def workspace_detail_page(request, workspace_id, node_id=0): workspace = get_object_or_404(Workspace, pk=int_or_none(workspace_id)) module = get_object_or_404(Module, stage_num=constants.ME_ONBOARDING_STAGE_NUM) node_id = int_or_none(node_id) node = module.get_node(node_id) # Either load up a "Slide" or load up the "Question". if node['type'] == "slide": return render( request, 'tenant_reception/workspace/detail/slide_view.html', { 'page': 'workspace', 'workspace': workspace, 'module': module, 'slide': get_object_or_404(Slide, pk=int_or_none(node['id'])), "node": node, }) elif node['type'] == "question": question = get_object_or_404(Question, pk=int_or_none(node['id'])) document_type = get_object_or_404(DocumentType, pk=int_or_none( node['document_type'])) document, created = Document.objects.get_or_create( workspace=workspace, document_type=document_type, name=str(document_type)) answer, created = QuestionAnswer.objects.get_or_create( workspace=workspace, document=document, question=question) return render( request, 'tenant_reception/workspace/detail/question_view.html', { 'page': 'workspace', 'workspace': workspace, 'module': module, 'question': question, "answer": answer, "node": node }) # Generate a 404 error if the node reached does not have a supported format. raise Http404(_("Unsupported node format detected."))
def render_question_type_034(workspace, module, node, question, answer): """ DEPENDENCY: - QTYPE_ID: 31 | Will you offer mainly products, services, or both - QTYPE_ID: 32 | lease list at least 1, but up to 3 product or service categories that you will offer. """ picked = answer.content OTHER_TEXT = "Other (Please Specify)" # For this particular document and module, find the previous questions. q1_qid = int_or_none(question.dependency['q1_qid']) q2_qid = int_or_none(question.dependency['q2_qid']) a1_raw = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) a1 = a1_raw.content a2_raw = QuestionAnswer.objects.get(question_id=q2_qid, workspace=workspace) a2 = a2_raw.content # 2. Generate info. offer_category = a1['var_1'] offer_1 = a2['var_1'] offer_2 = a2['var_2'] offer_3 = a2['var_3'] # Render. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': picked, "OTHER_TEXT": OTHER_TEXT, 'offer_category': offer_category, 'offer_1': offer_1, 'offer_2': offer_2, 'offer_3': offer_3 }
def resource_master_page(request, category_id): category = get_object_or_404(InfoResourceCategory, id=int_or_none(category_id)) return render( request, 'tenant_reception/resource/master/resource/view.html', { 'page': 'reception-resource-master', 'category': category, 'inforesources': InfoResource.objects.filter( category=category, stage_num__lte=request.tenant_me.stage_num, ) })
def render_question_type_011(workspace, module, node, question, answer): # Fetch the image that is associated with this question's answer. imageupload = None upload_id = answer.content.get('var_2', None) if upload_id: upload_id = int_or_none(upload_id) imageupload = ImageUpload.objects.get(id=upload_id) return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, 'imageupload': imageupload, "OTHER_TEXT": "Other (Please Specify)" }
def category_details_page(request, category_id): category = get_object_or_404(InfoResourceCategory, id=int_or_none(category_id)) inforesources = None if request.tenant_me.is_employee(): inforesources = InfoResource.objects.filter( category=category, is_for_entrepreneur=True ) else: inforesources = InfoResource.objects.filter( category=category, stage_num__lte=request.tenant_me.stage_num, is_for_entrepreneur=True ) return render(request, 'tenant_resource/client/category/details/view.html',{ 'page': 'resource', 'category': category, 'inforesources': inforesources })
def master_page(request, workspace_id): workspace = get_object_or_404(Workspace, pk=int_or_none(workspace_id)) # Return the Module & Documents that are accessible for the highest "stage_num" # that was achieved. modules = Module.objects.filter( stage_num__lte=workspace.stage_num).order_by('stage_num') documents = Document.objects.filter( workspace_id=workspace_id, document_type__stage_num__lte=workspace.stage_num) # Render our view after injecting our data into the template. return render( request, 'tenant_workspace/workspace/master/view.html', { 'page': str(workspace), 'workspace': workspace, 'modules': modules, 'documents': documents, 'mes': Me.objects.all() })
def render_question_type_009(workspace, module, node, question, answer): """ DEPENDENCY: - template #001 | QID: 10 | geographic market """ # For this particular document and module, find the previous question. previous_question_id = int_or_none( question.dependency['previous_question_id']) previous_question_answer = QuestionAnswer.objects.get( question_id=previous_question_id, workspace=workspace) # Input the variables into the template and render the view. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, 'previous_picked': previous_question_answer.content, "OTHER_TEXT": "Other (Please Specify)" }
def render_question_type_055(workspace, module, node, question, answer): """ DEPENDENCY: - QID: 101 | We have taken your material, labour and overhead costs and spread them out based on the volume of product you told us for months 1-36. """ # For this particular document and module, find the previous questions. q1_qid = int_or_none(question.dependency['q1_qid']) # Fetch Q1 q1 = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) dependent_picked = q1.content # View template. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, 'picked_count': len(answer.content), 'dependent_picked': dependent_picked }
def render_question_type_039(workspace, module, node, question, answer): """ DEPENDENCY: - QID: 32 | product categories """ # Fetch the dependency answer. q1_qid = int_or_none(question.dependency['q1_qid']) dependent_answer = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) dependent_answer = dependent_answer.content # Render our template. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'picked': answer.content, 'picked_count': len(answer.content), 'dependent_answer': dependent_answer }
def render_question_type_064(workspace, module, node, question, answer): #QID 165 #===================# # CALCULATE REVENUE # #===================# # Fetch Q1 q1_qid = int_or_none(question.dependency['q1_qid']) q1 = QuestionAnswer.objects.get(question_id=q1_qid, workspace=workspace) q1_picked = q1.content # Fetch Q2 q2_qid = int_or_none(question.dependency['q2_qid']) q2 = QuestionAnswer.objects.get(question_id=q2_qid, workspace=workspace) q2_picked = q2.content # # Debugging Purposes only. # print(q1_picked) # print(q2_picked) # print("\n") # Calculate the revenue. revenue = calculate_revenue(q1_picked, q2_picked) # print(revenue) # print("\n") # Calculate the COGS. cogs = calculate_cogs(q1_picked, q2_picked) # print(cogs) # print("\n") # Calculate labour costs. labour = calculate_labour(q1_picked, q2_picked) # print(labour) # print("\n") # Calculate the materials cost. materials = calculate_materials(q1_picked, q2_picked) # print(materials) # print("\n") # Calculate the overhead cost. overhead = calculate_overhead(q1_picked, q2_picked) # print(overhead) # print("\n") #===================================# # CALCULATE SUM OF GENERAL EXPENSES # #===================================# fixed_costs = {"yr1": 0, "yr2": 0, "yr3": 0, "total": 0} variable_costs = {"yr1": 0, "yr2": 0, "yr3": 0, "total": 0} # Q3 - FETCH q3_qid = int_or_none(question.dependency['q3_qid']) q3 = QuestionAnswer.objects.get(question_id=q3_qid, workspace=workspace) q3_picked = q3.content # Q3 - CALCULATE SUM for item in q3_picked: if item['var_5'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_6']) fixed_costs['yr2'] += float(item['var_7']) fixed_costs['yr3'] += float(item['var_8']) fixed_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) elif item['var_5'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_6']) variable_costs['yr2'] += float(item['var_7']) variable_costs['yr3'] += float(item['var_8']) variable_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) # Q4 - FETCH q4_qid = int_or_none(question.dependency['q4_qid']) q4 = QuestionAnswer.objects.get(question_id=q4_qid, workspace=workspace) q4_picked = q4.content # Q4 - CALCULATE SUM for item in q4_picked: if item['var_5'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_6']) fixed_costs['yr2'] += float(item['var_7']) fixed_costs['yr3'] += float(item['var_8']) fixed_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) elif item['var_5'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_6']) variable_costs['yr2'] += float(item['var_7']) variable_costs['yr3'] += float(item['var_8']) variable_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) # Q5 - FETCH q5_qid = int_or_none(question.dependency['q5_qid']) q5 = QuestionAnswer.objects.get(question_id=q5_qid, workspace=workspace) q5_picked = q5.content # Q5 - CALCULATE SUM for item in q5_picked: if item['var_5'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_6']) fixed_costs['yr2'] += float(item['var_7']) fixed_costs['yr3'] += float(item['var_8']) fixed_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) elif item['var_5'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_6']) variable_costs['yr2'] += float(item['var_7']) variable_costs['yr3'] += float(item['var_8']) variable_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) # Q6 - FETCH q6_qid = int_or_none(question.dependency['q6_qid']) q6 = QuestionAnswer.objects.get(question_id=q6_qid, workspace=workspace) q6_picked = q6.content # Q6 - CALCULATE SUM for item in q6_picked: if item['var_6'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_7']) fixed_costs['yr2'] += float(item['var_8']) fixed_costs['yr3'] += float(item['var_9']) fixed_costs['total'] += float(item['var_7']) + float( item['var_8']) + float(item['var_9']) elif item['var_6'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_7']) variable_costs['yr2'] += float(item['var_7']) variable_costs['yr3'] += float(item['var_8']) variable_costs['total'] += float(item['var_7']) + float( item['var_8']) + float(item['var_9']) # Q7 - FETCH q7_qid = int_or_none(question.dependency['q7_qid']) q7 = QuestionAnswer.objects.get(question_id=q4_qid, workspace=workspace) q7_picked = q7.content # Q7 - CALCULATE SUM for item in q7_picked: if item['var_5'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_6']) fixed_costs['yr2'] += float(item['var_7']) fixed_costs['yr3'] += float(item['var_8']) fixed_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) elif item['var_5'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_6']) variable_costs['yr2'] += float(item['var_7']) variable_costs['yr3'] += float(item['var_8']) variable_costs['total'] += float(item['var_6']) + float( item['var_7']) + float(item['var_8']) # Q8 - FETCH q8_qid = int_or_none(question.dependency['q8_qid']) q8 = QuestionAnswer.objects.get(question_id=q8_qid, workspace=workspace) q8_picked = q8.content # Q8 - CALCULATE SUM for item in q8_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q9 - FETCH q9_qid = int_or_none(question.dependency['q9_qid']) q9 = QuestionAnswer.objects.get(question_id=q9_qid, workspace=workspace) q9_picked = q9.content # Q9 - CALCULATE SUM for item in q9_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q10 - FETCH q10_qid = int_or_none(question.dependency['q10_qid']) q10 = QuestionAnswer.objects.get(question_id=q10_qid, workspace=workspace) q10_picked = q10.content # Q10 - CALCULATE SUM for item in q10_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q11 - FETCH q11_qid = int_or_none(question.dependency['q11_qid']) q11 = QuestionAnswer.objects.get(question_id=q11_qid, workspace=workspace) q11_picked = q11.content # Q11 - CALCULATE SUM for item in q11_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q12 - FETCH q12_qid = int_or_none(question.dependency['q12_qid']) q12 = QuestionAnswer.objects.get(question_id=q12_qid, workspace=workspace) q12_picked = q12.content # Q12 - CALCULATE SUM for item in q12_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q13 - FETCH q13_qid = int_or_none(question.dependency['q13_qid']) q13 = QuestionAnswer.objects.get(question_id=q13_qid, workspace=workspace) q13_picked = q13.content # Q13 - CALCULATE SUM for item in q13_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q14 - FETCH q14_qid = int_or_none(question.dependency['q14_qid']) q14 = QuestionAnswer.objects.get(question_id=q14_qid, workspace=workspace) q14_picked = q14.content # Q14 - CALCULATE SUM for item in q14_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q15 - FETCH q15_qid = int_or_none(question.dependency['q15_qid']) q15 = QuestionAnswer.objects.get(question_id=q15_qid, workspace=workspace) q15_picked = q15.content # Q15 - CALCULATE SUM for item in q15_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q16 - FETCH q16_qid = int_or_none(question.dependency['q16_qid']) q16 = QuestionAnswer.objects.get(question_id=q16_qid, workspace=workspace) q16_picked = q16.content # Q16 - CALCULATE SUM for item in q16_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q17 - FETCH q17_qid = int_or_none(question.dependency['q17_qid']) q17 = QuestionAnswer.objects.get(question_id=q17_qid, workspace=workspace) q17_picked = q17.content # Q17 - CALCULATE SUM for item in q17_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q18 - FETCH q18_qid = int_or_none(question.dependency['q18_qid']) q18 = QuestionAnswer.objects.get(question_id=q18_qid, workspace=workspace) q18_picked = q18.content # Q18 - CALCULATE SUM for item in q18_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q19 - FETCH q19_qid = int_or_none(question.dependency['q19_qid']) q19 = QuestionAnswer.objects.get(question_id=q19_qid, workspace=workspace) q19_picked = q19.content # Q19 - CALCULATE SUM for item in q19_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q20 - FETCH q20_qid = int_or_none(question.dependency['q20_qid']) q20 = QuestionAnswer.objects.get(question_id=q20_qid, workspace=workspace) q20_picked = q20.content # Q20 - CALCULATE SUM for item in q20_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q21 - FETCH q21_qid = int_or_none(question.dependency['q21_qid']) q21 = QuestionAnswer.objects.get(question_id=q21_qid, workspace=workspace) q21_picked = q21.content # Q21 - CALCULATE SUM for item in q21_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q22 - FETCH q22_qid = int_or_none(question.dependency['q22_qid']) q22 = QuestionAnswer.objects.get(question_id=q22_qid, workspace=workspace) q22_picked = q22.content # Q22 - CALCULATE SUM for item in q22_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q23 - FETCH q23_qid = int_or_none(question.dependency['q23_qid']) q23 = QuestionAnswer.objects.get(question_id=q23_qid, workspace=workspace) q23_picked = q23.content # Q23 - CALCULATE SUM for item in q23_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Q24 - FETCH q24_qid = int_or_none(question.dependency['q24_qid']) q24 = QuestionAnswer.objects.get(question_id=q24_qid, workspace=workspace) q24_picked = q24.content # Q24 - CALCULATE SUM for item in q24_picked: if item['var_4'] == FIXED_COST_TYPE: fixed_costs['yr1'] += float(item['var_5']) fixed_costs['yr2'] += float(item['var_6']) fixed_costs['yr3'] += float(item['var_7']) fixed_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) elif item['var_4'] == VARIABLE_COST_TYPE: variable_costs['yr1'] += float(item['var_5']) variable_costs['yr2'] += float(item['var_6']) variable_costs['yr3'] += float(item['var_7']) variable_costs['total'] += float(item['var_5']) + float( item['var_6']) + float(item['var_7']) # Sum the fixed and variables costs together. costs = matrix_add_by(fixed_costs, variable_costs) # Debugging Purposes # print("fixed_costs:", fixed_costs) # print("variable_costs:", variable_costs) # print("costs:", costs) # print("\n") #======================# # CALCULATE SCENERIO 1 # #======================# # "There would be no change" scenario = compute_scenario(revenue, cogs, labour, materials, overhead, costs, fixed_costs, variable_costs) # Save our computation. answer.content = scenario answer.save() # Return result. return { 'workspace': workspace, 'module': module, 'node': node, 'question': question, 'answer': answer, 'scenario': scenario, }