示例#1
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     if self.request.user.is_authenticated():
         context['current_user_subscription'] = getattr(self.request.user, 'subscription', None)
     else:
         context['current_user_subscription'] = None
     return context
示例#2
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     #  объект выбранной версии
     version = Version.objects.select_related("revision").get(id=self.kwargs["version_id"])
     #  список всех полей модели
     fields = [f.name for f in BoatModel._meta.get_fields(include_parents=False)]
     boat = {}
     #  собираем контекст лодки из версии для отображения состояния лодки на момент сохранения
     #  версии
     for fld in fields:
         try:
             boat[fld] = version.field_dict[fld]
         except KeyError:
             boat[fld] = "DoesNotExists"
     boat.update({"author": version.revision.user})
     context.update({"boat": boat, "version": version})
     # самая старая фотка (пока не используется)
     minimal_id = BoatImage.objects.aggregate(min=Min('id', filter=Q(boat_id=self.kwargs[
         "pk"])))
     try:
         #  получаем одну фотку из текущей (выбранной) версии. Объект сохраненной лодки и
         #  объект сохраненного изображения имеют один и тот же revision_id но разный
         #  content_type_id. Через это можно установить взаимосвязь
         image_version = Version.objects.filter(revision_id=version.revision_id,
             content_type_id=ContentType.objects.get(model="boatimage").id).\
             only("object_id").order_by("?").first()
         image = BoatImage.objects.get(pk=image_version.object_id)
         context["image"] = image
     except (ObjectDoesNotExist, AttributeError):
         pass
     return context
示例#3
0
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)

        context['recent_actions'] = self.object.actionrecord_set.all()[:5]
        context['recent_transactions'] = self.object.transaction_set.all()[:5]

        return context
示例#4
0
文件: views.py 项目: llnz/moonbizgame
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     
     context['recent_actions'] = self.object.actionrecord_set.all()[:5]
     context['recent_transactions'] = self.object.transaction_set.all()[:5]
     
     return context
示例#5
0
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)
        context['identity_bill'] = self.kwargs['pk']
        context['products'] = Product.objects.all()
        context['line_bill'] = LineBill.objects.filter(bill=self.object)

        return context
示例#6
0
文件: views.py 项目: MaksUr/catsekb
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context.update(
         get_base_catsekb_context(active_menu=self.active_menu,
                                  extra_title=URL_NAME_SUBJECT_TITLE.format(
                                      subj=self.object.name)))
     return context
示例#7
0
    def get_context_data(self, *args, **kwargs):
        context = DetailView.get_context_data(self, *args, **kwargs)
        context['categories'] = Category.objects.all()

        # context['article'] = Article.objects.filter(category = self.get_object())

        return context
示例#8
0
文件: views.py 项目: ccnmtl/plexus
    def get_context_data(self, *args, **kwargs):
        ctx = DetailView.get_context_data(self, **kwargs)

        grainlog = GrainLog.objects.current_grainlog()
        if grainlog:
            ctx['grains'] = Grain(grainlog.data()).servers()

        return ctx
示例#9
0
 def get_context_data(self, **kwargs):
     data = DetailView.get_context_data(self, **kwargs)
     data['operations'] = self.object.operations.all()
     for operation in data['operations']:
         operation.edit_form = forms.EditOperationForm(instance=operation)
     data['create_operation_form'] = forms.CreateOperationForm(
         initial={'transaction': self.object.pk})
     return data
示例#10
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     if self.request.user.is_authenticated:
         context['user'] = ExtraUser.objects.get(pk=self.request.user.pk)
     context["comments"] = Comment.objects.filter(
         foreignkey_to_article_id=self.kwargs["pk"])
     context["allowed_comments"] = \
        (self.request.get_signed_cookie('allowed_comments', default=None))
     return context
示例#11
0
 def get_context_data(self, *args, **kwargs):
     context = DetailView.get_context_data(self, *args, **kwargs)
     lines = self.get_object().productlist_set.all()
     sum = 0
     for line in lines:
         subsum = line.product.price * line.quantity
         sum += subsum
     context['sum'] = sum
     return context
示例#12
0
    def get_context_data(self, *args, **kwargs):
        context = DetailView.get_context_data(self, *args, **kwargs)

        comment_form_initial = {
            'article': self.get_object()
        }

        context['comment_form'] = CommentForm(initial=comment_form_initial)

        return context
示例#13
0
	def get_context_data(self, **kwargs):
		self.object = self.get_object()
		context = DetailView.get_context_data(self, object=self.object, **kwargs)
		
		try:
			context['ticket_changes'] = backend.get_ticket_changes(self.object)
		except NotImplementedError:
			pass
		
		return context
示例#14
0
文件: views.py 项目: skhal/reader
    def get_context_data(self, *parg, **karg):
        """ Report missing author or missing associated books """

        data = DetailView.get_context_data(self, *parg, **karg)

        if not data["author"]:
            data["error_message"] = "author is not found."
        elif not data["author"].books:
            data["info_message"] = "no books are found for author."

        return data
示例#15
0
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)
        context["categories"] = Category.objects.all()
        context["comments"] = Comment.objects.filter(
            article=self.get_object()).order_by('-date')

        comment_form_initial = {'article': self.get_object()}

        context["comment_form"] = CommentForm(initial=comment_form_initial)

        return context
示例#16
0
文件: views.py 项目: pixmin/poimap
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)
        ticket_valid = True
        if self.get_object().is_validated:
            ticket_valid = False
        else:
            self.object.is_validated = True
            self.object.save()

        context["ticket_valid"] = ticket_valid
        return context
示例#17
0
文件: views.py 项目: pixmin/poimap
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     validation_url = self.request.build_absolute_uri(
         reverse('ticket-validation', args=(self.get_object().num, )))
     img = qrcode.make(validation_url)
     buffer = StringIO.StringIO()
     img.save(buffer, "PNG")
     img_str = base64.b64encode(buffer.getvalue())
     context["qrcode"] = img_str
     context["today"] = datetime.today()
     return context
示例#18
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['products'] = Product.objects.all().order_by('name')
     context['pdf'] = False
     context['form'] = QuotationForm
     allLine = CommandLine.objects.filter(quotation=self.object.id)
     total = 0
     for line in allLine:
         total += line.product.price * line.quantity
     context['total'] = total
     return context
示例#19
0
文件: articles.py 项目: begosha/blogg
 def get(self, request, *args, **kwargs):
     self.object = self.get_object()
     context = DetailView.get_context_data(self, object=self.object)
     context['token'] = self.request.COOKIES['csrftoken']
     try:
         if self.object.post_like.filter(user=self.request.user):
             context['is_liked_post'] = True
         else:
             context['is_liked_post'] = False
     except TypeError:
         return self.render_to_response(context)
     return self.render_to_response(context)
示例#20
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['identity_quot'] = self.kwargs['pk']
     context['status_choices'] = STATUS_CHOICES
     context['payment_choice'] = Bill.PAYMENT_CHOICES
     context['products'] = Product.objects.all()
     context['line_quotation'] = LineQuotation.objects.filter(
         quotation=self.object)
     context["line_quotation_form"] = LineQuotationForm(
         initial={"quotation": self.object})
     context["line_quotation_delete"] = LineQuotationDelete
     return context
示例#21
0
    def get_context_data(self, **kwargs):
        np = get_newspaper(self.newspaper_id())
        year = get_year(self.year_id())
        issue = get_issue(np, year, self.issue_id())

        context = DetailView.get_context_data(self, **kwargs)
        context.update({
            "np": np,
            "year": year,
            "issue": issue,
        })
        return context
示例#22
0
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)
        # We get the language, "fr" by default
        lang = "fr"
        if "lang" in self.request.GET:
            lang = self.request.GET["lang"]
        elif hasattr(self.request, "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in ["fr","en","es"]:
            lang = self.request.LANGUAGE_CODE

        context['uri_labels'] = get_record_uri_labels(self.object,lang)
        
        
        return context
示例#23
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context["blocket"], context['pricelist'], context["cities"] \
         = (boats.utilities.spider(self.kwargs.get("name")))
     rate = boats.utilities.currency_converter(1000)
     context["pricelist_euro"] = []
     for price in context['pricelist']:
             try:
                 context["pricelist_euro"].append(int(price/rate))
             except TypeError:
                 context["pricelist_euro"].append(None)
     cache.set(self.object.id, context["cities"], 60*60*12)
     return context
示例#24
0
文件: views.py 项目: pixmin/poimap
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)
        try:
            context["to_route"] = self.get_object().route_set.get(direction=1)
        except Route.DoesNotExist:
            context["to_route"] = None
        try:
            context["from_route"] = self.get_object().route_set.get(
                direction=2)
        except Route.DoesNotExist:
            context["from_route"] = None

        return context
示例#25
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     period = Config.objects.get(name='active_period').value
     bs = BillingSchedule.objects.get(pk=period)
     business_date = Config.objects.get(name='business_date').value
     business_date = datetime.strptime(business_date,'%Y-%m-%d')
     business_date = business_date.strftime('%b %d, %Y')
     context['period'] = str(bs)
     context['usage'] = bs.reading_start_date.strftime("%b %d, %Y") + " - " + bs.reading_end_date.strftime("%b %d, %Y")
     context['business_date'] = business_date
     context['account'] = context['bill_detail'].account
     context['read_charges'] = context['bill_detail'].meter_read.readcharge_set.order_by('id').all()
     #context['now'] = timezone.now()
     return context
示例#26
0
文件: views.py 项目: MaksUr/catsekb
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context.update(
         get_base_catsekb_context(active_menu=self.active_menu,
                                  extra_title=self.object.title,
                                  project=self.project))
     if self.pagination_order and self.feed_url:
         context['page'] = self.get_page()
         context['feed_per_page'] = FEED_PAGINATE_BY
         context['feed_url'] = reverse(self.feed_url)
     if self.recommendations:
         context['recommendations'] = self.queryset.order_by(
             '?')[:self.recommendations]
     return context
示例#27
0
    def get_context_data(self, **kwargs):
        context = DetailView.get_context_data(self, **kwargs)
        # We get the language, "fr" by default
        lang = "fr"
        if "lang" in self.request.GET:
            lang = self.request.GET["lang"]
        elif hasattr(self.request,
                     "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in [
                         "fr", "en", "es"
                     ]:
            lang = self.request.LANGUAGE_CODE

        context['uri_labels'] = get_record_uri_labels(self.object, lang)

        return context
示例#28
0
    def get_context_data(self, **kwargs):

        if not self.object.is_public:
            if not self.request.user == self.object:
                raise PermissionDenied("This user either doesn't exist or "
                                       "their account is private")

        context = DetailView.get_context_data(self, **kwargs)

        permissions = {
            "is_administrator": self.request.user == self.object
        }
        context.update({
            "permissions": permissions
        })
        return context
示例#29
0
 def get_context_data(self, **kwargs):
     show_permission = self.request.user.is_authenticated
     context = DetailView.get_context_data(self, **kwargs)
     context.update(get_base_catsekb_context(
         active_menu=ANIMALS, extra_title=self.object.__str__()),
                    project='catsekb')
     animal = kwargs[DJ_OBJECT]
     if show_permission is False and animal.show is False:
         raise Http404("Нет прав для просмотра этой страницы")
     animals_query = self.get_animals_query()
     if animals_query:
         animals = get_animals_from_query(animals_query,
                                          show_permission=True)
         context['page'] = self.get_animal_page(animals, animal)
     shelter_animals, shelter_animals_count = get_shelter_animals(
         show_permission=True, count=9)
     context['shelter_animals'] = shelter_animals
     context['shelter_caption'] = 'Ищут дом'
     return context
示例#30
0
文件: views.py 项目: DeppSRL/open-aid
    def get_context_data(self, **kwargs):
        context = super(CodeListView, self).get_context_data(**kwargs)
        context = DetailView.get_context_data(self, **context)

        # adds model name to the context so the app knows which page of codelist it's rendering
        model_name = self.model.__name__.lower()
        context.update({'model_name': model_name})

        year_value = utils.sanitize_get_param(int,
                                              self.request.GET.get('year'),
                                              contexts.END_YEAR,
                                              top=contexts.END_YEAR,
                                              length=4)
        # depending on which codelist page it's rendereing adds top projs or top inits
        if model_name in ['agency', 'aidtype']:
            context['top_projects'] = self.object.top_projects(year=year_value)
        elif model_name in ['recipient', 'sector']:
            top_initiatives = self.object.top_initiatives()
            context['top_initiatives'] = top_initiatives[:settings.
                                                         TOP_ELEMENTS_NUMBER]
            context['top_initiatives_count'] = len(top_initiatives)

        return context
示例#31
0
 def get_context_data(self, **kwargs):
     data = DetailView.get_context_data(self, **kwargs)
     data['operations'] = \
         models.Operation.objects \
                         .filter(account__lft__gte=self.object.lft,
                                 account__rght__lte=self.object.rght,
                                 account__tree_id=self.object.tree_id) \
                         .select_related('transaction')
     max_amount = 0
     for operation in data['operations']:
         operation.relative_width = abs(int(operation.amount / 10))
         if operation.relative_width > max_amount:
             max_amount = operation.relative_width
     for operation in data['operations']:
         try:
             operation.relative_width = int(
                 operation.relative_width * 100 / max_amount)
         except ZeroDivisionError:
             operation.relative_width = 0
         if operation.relative_width == 0 and abs(operation.amount) >= 1:
             operation.relative_width = 1
     data['import_operations_form'] = forms.ImportOperationsForm(
         initial={'account': self.object.pk})
     populate_monthly_amount(data['object'])
     data['descendants'] = data['object'].get_descendants()
     populate_monthly_amounts(data['descendants'])
     month_list = []
     today = now().date()
     account = data['object']
     max_balance = None
     for month_delta in range(-12, 1):
         date_floor = today + relativedelta(months=month_delta)
         date_floor = datetime.date(date_floor.year, date_floor.month, 1)
         date_ceil = date_floor + relativedelta(months=1)
         date_ceil = datetime.date(date_ceil.year, date_ceil.month, 1)
         amount = models.Operation.objects \
             .filter(account__lft__gte=account.lft,
                     account__rght__lte=account.rght,
                     account__tree_id=account.tree_id) \
             .filter(
                 date__gte=date_floor,
                 date__lt=date_ceil) \
             .aggregate(balance=Sum('amount')) \
             .values()[0]
         if amount is None:
             average = decimal.Decimal('0.00')
         else:
             average = amount
             average = average.quantize(decimal.Decimal('0.01'))
         month_list.append({
             'year': date_floor.year,
             'title': date_floor.strftime('%B %Y'),
             'balance': average,
             'relative_balance': 0,
         })
         if abs(average) > max_balance:
             max_balance = abs(average)
     for month in month_list:
         month['relative_balance'] = int(
             abs(month['balance']) * 100 / max_balance)
     data['month_list'] = month_list
     return data
示例#32
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['today'] = date.today()
     return context
示例#33
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['tasks'] = self.object.tasks.all()
     return context
示例#34
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context["categories"] = Category.objects.all()
     return context
示例#35
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['today'] = date.today()
     return context
示例#36
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['tasks'] = self.object.tasks.all()
     context['urgent_tasks'] = self.object.tasks.get_urgent()
     return context
示例#37
0
    def get_context_data(self, **kwargs):        
        
        self.object_list = self.get_queryset()
        if kwargs is None :
            kwargs = {}
        kwargs['object_list'] = self.object_list         

        # Beware: because of multiple inheritance this call MultipleObjectMixin.get_context_data(self, **context)
        context = DetailView.get_context_data(self, **kwargs)
        
        context['notices'] = self.object.notices.select_related().all().prefetch_related('images')[:10]
        context['ancestors'] = self.object.get_ancestors(ascending=True)
                 
        context['filter_form'] = self.get_filter_form()
        context['link_semantic_level_choice'] = TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES
        context['JOCONDE_IMAGE_BASE_URL'] = settings.JOCONDE_IMAGE_BASE_URL
        context['JOCONDE_NOTICE_BASE_URL'] = settings.JOCONDE_NOTICE_BASE_URL
        context['wikipedia_lang_list'] = settings.WIKIPEDIA_URLS.keys()
        context['wikipedia_urls'] = json.dumps(settings.WIKIPEDIA_URLS)
        
        valid_thesaurus_ids = [entry['thesaurus__id'] for entry in Term.objects.root_nodes().values('thesaurus__id').annotate(root_nodes_count=Count('thesaurus__id')).order_by().filter(root_nodes_count__lt=settings.JOCONDE_TERM_TREE_MAX_ROOT_NODE)]  # @UndefinedVariable
        context['term_tree_valid_thesaurus'] = json.dumps(valid_thesaurus_ids)
        if self.selected_thesaurus and self.can_display_level:
            if self.selected_thesaurus.id in valid_thesaurus_ids:
                context['show_levels'] = True
            else:
                context['show_levels'] = False
        else:
            context['show_level'] = False        

        
        field_index = {
            'DOMN' : 1,
            'AUTR' : 3,
            'ECOL' : 4,
            'REPR' : 5,
            'PERI' : 6,
            'EPOQ' : 6,
            'LIEUX': 4,
            'SREP' : 9
        }[self.object.thesaurus.label]
        
        field_name = {
            'SREP' :  u"Source sujet représenté"
        }.get(self.object.thesaurus.label, self.object.thesaurus.label) 

        encoded_label = self.object.label.encode('latin1') if self.object.label is not None else ""
        
        context['encoded_term_label_query_parameter'] = urllib. urlencode({
                'FIELD_%d' % field_index: field_name.encode('latin1'),
                'VALUE_%d' % field_index: encoded_label}).replace('+','%20')
                
        #prev_id, nex_id, prev_page, next_page
        page = context['page_obj']
        
        prev_id = None
        prev_page = 0
        next_id = None
        next_page = 0
        
        
        object_list_ids = [obj.id for obj in list(page.object_list)]
        
        if self.object.id in object_list_ids:
            current_index = object_list_ids.index(self.object.id)

            if current_index > 0:
                prev_id = object_list_ids[current_index-1]
                prev_page = page.number
            elif page.has_previous():
                prev_page = page.previous_page_number()
                prev_id = page.paginator.object_list[page.start_index() - 2].id
    
            if current_index < (len(page)-1):
                next_id = object_list_ids[current_index+1]
                next_page = page.number
            elif page.has_next():
                next_page = page.next_page_number()
                next_id = page.paginator.object_list[page.end_index()].id
        

        context.update({
            'prev_id': prev_id,
            'prev_page': prev_page,
            'next_id': next_id,
            'next_page': next_page
        })
                

        return context 
示例#38
0
文件: generic.py 项目: dmitryro/mqm
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context['show_form'] = self.show_form or context['form'].is_bound
     return context
示例#39
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self)
     context['status_choices'] = STATUS_CHOICES
     context['form'] = QuotationLineForm(initial={"quotation": self.object})
     return context
示例#40
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context["user"] = Users.objects.get(id=self.kwargs["pk"])
     context["transaction"] = Transactions.objects.filter(
         WhomUsers=self.kwargs["pk"])
     return context
示例#41
0
 def get_context_data(self, **kwargs):
     context = djDetailView.get_context_data(self, **kwargs)
     context['laboratory'] = self.lab
     context['datetime'] = timezone.now()
     return context
示例#42
0
 def get_context_data(self, *args, **kwargs):
     context = DetailView.get_context_data(self, *args, **kwargs)
     context["products"] = Product.objects.all()
     context["product_list_form"] = ProductListForm(initial={"quotation" : self.get_object()})
     context["all_status"] = allStatus
     return context
示例#43
0
 def get_context_data(self, *args, **kwargs):
     context = DetailView.get_context_data(self, *args, **kwargs)
     context.update(BaseView.get_context_data(self, *args, **kwargs))
     context["activities"] = Activity.objects.all()
     context["content"] = context["object"]
     return context
示例#44
0
 def get_context_data(self, **kwargs):
     context = DetailView.get_context_data(self, **kwargs)
     context["FormRented"] = FormMovie(initial={"movie" : self.object})
     return context
示例#45
0
 def get_context_data(self, **kwargs):
     context = AdminObjectView.get_context_data(self, **kwargs)
     context.update(DetailView.get_context_data(self, **kwargs))
     return context