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
696b7fb8
Commit
696b7fb8
authored
6 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Comment and refactor [TIMETABLE/SUBSTITUTIONS]
parent
571ff193
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
+16
-4
16 additions, 4 deletions
schoolapps/timetable/pdf.py
schoolapps/timetable/views.py
+14
-12
14 additions, 12 deletions
schoolapps/timetable/views.py
with
30 additions
and
16 deletions
schoolapps/timetable/pdf.py
+
16
−
4
View file @
696b7fb8
...
...
@@ -4,6 +4,8 @@ import subprocess
from
django.utils
import
timezone
from
django.utils
import
formats
# LaTeX constants
TEX_HEADER
=
"""
\\
documentclass[11pt]{article}
\\
usepackage[ngerman]{babel}
\\
usepackage[utf8]{inputenc}
...
...
@@ -86,28 +88,38 @@ TEX_HEADER_CLASS = """
def
generate_pdf
(
tex
,
filename
):
"""
Generate a PDF by LaTeX code
"""
# Read LaTeX file
tex_file
=
open
(
os
.
path
.
join
(
"
latex
"
,
filename
+
"
.tex
"
),
"
w
"
)
tex_file
.
write
(
tex
)
tex_file
.
close
()
# Execute pdflatex to generate the PDF
bash_command
=
"
pdflatex -output-directory latex {}.tex
"
.
format
(
filename
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
output
=
process
.
communicate
()[
0
]
# bash_command = "xreader {}.pdf".format(filename)
# process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
return
True
def
tex_replacer
(
s
):
"""
Replace HTML tags by LaTeX tags
"""
# Strong text
s
=
s
.
replace
(
"
<strong>
"
,
"
\\
textbf{
"
)
s
=
s
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
=
s
.
replace
(
"
</strong>
"
,
"
}
"
)
# Struck out text
s
=
s
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
=
s
.
replace
(
"
</s>
"
,
"
}
"
)
# Arrow
s
=
s
.
replace
(
"
→
"
,
"
$
\\
rightarrow$
"
)
return
s
def
generate_class_tex
(
subs
,
date
):
"""
Generate LaTeX for a PDF by a substitution table
"""
tex_body
=
""
# Format dates
...
...
This diff is collapsed.
Click to expand it.
schoolapps/timetable/views.py
+
14
−
12
View file @
696b7fb8
...
...
@@ -68,6 +68,8 @@ def plan(request, plan_type, plan_id):
def
get_next_weekday
(
date
):
"""
Get the next weekday by a datetime object
"""
if
date
.
isoweekday
()
in
{
6
,
7
}:
date
+=
datetime
.
timedelta
(
days
=
date
.
isoweekday
()
%
4
)
return
date
...
...
@@ -75,38 +77,38 @@ def get_next_weekday(date):
@login_required
def
sub_pdf
(
request
):
"""
Show substitutions as PDF for the next weekday (specially for monitors)
"""
# Get the next weekday
today
=
timezone
.
datetime
.
now
()
first_day
=
get_next_weekday
(
today
)
# Get subs and generate table
subs
=
get_substitutions_by_date
(
first_day
)
sub_table
=
generate_sub_table
(
subs
)
# Generate LaTeX
tex
=
generate_class_tex
(
sub_table
,
first_day
)
print
(
first_day
)
print
(
tex
)
# Generate PDF
generate_pdf
(
tex
,
"
class
"
)
# Read and response PDF
file
=
open
(
os
.
path
.
join
(
"
latex
"
,
"
class.pdf
"
),
"
rb
"
)
return
FileResponse
(
file
,
content_type
=
"
application/pdf
"
)
@login_required
def
substitutions
(
request
,
year
=
None
,
day
=
None
,
month
=
None
):
"""
Show substitutions in a classic view
"""
date
=
timezone
.
datetime
.
now
()
if
year
is
not
None
and
day
is
not
None
and
month
is
not
None
:
date
=
timezone
.
datetime
(
year
=
year
,
month
=
month
,
day
=
day
)
print
(
date
)
# Get subs and generate table
subs
=
get_substitutions_by_date
(
date
)
sub_table
=
generate_sub_table
(
subs
)
tex
=
generate_class_tex
(
sub_table
,
date
)
print
(
tex
)
generate_pdf
(
tex
,
"
class
"
)
for
row
in
sub_table
:
print
(
row
.
lesson
)
print
(
row
.
teacher
)
context
=
{
"
subs
"
:
subs
,
...
...
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