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
1b20eb62
Verified
Commit
1b20eb62
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add model for live documents
parent
3ddc0ec5
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
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/resint/migrations/0006_livedocument.py
+30
-0
30 additions, 0 deletions
aleksis/apps/resint/migrations/0006_livedocument.py
aleksis/apps/resint/models.py
+45
-0
45 additions, 0 deletions
aleksis/apps/resint/models.py
with
75 additions
and
0 deletions
aleksis/apps/resint/migrations/0006_livedocument.py
0 → 100644
+
30
−
0
View file @
1b20eb62
# Generated by Django 3.2.5 on 2021-08-03 18:02
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
contenttypes
'
,
'
0002_remove_content_type_name
'
),
(
'
resint
'
,
'
0005_fix_permissions
'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'
LiveDocument
'
,
fields
=
[
(
'
id
'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'
ID
'
)),
(
'
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
'
)),
(
'
last_update
'
,
models
.
DateTimeField
(
blank
=
True
,
null
=
True
,
verbose_name
=
'
Date and time of the last update
'
)),
(
'
current_file
'
,
models
.
FileField
(
blank
=
True
,
null
=
True
,
upload_to
=
'
chronos/plan_pdfs/
'
,
verbose_name
=
'
Current file
'
)),
(
'
polymorphic_ctype
'
,
models
.
ForeignKey
(
editable
=
False
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'
polymorphic_resint.livedocument_set+
'
,
to
=
'
contenttypes.contenttype
'
)),
],
options
=
{
'
verbose_name
'
:
'
Live document
'
,
'
verbose_name_plural
'
:
'
Live documents
'
,
},
),
]
This diff is collapsed.
Click to expand it.
aleksis/apps/resint/models.py
+
45
−
0
View file @
1b20eb62
from
datetime
import
datetime
from
datetime
import
datetime
from
typing
import
Optional
from
typing
import
Optional
from
django.core.files
import
File
from
django.core.validators
import
FileExtensionValidator
,
MaxValueValidator
,
MinValueValidator
from
django.core.validators
import
FileExtensionValidator
,
MaxValueValidator
,
MinValueValidator
from
django.db
import
models
from
django.db
import
models
from
django.utils
import
timezone
from
django.utils
import
timezone
...
@@ -8,6 +9,7 @@ from django.utils.translation import gettext_lazy as _
...
@@ -8,6 +9,7 @@ from django.utils.translation import gettext_lazy as _
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
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.mixins
import
ExtensibleModel
...
@@ -141,3 +143,46 @@ class Poster(ExtensibleModel):
...
@@ -141,3 +143,46 @@ class Poster(ExtensibleModel):
cw
=
CalendarWeek
(
week
=
self
.
week
,
year
=
self
.
year
)
cw
=
CalendarWeek
(
week
=
self
.
week
,
year
=
self
.
year
)
day
=
cw
[
self
.
group
.
publishing_day
]
day
=
cw
[
self
.
group
.
publishing_day
]
return
timezone
.
datetime
.
combine
(
day
,
self
.
group
.
publishing_time
)
return
timezone
.
datetime
.
combine
(
day
,
self
.
group
.
publishing_time
)
class
LiveDocument
(
PolymorphicModel
):
"""
Model for periodically/automatically updated PDF files.
"""
slug
=
models
.
SlugField
(
verbose_name
=
_
(
"
Slug
"
),
help_text
=
_
(
"
This will be used for the name of the current PDF file.
"
),
)
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
(
upload_to
=
"
live_documents/
"
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"
Current file
"
),
editable
=
False
,
)
def
update
(
self
,
file
:
Optional
[
File
]
=
None
):
"""
Set a new PDF file as current file.
"""
if
file
:
self
.
current_file
.
save
(
"
current.pdf
"
,
file
)
self
.
last_update
=
timezone
.
now
()
self
.
save
()
def
get_current_file
(
self
)
->
Optional
[
File
]:
"""
Get current PDF file.
"""
if
not
self
.
current_file
:
self
.
update
()
return
self
.
current_file
.
file
if
self
.
current_file
else
None
@property
def
filename
(
self
)
->
str
:
"""
Get the filename without path of the PDF file.
"""
return
f
"
{
self
.
slug
}
.pdf
"
class
Meta
:
verbose_name
=
_
(
"
Live document
"
)
verbose_name_plural
=
_
(
"
Live documents
"
)
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