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
a54ffb39
Commit
a54ffb39
authored
6 years ago
by
Jonathan Weth
Committed by
root
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request
#152
from Katharineum/feature/merge-2-sub-pdfs
Feature/merge 2 sub pdfs
#149
parents
2c470cdd
875a90d1
No related branches found
No related tags found
1 merge request
!86
Merge school-apps
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
schoolapps/timetable/pdf.py
+9
-8
9 additions, 8 deletions
schoolapps/timetable/pdf.py
schoolapps/timetable/views.py
+27
-10
27 additions, 10 deletions
schoolapps/timetable/views.py
with
37 additions
and
18 deletions
README.md
+
1
−
0
View file @
a54ffb39
...
...
@@ -49,6 +49,7 @@ pip install django-material
pip install django-filter
pip install django_react_templatetags
pip install kanboard
pip install PyPDF2
```
-
`example_secure_settings.py`
zu
`secure_settings.py`
kopieren und anpassen
...
...
This diff is collapsed.
Click to expand it.
schoolapps/timetable/pdf.py
+
9
−
8
View file @
a54ffb39
...
...
@@ -16,13 +16,12 @@ TEX_HEADER_1 = """\\documentclass[11pt]{article}
\\
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}
...
...
@@ -31,6 +30,7 @@ TEX_HEADER_1 = """\\documentclass[11pt]{article}
{
\\
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,
...
...
@@ -39,21 +39,19 @@ TEX_HEADER_1 = """\\documentclass[11pt]{article}
enlarge top by=3pt,
enlarge bottom by=3pt,coltext=white}
%
\\
usepackage{helvet} %Helvetica als Standardschriftart
%
\\
renewcommand{
\\
familydefault}{
\\
sfdefault} %Helvetica als Standardschriftart
% 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}
%
\\
renewcommand{
\\
sectionmark}[1]{#1}
%
\\
lhead{
\\
rightmark}
% 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}
...
...
@@ -64,6 +62,7 @@ TEX_HEADER = TEX_HEADER_1 + DIR + 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} &
...
...
@@ -116,8 +115,10 @@ def generate_pdf(tex, filename):
# Execute pdflatex to generate the PDF
bash_command
=
"
pdflatex -output-directory {} {}.tex
"
.
format
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
),
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
filename
))
print
(
bash_command
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
output
=
process
.
communicate
()[
0
]
print
(
output
)
def
tex_replacer
(
s
):
...
...
This diff is collapsed.
Click to expand it.
schoolapps/timetable/views.py
+
27
−
10
View file @
a54ffb39
import
datetime
import
os
from
PyPDF2
import
PdfFileMerger
from
django.contrib.auth.decorators
import
login_required
,
permission_required
from
django.http
import
Http404
,
FileResponse
from
django.shortcuts
import
render
,
redirect
...
...
@@ -192,18 +193,34 @@ def sub_pdf(request):
# Get the next weekday
today
=
timezone
.
datetime
.
now
()
first_day
=
get_next_weekday
(
today
)
second_day
=
get_next_weekday
(
today
+
datetime
.
timedelta
(
days
=
1
))
print
(
second_day
)
# Get subs and generate table
subs
=
get_substitutions_by_date
(
first_day
)
sub_table
=
generate_sub_table
(
subs
)
header_info
=
get_header_information
(
subs
)
# print(header_info.affected_teachers)
# Generate LaTeX
tex
=
generate_class_tex
(
sub_table
,
first_day
,
header_info
)
# Generate PDF
generate_pdf
(
tex
,
"
class
"
)
for
i
,
day
in
enumerate
([
first_day
,
second_day
]):
print
(
i
,
day
)
subs
=
get_substitutions_by_date
(
day
)
sub_table
=
generate_sub_table
(
subs
)
header_info
=
get_header_information
(
subs
)
# print(header_info.affected_teachers)
# Generate LaTeX
tex
=
generate_class_tex
(
sub_table
,
day
,
header_info
)
# Generate PDF
generate_pdf
(
tex
,
"
class{}
"
.
format
(
i
))
# Merge PDFs
merger
=
PdfFileMerger
()
class0
=
open
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
"
class0.pdf
"
),
"
rb
"
)
class1
=
open
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
"
class1.pdf
"
),
"
rb
"
)
merger
.
append
(
fileobj
=
class0
)
merger
.
append
(
fileobj
=
class1
)
# Write merged PDF to class.pdf
output
=
open
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
"
class.pdf
"
),
"
wb
"
)
merger
.
write
(
output
)
output
.
close
()
# Read and response PDF
file
=
open
(
os
.
path
.
join
(
BASE_DIR
,
"
latex
"
,
"
class.pdf
"
),
"
rb
"
)
...
...
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