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
8249be96
Verified
Commit
8249be96
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite show_current using constance settings and calendar week module
parent
1446f148
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/mensa/settings.py
+10
-0
10 additions, 0 deletions
aleksis/apps/mensa/settings.py
aleksis/apps/mensa/views.py
+10
-17
10 additions, 17 deletions
aleksis/apps/mensa/views.py
with
20 additions
and
17 deletions
aleksis/apps/mensa/settings.py
+
10
−
0
View file @
8249be96
import
os
from
datetime
import
time
from
django.utils.translation
import
gettext_lazy
as
_
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
CONSTANCE_CONFIG
=
{
"
MENSA_NEW_WEEK_DAY
"
:
(
4
,
_
(
"
Weekday at which the plan of the next week is to be shown
"
),
"
weekday_field
"
),
"
MENSA_NEW_WEEK_TIME
"
:
(
time
(
14
,
00
),
_
(
"
Time at which the plan of the next week is to be shown
"
),
time
)
}
CONSTANCE_CONFIG_FIELDSETS
=
{
"
Mensa settings
"
:
(
"
MENSA_NEW_WEEK_DAY
"
,
"
MENSA_NEW_WEEK_TIME
"
),
}
This diff is collapsed.
Click to expand it.
aleksis/apps/mensa/views.py
+
10
−
17
View file @
8249be96
import
datetime
import
os
import
time
from
calendarweek
import
CalendarWeek
from
constance
import
config
from
django.contrib.auth.decorators
import
login_required
,
permission_required
from
django.http
import
FileResponse
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.utils
import
timezone
from
django.conf
import
settings
from
.models
import
Menu
from
.settings
import
BASE_DIR
...
...
@@ -64,27 +65,19 @@ def return_default_pdf():
def
show_current
(
request
):
# Get current date with year and calendar week
current_date
=
timezone
.
datetime
.
now
()
year
,
c
alendar
_w
eek
=
current_date
.
isocalendar
()[:
2
]
cw
=
C
alendar
W
eek
.
from_date
(
current_date
)
# Calculate the number of days to next friday
days_to_add
=
5
-
current_date
.
isoweekday
()
if
days_to_add
<
0
:
days_to_add
=
days_to_add
+
7
if
days_to_add
==
6
or
days_to_add
==
7
:
calendar_week
+=
1
# Create datetime with next friday and time 14:10
friday
=
current_date
+
datetime
.
timedelta
(
days
=
days_to_add
)
friday_14_10
=
timezone
.
datetime
(
friday
.
year
,
friday
.
month
,
friday
.
day
,
14
,
10
)
# Create datetime with the friday of the week and the toggle time
friday
=
cw
[
int
(
config
.
MENSA_NEW_WEEK_DAY
)]
friday
=
timezone
.
datetime
.
combine
(
friday
,
config
.
MENSA_NEW_WEEK_TIME
)
# Check whether to show the plan of the next week or the current week
if
current_date
>
friday
_14_10
:
c
alendar_week
+=
1
if
current_date
>
friday
:
c
w
+=
1
# Look for matching PDF in DB
try
:
obj
=
Menu
.
objects
.
get
(
year
=
year
,
calendar_week
=
c
alendar_
week
)
obj
=
Menu
.
objects
.
get
(
year
=
cw
.
year
,
calendar_week
=
c
w
.
week
)
return
return_pdf
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
str
(
obj
.
pdf
)))
# Or show the default 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