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)
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))
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))
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
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
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)
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
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
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