Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Chronos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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-Chronos
Commits
5fa8528d
Commit
5fa8528d
authored
6 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Comment and refactor [TIMETABLE/SUBSTITUTIONS]
parent
151aaf1e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
biscuit/apps/chronos/pdf.py
+16
-4
16 additions, 4 deletions
biscuit/apps/chronos/pdf.py
biscuit/apps/chronos/views.py
+14
-12
14 additions, 12 deletions
biscuit/apps/chronos/views.py
with
30 additions
and
16 deletions
biscuit/apps/chronos/pdf.py
+
16
−
4
View file @
5fa8528d
...
@@ -4,6 +4,8 @@ import subprocess
...
@@ -4,6 +4,8 @@ import subprocess
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils
import
formats
from
django.utils
import
formats
# LaTeX constants
TEX_HEADER
=
"""
\\
documentclass[11pt]{article}
TEX_HEADER
=
"""
\\
documentclass[11pt]{article}
\\
usepackage[ngerman]{babel}
\\
usepackage[ngerman]{babel}
\\
usepackage[utf8]{inputenc}
\\
usepackage[utf8]{inputenc}
...
@@ -86,28 +88,38 @@ TEX_HEADER_CLASS = """
...
@@ -86,28 +88,38 @@ TEX_HEADER_CLASS = """
def
generate_pdf
(
tex
,
filename
):
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
=
open
(
os
.
path
.
join
(
"
latex
"
,
filename
+
"
.tex
"
),
"
w
"
)
tex_file
.
write
(
tex
)
tex_file
.
write
(
tex
)
tex_file
.
close
()
tex_file
.
close
()
# Execute pdflatex to generate the PDF
bash_command
=
"
pdflatex -output-directory latex {}.tex
"
.
format
(
filename
)
bash_command
=
"
pdflatex -output-directory latex {}.tex
"
.
format
(
filename
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
output
=
process
.
communicate
()[
0
]
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
):
def
tex_replacer
(
s
):
"""
Replace HTML tags by LaTeX tags
"""
# Strong text
s
=
s
.
replace
(
"
<strong>
"
,
"
\\
textbf{
"
)
s
=
s
.
replace
(
"
<strong>
"
,
"
\\
textbf{
"
)
s
=
s
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
=
s
.
replace
(
"
</strong>
"
,
"
}
"
)
s
=
s
.
replace
(
"
</strong>
"
,
"
}
"
)
# Struck out text
s
=
s
.
replace
(
"
<s>
"
,
"
\\
sout{
"
)
s
=
s
.
replace
(
"
</s>
"
,
"
}
"
)
s
=
s
.
replace
(
"
</s>
"
,
"
}
"
)
# Arrow
s
=
s
.
replace
(
"
→
"
,
"
$
\\
rightarrow$
"
)
s
=
s
.
replace
(
"
→
"
,
"
$
\\
rightarrow$
"
)
return
s
return
s
def
generate_class_tex
(
subs
,
date
):
def
generate_class_tex
(
subs
,
date
):
"""
Generate LaTeX for a PDF by a substitution table
"""
tex_body
=
""
tex_body
=
""
# Format dates
# Format dates
...
...
This diff is collapsed.
Click to expand it.
biscuit/apps/chronos/views.py
+
14
−
12
View file @
5fa8528d
...
@@ -68,6 +68,8 @@ def plan(request, plan_type, plan_id):
...
@@ -68,6 +68,8 @@ def plan(request, plan_type, plan_id):
def
get_next_weekday
(
date
):
def
get_next_weekday
(
date
):
"""
Get the next weekday by a datetime object
"""
if
date
.
isoweekday
()
in
{
6
,
7
}:
if
date
.
isoweekday
()
in
{
6
,
7
}:
date
+=
datetime
.
timedelta
(
days
=
date
.
isoweekday
()
%
4
)
date
+=
datetime
.
timedelta
(
days
=
date
.
isoweekday
()
%
4
)
return
date
return
date
...
@@ -75,38 +77,38 @@ def get_next_weekday(date):
...
@@ -75,38 +77,38 @@ def get_next_weekday(date):
@login_required
@login_required
def
sub_pdf
(
request
):
def
sub_pdf
(
request
):
"""
Show substitutions as PDF for the next weekday (specially for monitors)
"""
# Get the next weekday
today
=
timezone
.
datetime
.
now
()
today
=
timezone
.
datetime
.
now
()
first_day
=
get_next_weekday
(
today
)
first_day
=
get_next_weekday
(
today
)
# Get subs and generate table
subs
=
get_substitutions_by_date
(
first_day
)
subs
=
get_substitutions_by_date
(
first_day
)
sub_table
=
generate_sub_table
(
subs
)
sub_table
=
generate_sub_table
(
subs
)
# Generate LaTeX
tex
=
generate_class_tex
(
sub_table
,
first_day
)
tex
=
generate_class_tex
(
sub_table
,
first_day
)
print
(
first_day
)
print
(
tex
)
# Generate PDF
generate_pdf
(
tex
,
"
class
"
)
generate_pdf
(
tex
,
"
class
"
)
# Read and response PDF
file
=
open
(
os
.
path
.
join
(
"
latex
"
,
"
class.pdf
"
),
"
rb
"
)
file
=
open
(
os
.
path
.
join
(
"
latex
"
,
"
class.pdf
"
),
"
rb
"
)
return
FileResponse
(
file
,
content_type
=
"
application/pdf
"
)
return
FileResponse
(
file
,
content_type
=
"
application/pdf
"
)
@login_required
@login_required
def
substitutions
(
request
,
year
=
None
,
day
=
None
,
month
=
None
):
def
substitutions
(
request
,
year
=
None
,
day
=
None
,
month
=
None
):
"""
Show substitutions in a classic view
"""
date
=
timezone
.
datetime
.
now
()
date
=
timezone
.
datetime
.
now
()
if
year
is
not
None
and
day
is
not
None
and
month
is
not
None
:
if
year
is
not
None
and
day
is
not
None
and
month
is
not
None
:
date
=
timezone
.
datetime
(
year
=
year
,
month
=
month
,
day
=
day
)
date
=
timezone
.
datetime
(
year
=
year
,
month
=
month
,
day
=
day
)
print
(
date
)
# Get subs and generate table
subs
=
get_substitutions_by_date
(
date
)
subs
=
get_substitutions_by_date
(
date
)
sub_table
=
generate_sub_table
(
subs
)
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
=
{
context
=
{
"
subs
"
:
subs
,
"
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