def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['zmans_gotten'] = OwedItem.total_getting_count(self.request.user.username) context['gotten_zmans'] = OwedItem.to_get(self.request.user.username, 'zman') context['zmans_owed'] = OwedItem.total_to_give_count(self.request.user.username) context['owed_zmans'] = OwedItem.to_give(self.request.user.username, 'zman') return context
def get_context_data(self, **kwargs): """ Generating variables that end up in the view goes here. """ context = TemplateView.get_context_data(self, **kwargs) self.now = kwargs.get("date", self.now) or self.now if "date" in kwargs and kwargs["date"]: self.now = parse(kwargs["date"]) self.probes = Selector.factory(kwargs["selector"]).get_probes() self.outages = Outages( self.now, self.now + relativedelta(days=1), self.probes, 900, 0.01 ) context["date"] = kwargs.get("date", "") context["selector"] = kwargs["selector"] context["geography"] = self.get_geojson() context["outages"] = self.outages.get() context["log"] = self.get_connection_log(self.outages.events) context["name"] = Selector.get_name(kwargs["selector"]) return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) spirit = get_object_or_404(Spirit, pk=kwargs["pk"]) permissions = { "is_administrator": spirit.owner == self.request.user } context.update({ "spirit": spirit, "elements": { "positive": Element.objects.filter( applications__spirit=spirit, applications__strength__gte=0 ), "negative": Element.objects.filter( applications__spirit=spirit, applications__strength__lt=0 ), }, "permissions": permissions }) return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context.update({ "header": "About Spirithunter", "subheader": "Everything you need to know", }) return context
def get_context_data(self, **kwargs): context = DocumentViewMixin.get_context_data(self, **kwargs) context.update(TemplateView.get_context_data(self, **kwargs)) context['adminform'] = self.create_admin_form() context['form_url'] = self.request.get_full_path() context['tempdoc'] = self.get_temporary_store() context['tempdoc_info'] = self.get_temporary_store()._tempinfo return context
def get_context_data(self,**kwargs): context = TemplateView.get_context_data(self,**kwargs) barcode = self.request.GET.get('barcode',None) try: context['results'] = barcode and cdbazar.audio3.search(ean=barcode)[0] except IOError: context['error'] = "chyba komunikace s audio3" return context
def get_context_data(self,**kwargs): context = TemplateView.get_context_data(self,**kwargs) basket = Basket(self.request) basket.sell() basket._update() context['basket'] = basket context['mediatypes'] = MediaType.objects.all().order_by('order') return context
def get_context_data(self, *args, **kwargs): context = TemplateView.get_context_data(self, *args, **kwargs) context.update(BaseView.get_context_data(self, *args, **kwargs)) contacts = Contact.objects.all() if contacts.exists(): context["contact"] = contacts[0] return context
def get_context_data(self,**kwargs): context = TemplateView.get_context_data(self,**kwargs) context['basket'] = Basket(self.request) context['form'] = self.form context['barcode'] = self.form.is_bound and self.form.cleaned_data['barcode'] context['items'] = self.form.is_bound and Item.objects.filter(barcode=self.form.cleaned_data['barcode'])\ .filter(state__in=(Item.state_for_sale,Item.state_at_stock)) context['sold_items'] = self.form.is_bound and Item.objects.filter(barcode=self.form.cleaned_data['barcode'])\ .filter(state__in=(Item.state_expedited,Item.state_sold)) return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) resp = get_win_details(kwargs['win_id'], self.request) if resp.status_code != 200: raise Http404 context['win'] = resp.json() context['locked'] = locked(context['win']) context['edit_days'] = settings.EDIT_TIMEOUT_DAYS context['win']['date'] = date_parser(context['win']['date']) return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context.update({ "login_form": LoginForm(self.request), "registration_form": RegistrationForm(self.request), "header": "Join Us", "subheader": "Start a collection!", }) return context
def get_context_data(self, **kwargs): self.logger.debug("get_context_data: start") context = TemplateView.get_context_data(self, **kwargs) context.update({ "available_spirits": Spirit.objects.filter( owner=self.request.user, activity=Spirit.ACTIVITY_JARRED, health_current__gt=0 ).prefetch_related("elements", "facets", "nationalities") }) self.logger.debug("get_context_data: stop") return context
def get_context_data(self,**kwargs): context = TemplateView.get_context_data(self,**kwargs) context['title'] = u"K čištění" context['basket'] = Basket(self.request) context['form'] = self.form context['form2'] = self.form2 context['form2_message'] = self.form2_message context['barcode'] = self.barcode context['items'] = self.barcode and Item.objects.filter(barcode=self.barcode) if context['form']: context['form'].legend="" return context
def get_context_data(self, **kwargs): ctx = TemplateView.get_context_data(self, **kwargs) ctx['servers'] = Server.objects.filter( deprecated=False).order_by('name').select_related('location') ctx['applications'] = Application.objects.filter(deprecated=False) ctx['logs'] = GrainLog.objects.all() grainlog = GrainLog.objects.current_grainlog() if grainlog: grain = Grain(grainlog.data()) ctx['grains'] = grain.servers() return ctx
def get_context_data(self, **kwargs): kwargs['roads'] = roads = [] for entry in self.queryset: status = entry.get_latest_status() if status: latest = 'as of ' + status.status_at.strftime('%I:%m %p').strip('0').lower() else: latest = '' roads.append(dict( pk = entry.pk, latest_status = latest, average = entry.get_rate_average(), )) return TemplateView.get_context_data(self, **kwargs)
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context.update({ "debug": settings.DEBUG, "constants": { "Spirit": { "ACTIVITY_FROLIC": Spirit.ACTIVITY_FROLIC, "ACTIVITY_JARRED": Spirit.ACTIVITY_JARRED, "ACTIVITY_WANDER": Spirit.ACTIVITY_WANDER, "ACTIVITY_KILLED": Spirit.ACTIVITY_KILLED, } } }) return context
def get_context_data(self, **kwargs): def my_custom_sql(self): cursor = connection.cursor() cursor.execute("SELECT * FROM ( SELECT usuario.username, log.action_flag, log.object_repr, modelo.model, log.action_time FROM django_admin_log log INNER JOIN auth_user usuario ON log.user_id = usuario.id INNER JOIN django_content_type modelo ON log.content_type_id = modelo.id ORDER BY action_time DESC ) TEST;") #row = cursor.fetchone() desc = cursor.description return [ dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall() ] context = TemplateView.get_context_data(self, **kwargs) context['logs']= my_custom_sql(self) return context
def test_context(self): ## Instantiate object with no context test_view = TemplateReportView(output_filename='output.pdf',template_name='template.rml') ## Compare to results using Django's TemplateView test_view2 = TemplateView(output_filename='output.pdf',template_name='template.rml') ## Test with no context ## get context from each view context1 = test_view.get_context_data() context2 = test_view2.get_context_data() ## remove 'view' key from dictionary, if present try: del context1['view'] del context2['view'] except KeyError: pass ## v1.4 doesn't add this key self.assertEqual(context1, context2) ## Test with additional context items added ## get context from each view context1 = test_view.get_context_data(cv = 'test', cv2 = 'test2') context2 = test_view2.get_context_data(cv = 'test', cv2 = 'test2') ## remove 'view' key from dictionary, if present try: del context1['view'] del context2['view'] except KeyError: pass ## Django v1.4 doesn't add this key self.assertEqual(context1, context2)
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) # get all user's wins url = settings.WINS_AP + '?user__id=' + str(self.request.user.id) win_response = rabbit.get(url, request=self.request).json() wins = win_response['results'] # parse dates for win in wins: win['created'] = date_parser(win['created']) win['date'] = date_parser(win['date']) if win['updated']: win['updated'] = date_parser(win['updated']) win['sent'] = [date_parser(d) for d in win['sent']] if win['responded']: win['responded']['created'] = ( date_parser(win['responded']['created']) ) win['last_modified'] = win['updated'] or win['created'] # split wins up for user into unsent, sent and responded unsent = [w for w in wins if not w['complete']] context['unsent'] = sorted(unsent, key=lambda w: w['last_modified']) responded = [w for w in wins if w['responded']] context['responded'] = sorted( responded, key=lambda w: w['company_name'], ) # skip ones that weren't yet sent as well as not responded yet # better to show not sent wins as a seperate table in UI sent = [ w for w in wins if w['complete'] and w['sent'] and w not in context['responded'] ] context['sent'] = sorted( sent, key=lambda w: w['sent'][0], reverse=True, ) return context
def get_context_data(self,**kwargs): user = self.request.user userProfile, created = UserProfile.objects.get_or_create(user=user) if created: userProfile.save() context = TemplateView.get_context_data(self,**kwargs) context['my_orders'] = Order.objects.filter(user=user) context['form_authentication'] = getattr(self,'form_authentication', UserProfileAuthenticationForm()) context['form_contact'] = getattr(self,'form_contact', UserProfileContactForm(instance=userProfile)) context['form_invoicing'] = getattr(self,'form_invoicing', UserProfileInvoicingForm(instance=userProfile)) context['form_delivery'] = getattr(self,'form_delivery', UserProfileDeliveryForm(instance=userProfile)) context['form_payment'] = getattr(self,'form_payment', UserProfilePaymentForm(instance=userProfile)) return context
def get_context_data(self, **kwargs): delete_empty_transactions() # Maintenance. data = TemplateView.get_context_data(self, **kwargs) data['create_transaction_form'] = forms.CreateTransactionForm( initial={'date': now()}) data['account_list'] = models.Account.objects.all() populate_monthly_amounts(data['account_list']) # Recent operations: N latest operations from now. data['recent_operations'] = models.Operation.objects \ .filter(date__lte=now().date()) \ .order_by('-date')[0:5] # Next operations: N next operations from now. data['next_operations'] = models.Operation.objects \ .filter(date__gt=now().date()) \ .order_by('date')[0:5] # Unbalanced transactions. data['unbalanced_transactions'] = \ models.Transaction.objects.unbalanced()[0:10] self.request.session.setdefault('cart', []) data['cart'] = { 'items': models.Transaction.objects.filter( id__in=self.request.session['cart']), } return data
def get_context_data(self,**kwargs): context = TemplateView.get_context_data(self,**kwargs) gid = self.request.GET.get('gid',None) if gid: try: detail = cdbazar.audio3.Detail(gid) mediaType = MediaType.objects.all().filter(name=detail.type) articleData = dict(title = detail.title, interpret = detail.interpret, year = detail.year, publisher = detail.publisher, mediaType = mediaType and mediaType[0], specification = "", #detail.detail, tracklist = "", #detail.tracklists, origPrice = detail.price, barcode = detail.ean, pictureSource = detail.imgUrl, picture = Picture.loadFromURL(detail.imgUrl), ) if Article.objects.all().filter(barcode=detail.ean).count(): context['result'] = u"artikl s ean: %s už existuje. Přepisuji." % (detail.ean,) for article in Article.objects.all().filter(barcode=detail.ean): for key,value in articleData.items(): setattr(article,key,value) article.save() else: article = Article(**articleData) article.save() context['result'] = u"načteno" except: import traceback import sys traceback.print_exc(file=sys.stdout) #context['error'] = "chyba komunikace s audio3, %s" (sys.exc_info()[0],) context['error'] = "chyba komunikace s audio3" return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['post'] = get_object_or_404(BlogPost.published, pk=kwargs['pk']) return context
def get_context_data(self, *args, **kwargs): context = TemplateView.get_context_data(self, *args, **kwargs) context["openimagecredit_list"] = models.OpenImageCredit.objects.all() return context
def get_context_data(self, *args, **kwargs): context = TemplateView.get_context_data(self, *args, **kwargs) context.update(BaseView.get_context_data(self, *args, **kwargs)) context["images_list"] = Image.objects.all() return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['post_submitted'] = BlogPost.submitted.all() context['post_approved'] = BlogPost.approved.all() return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context["notices"] = Notice.objects.order_by("-id")[:3] context["questions"] = Question.objects.order_by("-id")[:3] return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) return context
def get_context_data(self, **kwargs): data = TemplateView.get_context_data(self, **kwargs) data['barcodes'] = self.generate_new_barcodes( int(self.request.GET['quantity'])) return data
def get_context_data(self, **kwargs): data = TemplateView.get_context_data(self, **kwargs) data["name"] = "some name" data["products"] = Product.objects.all() return data
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context["books"] = Book.objects.all().filter( branch__name__contains='EEE').order_by('id')[:] return context
def get_context_data(self, **kwargs): print(kwargs) print(self.request.GET) print(self.request.POST) return TemplateView.get_context_data(self, **kwargs)
def get_context_data(self, *args, **kwargs): context = TemplateView.get_context_data(self, *args, **kwargs) return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) pvsmatrix = [] pvslist = [] row_count = 0 # pagenation usage col_count = 0 logger.debug('current timezone name %s' % timezone.get_current_timezone_name()) logger.debug('default timezone name %s' % timezone.get_default_timezone_name()) report_expire_time = timezone.make_aware(datetime.now() + timedelta(minutes=-20)) logger.debug( 'report_expire_time: %s, and awared is %s' % (str(report_expire_time), timezone.is_aware(report_expire_time))) logger.debug('TIME_ZONE settings: %s' % getattr(settings, 'TIME_ZONE')) for p_serial in Energy.get_distinct_serial(): p_report = Report.objects.filter(serial=p_serial)[0] tz_local_last_update_time = timezone.localtime( timezone.make_aware(p_report.last_update_time, timezone.utc)) tz_console_last_update_time = timezone.localtime( tz_local_last_update_time, timezone.get_fixed_timezone(timedelta(hours=+8))) logger.debug( 'report time: (%s,%s), expired %s' % (p_report.last_update_time, tz_local_last_update_time, str((tz_local_last_update_time < report_expire_time)))) p_meta = { 'serial': p_serial, 'address': json.loads( p_report.dbconfig).get('accuweather').get('address'), 'public_ip': p_report.ip, 'private_ip': p_report.local_ip, #'url': reverse('user_pvs_view',args=(p_serial,)), 'url': reverse('user_pvs_view') + '#/userSite/' + p_serial, #'last_update_time': p_report.last_update_time.strftime('%Y-%m-%d %H:%M:%S'), 'last_update_time': tz_console_last_update_time.strftime('%Y-%m-%d %H:%M:%S'), 'class_text': 'danger' if (tz_local_last_update_time < report_expire_time) else 'success', 'chart_id': 'chart_id_%s' % p_serial, 'chart_data_var': 'data_%s' % p_serial, 'chart_data_value': json.dumps( PvsManager.prepare_pvs_energy_hourly_output_data( p_serial)), } pvslist.append(p_meta) col_count += 1 if col_count % 3 == 0: pvsmatrix.append(pvslist) pvslist = [] context['pvsmatrix'] = pvsmatrix return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) partners = Partner.objects.all().order_by('priority') context['partners'] = partners return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['account'] = self.account return context
def get_context_data(self, **kwargs): kwargs = TemplateView.get_context_data(self, **kwargs) userpk = kwargs["userpk"] kwargs["user_obj"] = User.objects.get(pk=userpk) return kwargs
def get_context_data(self, **kwargs): #context = super().get_context_data(**kwargs) context = TemplateView.get_context_data(self, **kwargs) context['ineject'] = "Hey I'm context" return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['sandbox'] = self.sandbox context['resource'] = self.resource return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['title'] = 'Add National Bank of Greece account' context['title_icon'] = 'plus' context['form'] = AddNBGAccountForm() return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['employee'] = Employee.objects.get(user=self.request.user) return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context["user"] = Users.objects.get(id=self.kwargs["pk"]) context["pple"] = Users.objects.exclude( id=self.kwargs["pk"]).order_by("id") return context
def get_context_data(self, **kwargs): context = TemplateView.get_context_data(self, **kwargs) context['title'] = 'Add PayPal account' context['title_icon'] = 'plus' context['form'] = AddPayPalAccountForm() return context