Пример #1
0
    def get(self, request, *args, **kwargs):
        self.object = SingleObjectMixin.get_object(self)
        if not request.user.has_perm('catalog.can_mark_returned'):
            return HttpResponseRedirect(reverse('books'))

        return render(request, 'catalog/book_confirm_delete.html',
                      SingleObjectMixin.get_context_data(self, **kwargs))
Пример #2
0
    def get(self, request, *args, **kwargs):
        self.object = SingleObjectMixin.get_object(self)
        if not request.user.has_perm('catalog.can_mark_returned'):
            return HttpResponseRedirect(reverse('authors'))

        return render(request, 'catalog/author_form.html',
                      FormMixin.get_context_data(self, **kwargs))
Пример #3
0
    def get_object(self, queryset=None):
        displayInConsole(self)

        obj = SingleObjectMixin.get_object(self, queryset=Quiz.objects.all())

        if obj.isAvailableFor(self.request.user, 'visibility'):
            return obj
Пример #4
0
 def value(self, view: SingleObjectMixin) -> Optional[datetime.datetime]:
     obj = view.get_object()
     if not hasattr(view.model, self.last_modified_field):
         raise ImproperlyConfigured(
             f"{view.model} does not have a field named {self.last_modified_field}."
         )
     return getattr(obj, self.last_modified_field)
Пример #5
0
 def get_context_object_name(self, obj):
     """
     Get the name to use for the object.
     """
     try:
         return SingleObjectMixin.get_context_object_name(self, obj)
     except AttributeError:
         return "object"
Пример #6
0
 def get_object(self, queryset=None):   
     self.object = None
     user = self.request.user
     obj = SingleObjectMixin.get_object(self, queryset)
     owner = getattr(obj, self.object_ownership_check, None)
     if owner is None or owner != user:            
         raise Http404(u"User is not allowed") 
     return obj
Пример #7
0
 def get_object(self, queryset=None):
     if issubclass(get_entry_model(), TranslatableModel):
         # Filter by slug and language
         # Note that translation support is still optional,
         # even though the class inheritance includes it.
         return TranslatableSlugMixin.get_object(self, queryset)
     else:
         # Regular slug check, skip TranslatableSlugMixin
         return SingleObjectMixin.get_object(self, queryset)
Пример #8
0
 def get_object(self, queryset=None):
     if issubclass(get_entry_model(), TranslatableModel):
         # Filter by slug and language
         # Note that translation support is still optional,
         # even though the class inheritance includes it.
         return TranslatableSlugMixin.get_object(self, queryset)
     else:
         # Regular slug check, skip TranslatableSlugMixin
         return SingleObjectMixin.get_object(self, queryset)
Пример #9
0
 def get_object(self):
     user = SingleObjectMixin.get_object(self)
     (obj, new) = self.request.user.friends.get_or_create(user=user)
     if new:
         messages.success(self.request,
                          "Friendship created with %s" % str(user))
     else:
         messages.error(self.request,
                        "Already a friend with %s" % str(user))
     return user
Пример #10
0
 def get_owner_object(self, queryset=None):
     object = SingleObjectMixin.get_object(self, queryset=queryset)
     if getattr(object, cls.owner_field_name) == self.request.user:
         return object
     else:
         raise Http404
Пример #11
0
 def get_context_data(self, **kwargs):
     extra = self.get_extra_context_data()
     context = SingleObjectMixin.get_context_data(self, **kwargs)
     context.update(extra)
     return context
Пример #12
0
 def get_object(self):
     user = SingleObjectMixin.get_object(self)
     self.request.user.friends.filter(user=user).delete()
     messages.success(self.request,
                      "Friendship removed from %s" % str(user))
     return user
Пример #13
0
 def get_context_data(self, **kwargs):
     extra = self.get_extra_context_data()
     context = SingleObjectMixin.get_context_data(self, **kwargs)
     context.update(extra)
     return context
Пример #14
0
 def get_context_data(self, **kwargs):
     data = SingleObjectMixin.get_context_data(self, **kwargs)
     data.update(FacebookViewMixin.get_context_data(self, **kwargs))
     return data
Пример #15
0
 def get_owner_object(self, queryset=None):
     object = SingleObjectMixin.get_object(self, queryset=queryset)
     if getattr(object, cls.owner_field_name) == self.request.user:
         return object
     else:
         raise Http404
Пример #16
0
 def get_queryset(self):
     try:
         return SingleObjectMixin.get_queryset(self)
     except AttributeError:
         return self.model.objects()
Пример #17
0
 def get_context_data(self, **kwargs):
     return SingleObjectMixin.get_context_data(self, **kwargs)
Пример #18
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     context.update(SingleObjectMixin.get_context_data(self, **kwargs))
     return context
Пример #19
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     context.update(SingleObjectMixin.get_context_data(self, **kwargs))
     return context