예제 #1
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)
예제 #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('books'))

        return render(request, 'catalog/book_confirm_delete.html',
                      SingleObjectMixin.get_context_data(self, **kwargs))
예제 #3
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))
예제 #4
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
예제 #5
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
예제 #6
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)
예제 #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):
     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
예제 #9
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
예제 #10
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
예제 #11
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