Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor 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-Core
Commits
22dc8ef5
Commit
22dc8ef5
authored
6 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Show current menu
parent
6f0f439b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!86
Merge school-apps
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
schoolapps/mealplan/urls.py
+2
-1
2 additions, 1 deletion
schoolapps/mealplan/urls.py
schoolapps/mealplan/views.py
+41
-0
41 additions, 0 deletions
schoolapps/mealplan/views.py
schoolapps/templates/partials/header.html
+13
-0
13 additions, 0 deletions
schoolapps/templates/partials/header.html
with
56 additions
and
1 deletion
schoolapps/mealplan/urls.py
+
2
−
1
View file @
22dc8ef5
...
...
@@ -4,5 +4,6 @@ from . import views
urlpatterns
=
[
path
(
''
,
views
.
index
,
name
=
"
menu_index
"
),
path
(
'
upload/
'
,
views
.
upload
,
name
=
"
menu_upload
"
),
path
(
'
<str:msg>
'
,
views
.
index
,
name
=
"
menu_index_msg
"
)
path
(
'
current.pdf
'
,
views
.
show_current
,
name
=
"
menu_show_current
"
),
path
(
'
<str:msg>
'
,
views
.
index
,
name
=
"
menu_index_msg
"
),
]
This diff is collapsed.
Click to expand it.
schoolapps/mealplan/views.py
+
41
−
0
View file @
22dc8ef5
import
datetime
import
os
from
django.http
import
FileResponse
from
django.shortcuts
import
render
,
redirect
from
django.utils
import
timezone
from
mealplan.models
import
MealPlan
from
.forms
import
MenuUploadForm
...
...
@@ -22,3 +27,39 @@ def upload(request):
def
index
(
request
,
msg
=
None
):
menus
=
MealPlan
.
objects
.
all
().
order_by
(
"
calendar_week
"
,
"
year
"
)
return
render
(
request
,
'
menu/index.html
'
,
{
"
msg
"
:
msg
,
"
menus
"
:
menus
})
def
return_pdf
(
filename
):
print
(
filename
)
# Read and response PDF
file
=
open
(
filename
,
"
rb
"
)
return
FileResponse
(
file
,
content_type
=
"
application/pdf
"
)
def
return_default_pdf
():
return
return_pdf
(
os
.
path
.
join
(
"
mealplan
"
,
"
default.pdf
"
))
def
show_current
(
request
):
current_date
=
timezone
.
datetime
.
now
()
year
,
calendar_week
=
current_date
.
isocalendar
()[:
2
]
# print(calendar_week)
# current_date += datetime.timedelta(days=4)
days_to_add
=
5
-
current_date
.
isoweekday
()
# print(days_to_add)
if
days_to_add
<
0
:
days_to_add
=
days_to_add
+
7
# print(days_to_add)
friday
=
current_date
+
datetime
.
timedelta
(
days
=
days_to_add
)
# print(friday)
friday_14_10
=
timezone
.
datetime
(
friday
.
year
,
friday
.
month
,
friday
.
day
,
14
,
10
)
# print(friday_14_10)
if
current_date
>
friday_14_10
:
calendar_week
+=
1
print
(
calendar_week
)
try
:
obj
=
MealPlan
.
objects
.
get
(
year
=
year
,
calendar_week
=
calendar_week
)
print
(
os
.
path
.
join
(
"
media
"
,
str
(
obj
.
pdf
)))
return
return_pdf
(
os
.
path
.
join
(
"
media
"
,
str
(
obj
.
pdf
)))
except
MealPlan
.
DoesNotExist
:
return
return_default_pdf
()
This diff is collapsed.
Click to expand it.
schoolapps/templates/partials/header.html
+
13
−
0
View file @
22dc8ef5
...
...
@@ -122,6 +122,19 @@
<div
class=
"divider"
></div>
</li>
{% endif %}
{% if perms.mealplan.can_add_mealplan %}
<li>
<a
class=
"subheader grey lighten-3"
>
Speiseplan
</a>
</li>
<li>
<a
href=
"{% url 'menu_index' %}"
>
<i
class=
"material-icons"
>
restaurant_menu
</i>
Speiseplan hochladen
</a>
</li>
<li>
<div
class=
"divider"
></div>
</li>
{% endif %}
<li>
<a
href=
"{% url 'logout' %}"
>
<i
class=
"material-icons"
>
exit_to_app
</i>
Abmelden
...
...
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