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
Model registry
Operate
Environments
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
AlekSIS®
Official
AlekSIS-App-Resint
Merge requests
!16
Resolve "Provide infrastructure for live documents"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Provide infrastructure for live documents"
3-provide-infrastructure-for-live-documents
into
master
Overview
8
Commits
13
Pipelines
7
Changes
1
Merged
Jonathan Weth
requested to merge
3-provide-infrastructure-for-live-documents
into
master
3 years ago
Overview
7
Commits
13
Pipelines
7
Changes
1
Expand
Closes
#3 (closed)
Edited
3 years ago
by
Jonathan Weth
0
0
Merge request reports
Viewing commit
8dc87f2b
Prev
Next
Show latest version
1 file
+
1
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Verified
8dc87f2b
Reformat
· 8dc87f2b
Jonathan Weth
authored
3 years ago
aleksis/apps/resint/views.py
+
98
−
3
Options
from
typing
import
Any
,
Dict
from
typing
import
Any
,
Dict
,
Type
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models
import
QuerySet
from
django.http
import
FileResponse
,
HttpRequest
from
django.forms
import
BaseModelForm
,
modelform_factory
from
django.http
import
FileResponse
,
Http404
,
HttpRequest
from
django.shortcuts
import
get_object_or_404
from
django.urls
import
reverse_lazy
from
django.utils.decorators
import
method_decorator
from
django.utils.translation
import
gettext
as
_
from
django.views
import
View
from
django.views.decorators.cache
import
never_cache
from
django.views.generic.detail
import
SingleObjectMixin
from
django.views.generic.list
import
ListView
from
django_tables2
import
SingleTableView
from
guardian.shortcuts
import
get_objects_for_user
from
reversion.views
import
RevisionMixin
from
rules.contrib.views
import
PermissionRequiredMixin
from
aleksis.core.mixins
import
AdvancedCreateView
,
AdvancedDeleteView
,
AdvancedEditView
from
.forms
import
PosterGroupForm
,
PosterUploadForm
from
.models
import
Poster
,
PosterGroup
from
.models
import
LiveDocument
,
Poster
,
PosterGroup
from
.tables
import
LiveDocumentTable
class
PosterGroupListView
(
PermissionRequiredMixin
,
ListView
):
@@ -138,3 +146,90 @@ class PosterCurrentView(PermissionRequiredMixin, SingleObjectMixin, View):
current_poster
=
group
.
current_poster
file
=
current_poster
.
pdf
if
current_poster
else
group
.
default_pdf
return
FileResponse
(
file
,
content_type
=
"
application/pdf
"
)
class
LiveDocumentListView
(
PermissionRequiredMixin
,
SingleTableView
):
"""
Table of all live documents.
"""
model
=
LiveDocument
table_class
=
LiveDocumentTable
permission_required
=
"
resint.view_livedocuments_rule
"
template_name
=
"
resint/live_document/list.html
"
def
get_context_data
(
self
,
**
kwargs
:
Any
)
->
dict
[
str
,
Any
]:
context
=
super
().
get_context_data
(
**
kwargs
)
context
[
"
widget_types
"
]
=
[
(
ContentType
.
objects
.
get_for_model
(
m
,
False
),
m
)
for
m
in
LiveDocument
.
__subclasses__
()
]
return
context
@method_decorator
(
never_cache
,
name
=
"
dispatch
"
)
class
LiveDocumentCreateView
(
PermissionRequiredMixin
,
AdvancedCreateView
):
"""
Create view for live documents.
"""
def
get_model
(
self
,
request
,
*
args
,
**
kwargs
):
app_label
=
kwargs
.
get
(
"
app
"
)
model
=
kwargs
.
get
(
"
model
"
)
ct
=
get_object_or_404
(
ContentType
,
app_label
=
app_label
,
model
=
model
)
return
ct
.
model_class
()
def
get_context_data
(
self
,
**
kwargs
:
Any
)
->
dict
[
str
,
Any
]:
context
=
super
().
get_context_data
(
**
kwargs
)
context
[
"
model
"
]
=
self
.
model
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
model
=
self
.
get_model
(
request
,
*
args
,
**
kwargs
)
return
super
().
get
(
request
,
*
args
,
**
kwargs
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
model
=
self
.
get_model
(
request
,
*
args
,
**
kwargs
)
return
super
().
post
(
request
,
*
args
,
**
kwargs
)
fields
=
"
__all__
"
model
=
LiveDocument
permission_required
=
"
resint.add_livedocument_rule
"
template_name
=
"
resint/live_document/create.html
"
success_url
=
reverse_lazy
(
"
live_documents
"
)
success_message
=
_
(
"
The live document has been created.
"
)
@method_decorator
(
never_cache
,
name
=
"
dispatch
"
)
class
LiveDocumentEditView
(
PermissionRequiredMixin
,
AdvancedEditView
):
"""
Edit view for live documents.
"""
def
get_form_class
(
self
)
->
Type
[
BaseModelForm
]:
return
modelform_factory
(
self
.
object
.
__class__
,
fields
=
self
.
fields
)
model
=
LiveDocument
fields
=
"
__all__
"
permission_required
=
"
resint.edit_livedocument_rule
"
template_name
=
"
resint/live_document/edit.html
"
success_url
=
reverse_lazy
(
"
live_documents
"
)
success_message
=
_
(
"
The live document has been saved.
"
)
@method_decorator
(
never_cache
,
name
=
"
dispatch
"
)
class
LiveDocumentDeleteView
(
PermissionRequiredMixin
,
RevisionMixin
,
AdvancedDeleteView
):
"""
Delete view for live documents.
"""
model
=
LiveDocument
permission_required
=
"
resint.delete_livedocument_rule
"
template_name
=
"
core/pages/delete.html
"
success_url
=
reverse_lazy
(
"
live_documents
"
)
success_message
=
_
(
"
The live document has been deleted.
"
)
class
LiveDocumentShowView
(
PermissionRequiredMixin
,
SingleObjectMixin
,
View
):
"""
Show the current version of the live document.
"""
model
=
LiveDocument
permission_required
=
"
resint.view_livedocument_rule
"
def
get
(
self
,
request
:
HttpRequest
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
FileResponse
:
live_document
=
self
.
get_object
()
file
=
live_document
.
get_current_file
()
if
not
file
:
raise
Http404
return
FileResponse
(
file
.
file
,
content_type
=
"
application/pdf
"
)
Loading