generate note of memberlist for jugendleiter

v1-0-stable
Christian Merten 9 years ago
parent 7bbfde8474
commit 2eebf2b463

@ -0,0 +1,58 @@
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{amssymb}
\usepackage{cmbright}
\usepackage{graphicx}
\usepackage{textpos}
\usepackage[colorlinks]{hyperref}
\usepackage{float}
\usepackage[margin=1cm]{geometry}
\renewcommand{\arraystretch}{1.5}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}
% HEADLINE
{\noindent\LARGE\textsc{Teilnehmerliste \\Sektionsveranstaltung}}\\
\textit{Erstellt: MEMBERLIST-DATE}\\
% DESCRIPTION TABLE
\begin{table}[H]
\begin{tabular}{ll}
\large Aktivität: & ACTIVITY \\
\large Gruppe: & GROUP \\
\large Ziel: & DESTINATION \\
\large Stützpunkt: & PLACE \\
\large Zeitraum: & TIME-PERIOD \\
\end{tabular}
\end{table}
\begin{table}[H]
\begin{tabularx}{\textwidth}{@{} l l Y @{}}
\toprule
\textbf{Name} & \textbf{Fähigkeiten (max. 100)} & \textbf{Kommentare} \\
\midrule
TABLE
\bottomrule
\end{tabularx}
\end{table}
\noindent\large Fähigkeiten der Gruppe\\
\begin{table}[H]
\begin{tabular*}{1\linewidth}{@{\extracolsep{\fill}}llll}
\toprule
\textbf{Name} & \textbf{Durchschnitt} & \textbf{Minimum} & \textbf{Maximum} \\
\midrule
TABLE-QUALITIES
\bottomrule
\end{tabular*}
\end{table}
\vspace{1cm}
\end{document}

@ -72,11 +72,12 @@ class MemberOnListInline(admin.StackedInline):
'cols': 40})},
}
class MemberListAdmin(admin.ModelAdmin):
inlines = [MemberOnListInline]
form = MemberListAdminForm
list_display = ['__str__', 'date']
actions = ['convert_to_pdf']
actions = ['convert_to_pdf', 'generate_notes']
formfield_overrides = {
ManyToManyField: {'widget': forms.CheckboxSelectMultiple}
}
@ -86,7 +87,6 @@ class MemberListAdmin(admin.ModelAdmin):
def convert_to_pdf(self, request, queryset):
"""Converts a member list to pdf.
"""
for memberlist in queryset:
# create a unique filename
@ -172,6 +172,102 @@ class MemberListAdmin(admin.ModelAdmin):
return response
def generate_notes(self, request, queryset):
"""Generates a short note for the jugendleiter"""
for memberlist in queryset:
# unique filename
filename = memberlist.name + "_note_" +\
datetime.today().strftime("%d_%m_%Y")
filename = filename.replace(' ', '_')
filename_tex = filename + '.tex'
filename_pdf = filename + '.pdf'
# generate table
table = ""
activities = [a.name for a in memberlist.activity.all()]
skills = {a: [] for a in activities}
for memberonlist in memberlist.memberonlist_set.all():
m = memberonlist.member
qualities = []
for activity, value in m.get_skills().items():
if activity not in activities:
continue
skills[activity].append(value)
qualities.append("\\textit{%s:} %s" % (activity, value))
comment = ". ".join(c for c
in (m.comments,
memberonlist.comments) if
c).replace("..", ".")
line = '{0} {1} & {2} & {3} \\\\'.format(
m.prename, m.lastname,
", ".join(qualities), comment or "---",
)
table += line
table_qualities = ""
for activity in activities:
line = '{0} & {1} & {2} & {3} \\\\ \n'.format(
activity,
sum(skills[activity]) / len(skills[activity]),
min(skills[activity]),
max(skills[activity])
)
table_qualities += line
# copy template
shutil.copy('media/memberlists/membernote_template.tex',
'media/memberlists/' + filename_tex)
# read in template
with open('media/memberlists/' + filename_tex, 'r') as f:
template_content = f.read()
# adapt template
template_content = template_content.replace('ACTIVITY', memberlist.name)
groups = ', '.join(g.name for g in memberlist.groups.all())
template_content = template_content.replace('GROUP', groups)
template_content = template_content.replace('DESTINATION', memberlist.destination)
template_content = template_content.replace('PLACE', memberlist.place)
template_content = template_content.replace('MEMBERLIST-DATE',
datetime.today().strftime('%d.%m.%Y'))
time_period = memberlist.date.strftime('%d.%m.%Y')
if memberlist.end != memberlist.date:
time_period += " - " + memberlist.end.strftime('%d.%m.%Y')
template_content = template_content.replace('TIME-PERIOD', time_period)
jugendleiter = ', '.join(j.name for j in memberlist.jugendleiter.all())
template_content = template_content.replace('JUGENDLEITER', jugendleiter)
template_content = template_content.replace('TABLE-QUALITIES',
table_qualities)
template_content = template_content.replace('TABLE', table)
# write adapted template to file
with open('media/memberlists/' + filename_tex, 'w') as f:
f.write(template_content)
# compile using pdflatex
oldwd = os.getcwd()
os.chdir('media/memberlists')
subprocess.call(['pdflatex', filename_tex])
time.sleep(1)
# do some cleanup
for f in glob.glob('*.log'):
os.remove(f)
for f in glob.glob('*.aux'):
os.remove(f)
os.remove(filename_tex)
os.chdir(oldwd)
# provide the user with the resulting pdf file
with open('media/memberlists/'+filename_pdf, 'rb') as pdf:
response = HttpResponse(FileWrapper(pdf))
response['Content-Type'] = 'application/pdf'
response['Content-Disposition'] = 'attachment; filename=' + filename_pdf
return response
class KlettertreffAdminForm(forms.ModelForm):
class Meta:

Loading…
Cancel
Save