Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 16
0
 def get_queryset(self):
     try:
         return SingleObjectMixin.get_queryset(self)
     except AttributeError:
         return self.model.objects()
Exemplo n.º 17
0
 def get_context_data(self, **kwargs):
     return SingleObjectMixin.get_context_data(self, **kwargs)
Exemplo n.º 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
Exemplo n.º 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