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
10881b8c
Commit
10881b8c
authored
6 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add badges and color in PDF | Some design changes in PDF [TIMETABLE/SUBSTITUTIONS]
parent
e15f805a
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/timetable/pdf.py
+54
-101
54 additions, 101 deletions
schoolapps/timetable/pdf.py
schoolapps/timetable/views.py
+5
-5
5 additions, 5 deletions
schoolapps/timetable/views.py
schoolapps/untisconnect/sub.py
+83
-0
83 additions, 0 deletions
schoolapps/untisconnect/sub.py
with
142 additions
and
106 deletions
schoolapps/timetable/pdf.py
+
54
−
101
View file @
10881b8c
...
...
@@ -23,12 +23,33 @@ TEX_HEADER = """\\documentclass[11pt]{article}
{
\\
bgroup\def
\\
ULthickness{1.5pt}}
{}{}
\\
usepackage[framemethod=tikz]{mdframed}
\\
newmdenv[
roundcorner=5pt,
backgroundcolor=green,
linecolor=green,
skipabove=0pt,
skipbelow=0pt,
leftmargin=0pt,
rightmargin=0pt
]{badges}
\\
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}
\\
usepackage{helvet} %Helvetica als Standardschriftart
\\
renewcommand{
\\
familydefault}{
\\
sfdefault} %Helvetica als Standardschriftart
\\
definecolor{grey}{rgb}{0.95,0.95,0.95}
\\
definecolor{darkgrey}{rgb}{0.6,0.6,0.6}
\\
definecolor{white}{rgb}{1,1,1}
\\
definecolor{green}{RGB}{76,175,80}
\\
pagestyle{fancy}
%
\\
renewcommand{
\\
sectionmark}[1]{#1}
...
...
@@ -36,99 +57,12 @@ TEX_HEADER = """\\documentclass[11pt]{article}
\\
lhead{
\\
includegraphics[width=5cm]{static/common/logo.png}}
\\
lfoot{Katharineum zu Lübeck}
\\
cfoot{
\\
thepage}
\\
rfoot{
Alle Angaben ohne Gewähr
}
\\
rfoot{
\\
small Umsetzung: © 2018 by Computer-AG
}
\\
begin{document}
"""
TEX_FOOTER
=
'
\end{document}
'
TEX_DIR_PATH
=
'
latex
'
TEACHER_TEX
=
'
latex/teacher.tex
'
TEACHER_PDF
=
'
latex/teacher.pdf
'
CLASS_TEX
=
'
latex/class.tex
'
CLASS_PDF
=
'
latex/class.pdf
'
class
SubRow
(
object
):
def
__init__
(
self
):
self
.
color
=
"
black
"
self
.
css_class
=
"
black-text
"
self
.
lesson
=
""
self
.
classes
=
""
self
.
teacher
=
""
self
.
subject
=
""
self
.
room
=
""
self
.
text
=
""
self
.
extra
=
""
def
generate_sub_table
(
subs
):
sub_rows
=
[]
for
sub
in
subs
:
sub_row
=
SubRow
()
if
sub
.
type
==
1
or
sub
.
type
==
2
:
sub_row
.
css_class
=
"
green-text
"
sub_row
.
color
=
"
green
"
elif
sub
.
type
==
3
:
sub_row
.
css_class
=
"
blue-text
"
sub_row
.
color
=
"
blue
"
if
sub
.
type
==
3
:
sub_row
.
lesson
=
"
{}./{}
"
.
format
(
sub
.
lesson
-
1
,
sub
.
lesson
)
else
:
sub_row
.
lesson
=
"
{}.
"
.
format
(
sub
.
lesson
)
for
class_
in
sub
.
classes
:
sub_row
.
classes
=
class_
.
name
if
sub
.
type
==
1
:
sub_row
.
teacher
=
"
<s>{}</s>
"
.
format
(
sub
.
teacher_old
.
shortcode
)
elif
sub
.
teacher_new
and
sub
.
teacher_old
:
sub_row
.
teacher
=
"
<s>{}</s> → <strong>{}</strong>
"
.
format
(
sub
.
teacher_old
.
shortcode
,
sub
.
teacher_new
.
shortcode
)
elif
sub
.
teacher_new
and
not
sub
.
teacher_old
:
sub_row
.
teacher
=
"
<strong>{}</strong>
"
.
format
(
sub
.
teacher_new
.
shortcode
)
else
:
sub_row
.
teacher
=
"
<strong>{}</strong>
"
.
format
(
sub
.
teacher_old
.
shortcode
)
if
sub
.
type
==
3
:
sub_row
.
subject
=
"
Aufsicht
"
elif
sub
.
type
==
1
or
sub
.
type
==
2
:
sub_row
.
subject
=
"
<s>{}</s>
"
.
format
(
sub
.
subject_old
.
shortcode
)
elif
sub
.
subject_new
and
sub
.
subject_old
:
sub_row
.
subject
=
"
<s>{}</s> → <strong>{}</strong>
"
.
format
(
sub
.
subject_old
.
shortcode
,
sub
.
subject_new
.
shortcode
)
elif
sub
.
subject_new
and
not
sub
.
subject_old
:
sub_row
.
subject
=
"
<strong>{}</strong>
"
.
format
(
sub
.
subject_new
.
shortcode
)
else
:
sub_row
.
subject
=
"
<strong>{}</strong>
"
.
format
(
sub
.
subject_old
.
shortcode
)
if
sub
.
type
==
3
:
sub_row
.
room
=
sub
.
corridor
.
name
elif
sub
.
type
==
1
or
sub
.
type
==
2
:
pass
elif
sub
.
room_new
and
sub
.
room_old
:
sub_row
.
room
=
"
<s>{}</s> → <strong>{}</strong>
"
.
format
(
sub
.
room_old
.
shortcode
,
sub
.
room_new
.
shortcode
)
elif
sub
.
room_new
and
not
sub
.
room_old
:
sub_row
.
room
=
sub
.
room_new
.
shortcode
else
:
sub_row
.
room
=
sub
.
room_old
.
shortcode
sub_row
.
text
=
sub
.
text
if
sub
.
type
==
1
:
sub_row
.
badge
=
"
Schüler frei
"
elif
sub
.
type
==
2
:
sub_row
.
badge
=
"
Lehrer frei
"
sub_row
.
extra
=
"
{} {}
"
.
format
(
sub
.
id
,
sub
.
lesson_id
)
sub_rows
.
append
(
sub_row
)
return
sub_rows
TEX_TABLE_HEADER_CLASS
=
"""
\def
\\
arraystretch{1.5}
\\
begin{longtable}{|p{20mm}|p{10mm}|p{32mm}|p{25mm}|p{30mm}|p{35mm}|}
...
...
@@ -163,23 +97,24 @@ def generate_pdf(tex, filename):
return
True
def
replacer
(
s
tr
):
s
tr
=
s
tr
.
replace
(
"
<strong>
"
,
"
\\
textbf{
"
)
s
tr
=
s
tr
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
tr
=
s
tr
.
replace
(
"
</strong>
"
,
"
}
"
)
s
tr
=
s
tr
.
replace
(
"
</s>
"
,
"
}
"
)
s
tr
=
s
tr
.
replace
(
"
→
"
,
"
$
\\
rightarrow$
"
)
return
s
tr
def
tex_
replacer
(
s
):
s
=
s
.
replace
(
"
<strong>
"
,
"
\\
textbf{
"
)
s
=
s
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
=
s
.
replace
(
"
</strong>
"
,
"
}
"
)
s
=
s
.
replace
(
"
</s>
"
,
"
}
"
)
s
=
s
.
replace
(
"
→
"
,
"
$
\\
rightarrow$
"
)
return
s
def
generate_class_
pdf
(
subs
,
date
):
def
generate_class_
tex
(
subs
,
date
):
tex_body
=
""
#
D
ates
#
Format d
ates
status_date
=
formats
.
date_format
(
date
,
format
=
"
j. F Y,
\\
K
\\
W W
"
)
current_date
=
formats
.
date_format
(
timezone
.
datetime
.
now
(),
format
=
"
j. F Y H:i
"
)
head_date
=
formats
.
date_format
(
date
,
format
=
"
l, j. F Y
"
)
# Generate header with dates
tex_body
+=
TEX_HEADER_CLASS
%
(
status_date
,
current_date
,
head_date
)
# Begin table
...
...
@@ -187,17 +122,35 @@ def generate_class_pdf(subs, date):
color_background
=
True
for
sub
in
subs
:
# Color every second row in grey
if
color_background
:
tex_body
+=
'
\\
rowcolor{grey}
'
# Get color tag for row
color
=
"
\color{%s}
"
%
sub
.
color
# Print classes
tex_body
+=
color
tex_body
+=
'
\\
textbf{
'
+
sub
.
classes
+
'
} &
'
# Print lesson number, teacher, subject and room
for
i
in
[
sub
.
lesson
,
sub
.
teacher
,
sub
.
subject
,
sub
.
room
]:
tex_body
+=
replacer
(
i
)
+
'
&
'
tex_body
+=
color
tex_body
+=
tex_replacer
(
i
)
+
'
&
'
# Print badge (Cancellation)
if
sub
.
badge
is
not
None
:
tex_body
+=
"""
\\
large
\\
badge{%s}
"""
%
sub
.
badge
# Print notice and new line
tex_body
+=
color
tex_body
+=
"
\\
Large
\\
textit{%s}
\\\\\\
hline
\n
"
%
(
sub
.
text
or
""
)
tex_body
+=
"
\\
textit{%s}
\\\\\\
hline
\n
"
%
(
sub
.
text
or
""
)
# Change background
color_background
=
not
color_background
# End table
tex_body
+=
'
\\
end{longtable}
'
texcontent
=
TEX_HEADER
+
tex_body
+
TEX_FOOTER
return
texcontent
# Connect header, body and footer
tex_content
=
TEX_HEADER
+
tex_body
+
TEX_FOOTER
return
tex_content
This diff is collapsed.
Click to expand it.
schoolapps/timetable/views.py
+
5
−
5
View file @
10881b8c
...
...
@@ -2,9 +2,9 @@ from django.contrib.auth.decorators import login_required
from
django.http
import
Http404
from
django.shortcuts
import
render
from
timetable.pdf
import
generate_sub_table
,
generate_class_
pdf
,
generate_pdf
from
timetable.pdf
import
generate_class_
tex
,
generate_pdf
from
untisconnect.parse
import
*
from
untisconnect.sub
import
get_substitutions_by_date
,
date_to_untis_date
,
untis_date_to_date
from
untisconnect.sub
import
get_substitutions_by_date
,
date_to_untis_date
,
untis_date_to_date
,
generate_sub_table
from
django.utils
import
timezone
try
:
...
...
@@ -74,10 +74,10 @@ def substitutions(request, year=None, day=None, month=None):
subs
=
get_substitutions_by_date
(
date
)
sub_table
=
generate_sub_table
(
subs
)
pdf
=
generate_class_
pdf
(
sub_table
,
date
)
print
(
pdf
)
tex
=
generate_class_
tex
(
sub_table
,
date
)
print
(
tex
)
generate_pdf
(
pdf
,
"
class
"
)
generate_pdf
(
tex
,
"
class
"
)
for
row
in
sub_table
:
print
(
row
.
lesson
)
...
...
This diff is collapsed.
Click to expand it.
schoolapps/untisconnect/sub.py
+
83
−
0
View file @
10881b8c
...
...
@@ -22,6 +22,7 @@ TYPE_CANCELLATION = 1
TYPE_TEACHER_CANCELLATION
=
2
TYPE_CORRIDOR
=
3
def
parse_type_of_untis_flags
(
flags
):
type_
=
TYPE_SUBSTITUTION
if
"
E
"
in
flags
:
...
...
@@ -129,6 +130,88 @@ def substitutions_sorter(sub):
return
sort_by
class
SubRow
(
object
):
def
__init__
(
self
):
self
.
color
=
"
black
"
self
.
css_class
=
"
black-text
"
self
.
lesson
=
""
self
.
classes
=
""
self
.
teacher
=
""
self
.
subject
=
""
self
.
room
=
""
self
.
text
=
""
self
.
extra
=
""
def
generate_sub_table
(
subs
):
sub_rows
=
[]
for
sub
in
subs
:
sub_row
=
SubRow
()
sub_row
.
color
=
"
black
"
if
sub
.
type
==
1
or
sub
.
type
==
2
:
sub_row
.
css_class
=
"
green-text
"
sub_row
.
color
=
"
green
"
elif
sub
.
type
==
3
:
sub_row
.
css_class
=
"
blue-text
"
sub_row
.
color
=
"
blue
"
if
sub
.
type
==
3
:
sub_row
.
lesson
=
"
{}./{}
"
.
format
(
sub
.
lesson
-
1
,
sub
.
lesson
)
else
:
sub_row
.
lesson
=
"
{}.
"
.
format
(
sub
.
lesson
)
for
class_
in
sub
.
classes
:
sub_row
.
classes
=
class_
.
name
if
sub
.
type
==
1
:
sub_row
.
teacher
=
"
<s>{}</s>
"
.
format
(
sub
.
teacher_old
.
shortcode
)
elif
sub
.
teacher_new
and
sub
.
teacher_old
:
sub_row
.
teacher
=
"
<s>{}</s> → <strong>{}</strong>
"
.
format
(
sub
.
teacher_old
.
shortcode
,
sub
.
teacher_new
.
shortcode
)
elif
sub
.
teacher_new
and
not
sub
.
teacher_old
:
sub_row
.
teacher
=
"
<strong>{}</strong>
"
.
format
(
sub
.
teacher_new
.
shortcode
)
else
:
sub_row
.
teacher
=
"
<strong>{}</strong>
"
.
format
(
sub
.
teacher_old
.
shortcode
)
if
sub
.
type
==
3
:
sub_row
.
subject
=
"
Aufsicht
"
elif
sub
.
type
==
1
or
sub
.
type
==
2
:
sub_row
.
subject
=
"
<s>{}</s>
"
.
format
(
sub
.
subject_old
.
shortcode
)
elif
sub
.
subject_new
and
sub
.
subject_old
:
sub_row
.
subject
=
"
<s>{}</s> → <strong>{}</strong>
"
.
format
(
sub
.
subject_old
.
shortcode
,
sub
.
subject_new
.
shortcode
)
elif
sub
.
subject_new
and
not
sub
.
subject_old
:
sub_row
.
subject
=
"
<strong>{}</strong>
"
.
format
(
sub
.
subject_new
.
shortcode
)
else
:
sub_row
.
subject
=
"
<strong>{}</strong>
"
.
format
(
sub
.
subject_old
.
shortcode
)
if
sub
.
type
==
3
:
sub_row
.
room
=
sub
.
corridor
.
name
elif
sub
.
type
==
1
or
sub
.
type
==
2
:
pass
elif
sub
.
room_new
and
sub
.
room_old
:
sub_row
.
room
=
"
<s>{}</s> → <strong>{}</strong>
"
.
format
(
sub
.
room_old
.
shortcode
,
sub
.
room_new
.
shortcode
)
elif
sub
.
room_new
and
not
sub
.
room_old
:
sub_row
.
room
=
sub
.
room_new
.
shortcode
else
:
sub_row
.
room
=
sub
.
room_old
.
shortcode
sub_row
.
text
=
sub
.
text
sub_row
.
badge
=
None
if
sub
.
type
==
1
:
sub_row
.
badge
=
"
Schüler frei
"
elif
sub
.
type
==
2
:
sub_row
.
badge
=
"
Lehrer frei
"
sub_row
.
extra
=
"
{} {}
"
.
format
(
sub
.
id
,
sub
.
lesson_id
)
sub_rows
.
append
(
sub_row
)
return
sub_rows
def
get_substitutions_by_date
(
date
):
subs_raw
=
run_default_filter
(
run_using
(
models
.
Substitution
.
objects
.
filter
(
date
=
date_to_untis_date
(
date
)).
order_by
(
"
classids
"
,
"
lesson
"
)),
...
...
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