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
Commits
f3007ba0
Verified
Commit
f3007ba0
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Restructure and cleanup LiveDocument model using revisions
parent
8dc87f2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!16
Resolve "Provide infrastructure for live documents"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/resint/migrations/0006_livedocument.py
+10
-3
10 additions, 3 deletions
aleksis/apps/resint/migrations/0006_livedocument.py
aleksis/apps/resint/models.py
+39
-15
39 additions, 15 deletions
aleksis/apps/resint/models.py
aleksis/apps/resint/views.py
+1
-1
1 addition, 1 deletion
aleksis/apps/resint/views.py
with
50 additions
and
19 deletions
aleksis/apps/resint/migrations/0006_livedocument.py
+
10
−
3
View file @
f3007ba0
# Generated by Django 3.2.
5
on 2021-08-0
3
1
8:02
# Generated by Django 3.2.
4
on 2021-08-0
5
1
4:20
import
aleksis.core.managers
from
django.db
import
migrations
,
models
from
django.db
import
migrations
,
models
import
django.db.models.deletion
import
django.db.models.deletion
...
@@ -7,6 +8,7 @@ import django.db.models.deletion
...
@@ -7,6 +8,7 @@ import django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
dependencies
=
[
(
'
sites
'
,
'
0002_alter_domain_unique
'
),
(
'
contenttypes
'
,
'
0002_remove_content_type_name
'
),
(
'
contenttypes
'
,
'
0002_remove_content_type_name
'
),
(
'
resint
'
,
'
0005_fix_permissions
'
),
(
'
resint
'
,
'
0005_fix_permissions
'
),
]
]
...
@@ -16,15 +18,20 @@ class Migration(migrations.Migration):
...
@@ -16,15 +18,20 @@ class Migration(migrations.Migration):
name
=
'
LiveDocument
'
,
name
=
'
LiveDocument
'
,
fields
=
[
fields
=
[
(
'
id
'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'
ID
'
)),
(
'
id
'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'
ID
'
)),
(
'
extended_data
'
,
models
.
JSONField
(
default
=
dict
,
editable
=
False
)),
(
'
slug
'
,
models
.
SlugField
(
help_text
=
'
This will be used for the name of the current PDF file.
'
,
verbose_name
=
'
Slug
'
)),
(
'
slug
'
,
models
.
SlugField
(
help_text
=
'
This will be used for the name of the current PDF file.
'
,
verbose_name
=
'
Slug
'
)),
(
'
name
'
,
models
.
CharField
(
max_length
=
255
,
verbose_name
=
'
Name
'
)),
(
'
name
'
,
models
.
CharField
(
max_length
=
255
,
verbose_name
=
'
Name
'
)),
(
'
last_updat
e
'
,
models
.
DateTim
eField
(
blank
=
True
,
null
=
True
,
verbose_name
=
'
Date and time of the last update
'
,
editable
=
False
)),
(
'
current_fil
e
'
,
models
.
Fil
eField
(
blank
=
True
,
editable
=
False
,
null
=
True
,
upload_to
=
'
live_documents/
'
,
verbose_name
=
'
Current file
'
)),
(
'
current_file
'
,
models
.
FileField
(
blank
=
True
,
null
=
True
,
upload_to
=
'
chronos/plan_pdfs/
'
,
verbose_name
=
'
Current file
'
,
editable
=
False
)),
(
'
last_update_triggered_manually
'
,
models
.
BooleanField
(
default
=
False
,
editable
=
False
,
verbose_name
=
'
Was the last update triggered manually?
'
)),
(
'
polymorphic_ctype
'
,
models
.
ForeignKey
(
editable
=
False
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'
polymorphic_resint.livedocument_set+
'
,
to
=
'
contenttypes.contenttype
'
)),
(
'
polymorphic_ctype
'
,
models
.
ForeignKey
(
editable
=
False
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'
polymorphic_resint.livedocument_set+
'
,
to
=
'
contenttypes.contenttype
'
)),
(
'
site
'
,
models
.
ForeignKey
(
default
=
1
,
editable
=
False
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'
sites.site
'
)),
],
],
options
=
{
options
=
{
'
verbose_name
'
:
'
Live document
'
,
'
verbose_name
'
:
'
Live document
'
,
'
verbose_name_plural
'
:
'
Live documents
'
,
'
verbose_name_plural
'
:
'
Live documents
'
,
},
},
managers
=
[
(
'
objects
'
,
aleksis
.
core
.
managers
.
PolymorphicCurrentSiteManager
()),
],
),
),
]
]
This diff is collapsed.
Click to expand it.
aleksis/apps/resint/models.py
+
39
−
15
View file @
f3007ba0
...
@@ -7,11 +7,12 @@ from django.db import models
...
@@ -7,11 +7,12 @@ from django.db import models
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
gettext_lazy
as
_
from
django.utils.translation
import
gettext_lazy
as
_
import
reversion
from
calendarweek
import
CalendarWeek
from
calendarweek
import
CalendarWeek
from
calendarweek.django
import
i18n_day_name_choices_lazy
from
calendarweek.django
import
i18n_day_name_choices_lazy
from
polymorphic
.models
import
PolymorphicModel
from
reversion
.models
import
Revision
,
Version
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.mixins
import
ExtensibleModel
,
ExtensiblePolymorphicModel
class
PosterGroup
(
ExtensibleModel
):
class
PosterGroup
(
ExtensibleModel
):
...
@@ -145,8 +146,8 @@ class Poster(ExtensibleModel):
...
@@ -145,8 +146,8 @@ class Poster(ExtensibleModel):
return
timezone
.
datetime
.
combine
(
day
,
self
.
group
.
publishing_time
)
return
timezone
.
datetime
.
combine
(
day
,
self
.
group
.
publishing_time
)
class
LiveDocument
(
PolymorphicModel
):
class
LiveDocument
(
Extensible
PolymorphicModel
):
"""
Model for periodically/automatically updated
PDF
files.
"""
"""
Model for periodically/automatically updated files.
"""
slug
=
models
.
SlugField
(
slug
=
models
.
SlugField
(
verbose_name
=
_
(
"
Slug
"
),
verbose_name
=
_
(
"
Slug
"
),
...
@@ -154,9 +155,6 @@ class LiveDocument(PolymorphicModel):
...
@@ -154,9 +155,6 @@ class LiveDocument(PolymorphicModel):
)
)
name
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Name
"
))
name
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Name
"
))
last_update
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
"
Date and time of the last update
"
),
editable
=
False
)
current_file
=
models
.
FileField
(
current_file
=
models
.
FileField
(
upload_to
=
"
live_documents/
"
,
upload_to
=
"
live_documents/
"
,
null
=
True
,
null
=
True
,
...
@@ -164,25 +162,51 @@ class LiveDocument(PolymorphicModel):
...
@@ -164,25 +162,51 @@ class LiveDocument(PolymorphicModel):
verbose_name
=
_
(
"
Current file
"
),
verbose_name
=
_
(
"
Current file
"
),
editable
=
False
,
editable
=
False
,
)
)
last_update_triggered_manually
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
"
Was the last update triggered manually?
"
),
editable
=
False
)
def
update
(
self
,
file
:
Optional
[
File
]
=
None
):
@property
"""
Set a new PDF file as current file.
"""
def
last_version
(
self
)
->
Optional
[
Revision
]:
if
file
:
"""
Get django-reversion version of last file update.
"""
self
.
current_file
.
save
(
"
current.pdf
"
,
file
)
versions
=
Version
.
objects
.
get_for_object
(
self
).
order_by
(
"
revision__date_created
"
)
self
.
last_update
=
timezone
.
now
()
if
versions
.
exists
():
self
.
save
()
return
versions
.
last
()
return
None
@property
def
last_update
(
self
)
->
Optional
[
datetime
]:
"""
Get datetime of last file update.
"""
last_version
=
self
.
last_version
if
last_version
:
return
last_version
.
revision
.
date_created
return
None
def
get_current_file
(
self
)
->
Optional
[
File
]:
def
get_current_file
(
self
)
->
Optional
[
File
]:
"""
Get current
PDF
file.
"""
"""
Get current file.
"""
if
not
self
.
current_file
:
if
not
self
.
current_file
:
self
.
update
()
self
.
update
()
return
self
.
current_file
.
file
if
self
.
current_file
else
None
return
self
.
current_file
@property
@property
def
filename
(
self
)
->
str
:
def
filename
(
self
)
->
str
:
"""
Get the filename without path of the PDF file.
"""
"""
Get the filename without path of the PDF file.
"""
return
f
"
{
self
.
slug
}
.pdf
"
return
f
"
{
self
.
slug
}
.pdf
"
def
save
(
self
,
*
args
,
**
kwargs
):
with
reversion
.
create_revision
():
super
().
save
(
*
args
,
**
kwargs
)
def
update
(
self
,
triggered_manually
:
bool
=
True
):
"""
Update the file with a new version.
Has to be implemented by subclasses.
"""
pass
def
__str__
(
self
)
->
str
:
return
self
.
name
class
Meta
:
class
Meta
:
verbose_name
=
_
(
"
Live document
"
)
verbose_name
=
_
(
"
Live document
"
)
verbose_name_plural
=
_
(
"
Live documents
"
)
verbose_name_plural
=
_
(
"
Live documents
"
)
This diff is collapsed.
Click to expand it.
aleksis/apps/resint/views.py
+
1
−
1
View file @
f3007ba0
...
@@ -232,4 +232,4 @@ class LiveDocumentShowView(PermissionRequiredMixin, SingleObjectMixin, View):
...
@@ -232,4 +232,4 @@ class LiveDocumentShowView(PermissionRequiredMixin, SingleObjectMixin, View):
file
=
live_document
.
get_current_file
()
file
=
live_document
.
get_current_file
()
if
not
file
:
if
not
file
:
raise
Http404
raise
Http404
return
FileResponse
(
live_document
.
get_current_
file
()
,
content_type
=
"
application/pdf
"
)
return
FileResponse
(
file
.
file
,
content_type
=
"
application/pdf
"
)
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