Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Resint
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
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
Mike Gabriel
AlekSIS-App-Resint
Commits
ce4fa6f4
Verified
Commit
ce4fa6f4
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Generate scope names for live documents via ORM
(cherry picked from commit
4a936f85
)
parent
5e92cdc2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/resint/apps.py
+15
-5
15 additions, 5 deletions
aleksis/apps/resint/apps.py
aleksis/apps/resint/models.py
+3
-1
3 additions, 1 deletion
aleksis/apps/resint/models.py
with
18 additions
and
6 deletions
aleksis/apps/resint/apps.py
+
15
−
5
View file @
ce4fa6f4
from
django.apps
import
apps
from
django.utils.translation
import
gettext
as
_
from
django.db
import
models
from
django.db.models
import
functions
from
django.utils.translation
import
gettext_lazy
as
_
from
aleksis.core.util.apps
import
AppConfig
...
...
@@ -22,9 +24,17 @@ class ResintConfig(AppConfig):
def
get_all_scopes
(
cls
)
->
dict
[
str
,
str
]:
"""
Return all OAuth scopes and their descriptions for this app.
"""
LiveDocument
=
apps
.
get_model
(
"
resint
"
,
"
LiveDocument
"
)
scopes
=
{}
for
live_document
in
LiveDocument
.
objects
.
all
():
scopes
[
live_document
.
scope
]
=
_
(
"
Access PDF file for live document {}
"
).
format
(
live_document
.
name
label_prefix
=
_
(
"
Access PDF file for live document
"
)
scopes
=
dict
(
LiveDocument
.
objects
.
annotate
(
scope
=
functions
.
Concat
(
models
.
Value
(
f
"
{
LiveDocument
.
SCOPE_PREFIX
}
_
"
),
models
.
F
(
"
slug
"
),
output_field
=
models
.
CharField
(),
),
label
=
functions
.
Concat
(
models
.
Value
(
f
"
{
label_prefix
}
:
"
),
models
.
F
(
"
name
"
)),
)
.
values_list
(
"
scope
"
,
"
label
"
)
.
distinct
()
)
return
scopes
This diff is collapsed.
Click to expand it.
aleksis/apps/resint/models.py
+
3
−
1
View file @
ce4fa6f4
...
...
@@ -149,6 +149,8 @@ class Poster(ExtensibleModel):
class
LiveDocument
(
ExtensiblePolymorphicModel
):
"""
Model for periodically/automatically updated files.
"""
SCOPE_PREFIX
=
"
live_document_pdf
"
slug
=
models
.
SlugField
(
verbose_name
=
_
(
"
Slug
"
),
help_text
=
_
(
"
This will be used for the name of the current PDF file.
"
),
...
...
@@ -196,7 +198,7 @@ class LiveDocument(ExtensiblePolymorphicModel):
@property
def
scope
(
self
)
->
str
:
"""
Return OAuth2 scope name to access PDF file via API.
"""
return
f
"
live_document_pdf
_
{
self
.
slug
}
"
return
f
"
{
self
.
SCOPE_PREFIX
}
_
{
self
.
slug
}
"
def
save
(
self
,
*
args
,
**
kwargs
):
with
reversion
.
create_revision
():
...
...
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