Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
7f7467df
Commit
7f7467df
authored
5 months ago
by
Roang
Browse files
Options
Downloads
Patches
Plain Diff
Add SingleUUIDObjectMixin
We can use this mixin to get an object by its UUID in the URLconf.
parent
b2e27ad6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backoffice/views/mixins.py
+32
-1
32 additions, 1 deletion
src/backoffice/views/mixins.py
with
32 additions
and
1 deletion
src/backoffice/views/mixins.py
+
32
−
1
View file @
7f7467df
from
django.conf
import
settings
from
django.contrib.auth.mixins
import
LoginRequiredMixin
,
PermissionRequiredMixin
from
django.core.exceptions
import
PermissionDenied
from
django.http
import
HttpRequest
,
HttpResponse
from
django.http
import
Http404
,
HttpRequest
,
HttpResponse
from
django.shortcuts
import
redirect
from
django.urls
import
reverse
,
reverse_lazy
from
django.utils.translation
import
gettext_lazy
as
_
from
django.views.generic.detail
import
SingleObjectMixin
from
rules.contrib.views
import
PermissionRequiredMixin
as
RulesPermissionRequiredMixin
from
core.models.assemblies
import
Assembly
...
...
@@ -17,6 +18,7 @@ from core.models.sso import Application
class
ConferenceRequiredMixinBase
:
login_url
=
reverse_lazy
(
'
backoffice:login
'
)
require_conference
=
False
_conference
:
Conference
|
None
=
None
_conferencemember
:
ConferenceMember
|
None
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -429,3 +431,32 @@ class PasswordMixin:
)
return
context
class
SingleUUIDObjectMixin
(
SingleObjectMixin
):
uuid_url_kwarg
=
'
uuid
'
def
get_object
(
self
,
queryset
=
None
):
"""
Return the object the view is displaying.
Require `self.queryset` and a `uuid` argument in the URLconf.
Subclasses can override this to return any object.
"""
# Use a custom queryset if provided; this is required for subclasses
# like DateDetailView
if
queryset
is
None
:
queryset
=
self
.
get_queryset
()
uuid
=
self
.
kwargs
.
get
(
self
.
uuid_url_kwarg
)
if
uuid
is
not
None
:
queryset
=
queryset
.
filter
(
uuid
=
uuid
)
else
:
raise
AttributeError
(
f
'
Generic detail view
{
self
.
__class__
.
__name__
}
must be called with an object uuid in the URLconf.
'
)
try
:
# Get the single item from the filtered queryset
obj
=
queryset
.
get
()
except
queryset
.
model
.
DoesNotExist
as
exc
:
raise
Http404
(
_
(
'
No %(verbose_name)s found matching the query
'
)
%
{
'
verbose_name
'
:
queryset
.
model
.
_meta
.
verbose_name
})
from
exc
return
obj
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment