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
d9eab7e5
Commit
d9eab7e5
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Refactor and comment
parent
9236c504
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!86
Merge school-apps
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
schoolapps/timetable/pdf.py
+4
-118
4 additions, 118 deletions
schoolapps/timetable/pdf.py
schoolapps/timetable/views.py
+83
-30
83 additions, 30 deletions
schoolapps/timetable/views.py
with
87 additions
and
148 deletions
schoolapps/timetable/pdf.py
+
4
−
118
View file @
d9eab7e5
...
...
@@ -2,141 +2,27 @@ import os
import
subprocess
from
django.template.loader
import
render_to_string
from
django.utils
import
timezone
from
django.utils
import
formats
from
schoolapps.settings
import
BASE_DIR
# LaTeX constants
from
untisconnect.sub
import
get_header_information
LOGO_FILENAME
=
os
.
path
.
join
(
BASE_DIR
,
"
static
"
,
"
common
"
,
"
logo.png
"
)
TEX_HEADER_1
=
"""
\\
documentclass[11pt]{article}
\\
usepackage[ngerman]{babel}
\\
usepackage[sfdefault]{cabin}
\\
usepackage[utf8]{inputenc}
\\
usepackage[a4paper,left=1cm,right=1cm,top=2cm,bottom=2cm,bindingoffset=0mm]{geometry}
% Packages
\\
usepackage{fancyhdr}
\\
usepackage{graphicx}
\\
usepackage{longtable}
\\
usepackage{multirow}
\\
usepackage{color, colortbl}
\\
usepackage{geometry}
\\
usepackage{ulem, xpatch}
\\
xpatchcmd{
\\
sout}
{
\\
bgroup}
{
\\
bgroup\def
\\
ULthickness{1.5pt}}
{}{}
% Badge box
\\
usepackage{tcolorbox}
\\
newtcbox{
\\
badge}{nobeforeafter,colframe=green,colback=green,boxrule=0.5pt,arc=4pt,
boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt,tcbox raise base,
grow to left by=0pt,
grow to right by=-3pt,
enlarge top by=3pt,
enlarge bottom by=3pt,coltext=white}
% Define colors
\\
definecolor{grey}{RGB}{208, 208, 208}
\\
definecolor{darkgrey}{rgb}{0.6,0.6,0.6}
\\
definecolor{white}{rgb}{1,1,1}
\\
definecolor{green}{RGB}{76,175,80}
% Define header
\\
pagestyle{fancy}
% Left header: logo
\\
lhead{
\\
includegraphics[width=5cm]{
"""
TEX_HEADER_2
=
"""
}}
% Define footer
\\
lfoot{Katharineum zu Lübeck}
\\
cfoot{
\\
thepage}
\\
rfoot{
\\
small Umsetzung: © 2018--2019 by Computer-AG}
\\
begin{document}
"""
TEX_HEADER
=
TEX_HEADER_1
+
LOGO_FILENAME
+
TEX_HEADER_2
TEX_FOOTER
=
'
\end{document}
'
TEX_TABLE_HEADER_CLASS
=
"""
% Init table
\def
\\
arraystretch{1.5}
\\
begin{longtable}{p{20mm}p{8mm}p{32mm}p{25mm}p{30mm}p{45mm}}
\\
textbf{Klassen} &
\\
textbf{Std.} &
\\
textbf{Lehrer} &
\\
textbf{Fach} &
\\
textbf{Raum} &
\\
textbf{Hinweis}
\\\\
\\
hline
\\
endhead
"""
TEX_HEADER_CLASS
=
"""
\\
rhead{
\\
textbf{Vertretungen %s}
\\\\
Stand: %s
\\\\
}
\\
Large
\\
subsubsection*{}
\\
section*{
\\
Huge Vertretungen %s}
\n
"""
TEX_HEADER_BOX_START
=
"""
\\
fbox{
\\
parbox{0.27
\\
linewidth}{
"""
TEX_HEADER_BOX_MIDDLE
=
"""
}
\\
parbox{0.73
\\
linewidth}{
"""
TEX_HEADER_BOX_END
=
"""
}}
\n\n
"""
TEX_HEADER_BOX_ROW_A
=
"""
\\
textbf{%s}
"""
TEX_HEADER_BOX_ROW_B
=
"""
%s
"""
def
generate_pdf
(
tex
,
filename
):
"""
Generate a PDF by LaTeX code
"""
#
Read
LaTeX file
#
Write
LaTeX file
tex_file
=
open
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
filename
+
"
.tex
"
),
"
w
"
,
encoding
=
"
utf8
"
)
tex_file
.
write
(
tex
)
tex_file
.
close
()
# Execute pdflatex to generate the PDF
bash_command
=
"
pdflatex -halt-on-error -output-directory {} {}.tex
"
.
format
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
),
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
filename
))
print
(
bash_command
)
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
filename
)
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
output
=
process
.
communicate
()[
0
]
print
(
output
)
def
tex_replacer
(
s
):
"""
Replace HTML tags by LaTeX tags
"""
# Strong text
s
=
s
.
replace
(
"
<strong>
"
,
"
\\
textbf{
"
)
s
=
s
.
replace
(
"
</strong>
"
,
"
}
"
)
# Struck out text
s
=
s
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
=
s
.
replace
(
"
</s>
"
,
"
}
"
)
# Arrow
s
=
s
.
replace
(
"
→
"
,
"
$
\\
rightarrow$
"
)
return
s
print
(
"
[LATEX]
"
,
output
)
def
generate_class_tex
(
subs
,
date
,
header_info
,
hints
=
None
):
...
...
This diff is collapsed.
Click to expand it.
schoolapps/timetable/views.py
+
83
−
30
View file @
d9eab7e5
...
...
@@ -24,6 +24,10 @@ from schoolapps.settings import BASE_DIR
from
.models
import
Hint
####################
# HELPER FUNCTIONS #
####################
def
get_all_context
():
teachers
=
get_all_teachers
()
classes
=
get_all_classes
()
...
...
@@ -38,20 +42,6 @@ def get_all_context():
return
context
@login_required
@permission_required
(
"
timetable.show_plan
"
)
def
all
(
request
):
context
=
get_all_context
()
return
render
(
request
,
'
timetable/all.html
'
,
context
)
@login_required
@permission_required
(
"
timetable.show_plan
"
)
def
quicklaunch
(
request
):
context
=
get_all_context
()
return
render
(
request
,
'
timetable/quicklaunch.html
'
,
context
)
def
get_calendar_weeks
(
year
=
timezone
.
datetime
.
now
().
year
):
weeks
=
[]
...
...
@@ -84,23 +74,84 @@ def get_calendar_week(calendar_week, year=timezone.datetime.now().year):
return
None
def
get_next_weekday
(
date
):
"""
Get the next weekday by a datetime object
"""
if
date
.
isoweekday
()
in
{
6
,
7
}:
if
date
.
isoweekday
()
==
6
:
plus
=
2
else
:
plus
=
1
date
+=
datetime
.
timedelta
(
days
=
plus
)
return
date
#############
# OVERVIEWS #
#############
@login_required
@permission_required
(
"
timetable.show_plan
"
)
def
all
(
request
):
"""
[DJANGO VIEW]
Show all plans as collection
:param request: Django request
:return: rendered template
"""
context
=
get_all_context
()
return
render
(
request
,
'
timetable/all.html
'
,
context
)
@login_required
@permission_required
(
"
timetable.show_plan
"
)
def
quicklaunch
(
request
):
"""
[DJANGO VIEW]
Show all plans as buttons
:param request: Django request
:return: rendered template
"""
context
=
get_all_context
()
return
render
(
request
,
'
timetable/quicklaunch.html
'
,
context
)
#########
# PLANS #
#########
@login_required
@permission_required
(
"
timetable.show_plan
"
)
def
plan
(
request
,
plan_type
,
plan_id
,
regular
=
""
,
year
=
timezone
.
datetime
.
now
().
year
,
calendar_week
=
timezone
.
datetime
.
now
().
isocalendar
()[
1
]):
"""
[DJANGO VIEW]
Show a timetable (class, teacher, room, smart/regular)
:param request: Django requests
:param plan_type:
"
teacher
"
,
"
class
"
or
"
room
"
:param plan_id: UNTIS-ID of corresponding object
:param regular: regular plan = True, smart plan = False
:param year: year of plan (only for smart plan)
:param calendar_week: calendar week in year (only for smart plan)
:return:
"""
# Regular or smart plan?
if
regular
==
"
regular
"
:
smart
=
False
else
:
smart
=
True
# Get monday and friday of week
monday_of_week
=
get_calendar_week
(
calendar_week
,
year
)[
"
first_day
"
]
friday
=
monday_of_week
+
datetime
.
timedelta
(
days
=
4
)
#
print(monday_of_week)
#
Init hints
hints
=
None
hints_b
=
None
if
plan_type
==
'
teacher
'
:
# Teacher
_type
=
TYPE_TEACHER
el
=
get_teacher_by_id
(
plan_id
)
...
...
@@ -108,24 +159,25 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y
if
smart
:
hints
=
list
(
get_all_hints_for_teachers_by_time_period
(
monday_of_week
,
friday
))
hints_b
=
list
(
get_all_hints_not_for_teachers_by_time_period
(
monday_of_week
,
friday
))
print
(
hints
)
elif
plan_type
==
'
class
'
:
# Class
_type
=
TYPE_CLASS
el
=
get_class_by_id
(
plan_id
)
# Get hints
if
smart
:
hints
=
list
(
get_all_hints_by_class_and_time_period
(
el
,
monday_of_week
,
friday
))
print
(
hints
)
elif
plan_type
==
'
room
'
:
# Room
_type
=
TYPE_ROOM
el
=
get_room_by_id
(
plan_id
)
else
:
raise
Http404
(
'
Plan not found.
'
)
# Get plan
plan
=
get_plan
(
_type
,
plan_id
,
smart
=
smart
,
monday_of_week
=
monday_of_week
)
# print(parse_lesson_times())
context
=
{
"
smart
"
:
smart
,
...
...
@@ -160,12 +212,15 @@ def my_plan(request, year=None, month=None, day=None):
if
next_weekday
!=
date
:
return
redirect
(
"
timetable_my_plan
"
,
next_weekday
.
year
,
next_weekday
.
month
,
next_weekday
.
day
)
# Get calendar week and monday of week
calendar_week
=
date
.
isocalendar
()[
1
]
monday_of_week
=
get_calendar_week
(
calendar_week
,
date
.
year
)[
"
first_day
"
]
# Get user type (student, teacher, etc.)
_type
=
UserInformation
.
user_type
(
request
.
user
)
if
_type
==
UserInformation
.
TEACHER
:
# Teacher
_type
=
TYPE_TEACHER
shortcode
=
request
.
user
.
username
el
=
get_teacher_by_shortcode
(
shortcode
)
...
...
@@ -177,6 +232,7 @@ def my_plan(request, year=None, month=None, day=None):
hints_b
=
list
(
get_all_hints_not_for_teachers_by_time_period
(
date
,
date
))
elif
_type
==
UserInformation
.
STUDENT
:
# Student
_type
=
TYPE_CLASS
_name
=
UserInformation
.
user_classes
(
request
.
user
)[
0
]
el
=
get_class_by_name
(
_name
)
...
...
@@ -188,8 +244,10 @@ def my_plan(request, year=None, month=None, day=None):
hints_b
=
None
else
:
# No student or teacher > no my plan
return
redirect
(
"
timetable_admin_all
"
)
# Get plan
plan
=
get_plan
(
_type
,
plan_id
,
smart
=
True
,
monday_of_week
=
monday_of_week
)
context
=
{
...
...
@@ -211,17 +269,9 @@ def my_plan(request, year=None, month=None, day=None):
return
render
(
request
,
'
timetable/myplan.html
'
,
context
)
def
get_next_weekday
(
date
):
"""
Get the next weekday by a datetime object
"""
if
date
.
isoweekday
()
in
{
6
,
7
}:
if
date
.
isoweekday
()
==
6
:
plus
=
2
else
:
plus
=
1
date
+=
datetime
.
timedelta
(
days
=
plus
)
return
date
#################
# SUBSTITUTIONS #
#################
def
sub_pdf
(
request
):
"""
Show substitutions as PDF for the next weekday (specially for monitors)
"""
...
...
@@ -299,6 +349,10 @@ def substitutions(request, year=None, month=None, day=None):
return
render
(
request
,
'
timetable/substitution.html
'
,
context
)
###################
# HINT MANAGEMENT #
###################
@login_required
@permission_required
(
"
timetable.can_view_hint
"
)
def
hints
(
request
):
...
...
@@ -307,7 +361,6 @@ def hints(request):
if
request
.
session
.
get
(
"
msg
"
,
False
):
msg
=
request
.
session
[
"
msg
"
]
request
.
session
[
"
msg
"
]
=
None
# f.form.layout = Fieldset("Hi", Row("from_date", "to_date", "classes", "teachers"))
return
render
(
request
,
"
timetable/hints.html
"
,
{
"
f
"
:
f
,
"
msg
"
:
msg
})
...
...
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