Created
July 24, 2019 05:09
-
-
Save rj76/6344608318820c3d0b22aba158e35f89 to your computer and use it in GitHub Desktop.
Order fields available as django template {{ fields }}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctx = {} | |
if request and not isinstance(request.user, AnonymousUser): | |
ctx.update({ | |
'user_email': request.user.email, | |
'username': request.user.username, | |
}) | |
logger.info(ctx) | |
elif request and isinstance(request.user, AnonymousUser): | |
ctx.update({ | |
'user_email': '-', | |
'username': 'AnonymousUser', | |
}) | |
logger.info(ctx) | |
else: | |
ctx.update({ | |
'user_email': '-', | |
'username': 'AnonymousUser', | |
}) | |
# first add all order fields | |
for k in self.get_template_model_fields(): | |
ctx.update({k: '%s' % getattr(self, k)}) | |
# add order start and end date/time | |
ctx.update({ | |
'start_date': self.start_date_text, | |
'start_time': self.start_time_text, | |
'end_date': self.end_date_text, | |
'end_time': self.end_time_text, | |
'customer_id': self.get_customer_id() | |
}) | |
# add org order fields | |
if self.org_order_pk and self.org_member: | |
with tenant_context(org_tenant): | |
try: | |
org_order = Order.objects.get(pk=self.org_order_pk) | |
ctx.update({ | |
'org_order_id': org_order.order_id, | |
'org_order_companycode': org_order.member.companycode, | |
}) | |
except Order.DoesNotExist: | |
pass | |
# add json data from order | |
if self.jsondata: | |
for k, v in self.jsondata.items(): | |
ctx.update({k: v}) | |
# last status | |
last_status = self.get_last_status() | |
if last_status: | |
ctx.update({ | |
'status_date': last_status.status_date_text, | |
'status_time': last_status.status_time_text, | |
}) | |
# add user data | |
active_user = self.get_active_user() | |
if active_user: | |
ctx.update({ | |
'active_user_username': '%s' % active_user['username'], | |
'active_user_email': '%s' % active_user['email'], | |
'active_user_name': '%s' % active_user['name'], | |
}) | |
assigned_user = self.get_assigned_user() | |
if assigned_user: | |
ctx.update({ | |
'assigned_user_username': '%s' % assigned_user['username'], | |
'assigned_user_email': '%s' % assigned_user['email'], | |
'assigned_user_name': '%s' % assigned_user['name'], | |
}) | |
# add address | |
ctx.update({ | |
'order_name': '%s' % self.order_name, | |
'order_address': '%s' % self.order_address, | |
'order_postal': '%s' % self.order_postal, | |
'order_city': '%s' % self.order_city, | |
'order_country_code': '%s' % self.order_country_code, | |
}) | |
# add orderlines | |
orderlines = [] | |
for orderline in self.orderlines.all(): | |
orderlines.append({ | |
'product': orderline.product, | |
'location': orderline.location, | |
'remarks': orderline.remarks, | |
}) | |
ctx.update({'orderlines': orderlines}) | |
# add location | |
ctx.update({'location': '%s' % self.location}) | |
# add companycode | |
ctx.update({'companycode': '%s' % self.member.companycode}) | |
# quotation | |
try: | |
quotation = Quotation.objects.get(order=self) | |
ctx.update({ | |
'quotation_name': '%s' % quotation.quotation_name, | |
'quotation_address': '%s' % quotation.quotation_address, | |
'quotation_postal': '%s' % quotation.quotation_postal, | |
'quotation_city': '%s' % quotation.quotation_city, | |
'quotation_country_code': '%s' % quotation.quotation_country_code, | |
}) | |
except Quotation.DoesNotExist: | |
pass | |
return ctx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment