def protocol_pdf(request, meeting_pk=None): meeting = get_object_or_404(Meeting, pk=meeting_pk) filename = '%s-%s-%s.pdf' % ( meeting.title, meeting.start.strftime('%d-%m-%Y'), _('protocol') ) timetable_entries = meeting.timetable_entries.all().order_by('timetable_index') tops = [] for top in timetable_entries: try: vote = Vote.objects.filter(top=top)[0] except IndexError: vote = None tops.append((top, vote,)) b2_votes = Vote.objects.filter(result='2', top__in=timetable_entries) submission_forms = [x.submission_form for x in b2_votes] b1ized = Vote.objects.filter(result__in=['1', '1a'], submission_form__in=submission_forms).order_by('submission_form__submission__ec_number') pdf = render_pdf(request, 'db/meetings/xhtml2pdf/protocol.html', { 'meeting': meeting, 'tops': tops, 'b1ized': b1ized, }) return pdf_response(pdf, filename=filename)
def get_timetable_pdf(self, request): timetable = {} for entry in self: for user, ignored in entry.users: if ignored: continue if user in timetable: timetable[user].append(entry) else: timetable[user] = [entry] timetable = sorted( [{ 'user': key, 'entries': sorted(timetable[key], key=lambda x: x.timetable_index), } for key in timetable], key=lambda x: x['user'].last_name + x['user'].first_name) for row in timetable: row['start'], row['end'] = self._get_timeframe_for_user( row['user']) return render_pdf(request, 'meetings/pdf/timetable.html', { 'meeting': self, 'timetable': timetable, })
def vote_pdf(request, meeting_pk=None, vote_pk=None): vote = get_object_or_404(Vote, pk=vote_pk) pdf_name = vote_filename(vote) pdf_template = 'db/meetings/xhtml2pdf/vote.html' context = vote_context(vote) pdf = render_pdf(request, pdf_template, context) return pdf_response(pdf, filename=pdf_name)
def agenda_pdf(request, meeting_pk=None): meeting = get_object_or_404(Meeting, pk=meeting_pk) filename = '%s-%s-%s.pdf' % ( meeting.title, meeting.start.strftime('%d-%m-%Y'), _('agenda') ) pdf = render_pdf(request, 'db/meetings/xhtml2pdf/agenda.html', { 'meeting': meeting, }) return pdf_response(pdf, filename=filename)
def handle(self, ec_number, sf_pk, **options): try: s = Submission.objects.get(ec_number=ec_number) except Submission.DoesNotExist: raise CommandError("No submission matches the given EC-Number: %s" % ec_number) submission_form = s.forms.get(pk=sf_pk) if not submission_form: raise CommandError("This submission does not have an attached SubmissionForm.") pdf = render_pdf(FakeRequest(), 'db/submissions/xhtml2pdf/view.html', { 'paper_form_fields': paper_forms.get_field_info_for_model(SubmissionForm), 'submission_form': submission_form, 'documents': submission_form.documents.filter(deleted=False).order_by('doctype__name', '-date'), }) open('%s.pdf' % s.get_ec_number_display(separator='-'), 'w').write(pdf)
def submission_pdf(request, submission_form_pk=None): submission_form = get_object_or_404(SubmissionForm, pk=submission_form_pk) filename = 'ek-%s-Einreichung.pdf' % submission_form.submission.get_ec_number_display(separator='-') if not submission_form.pdf_document: pdf = render_pdf(request, 'db/submissions/xhtml2pdf/view.html', { 'paper_form_fields': paper_forms.get_field_info_for_model(SubmissionForm), 'submission_form': submission_form, 'documents': submission_form.documents.filter(deleted=False).order_by('doctype__name', '-date'), }) doc = Document.objects.create_from_buffer(pdf) submission_form.pdf_document = doc submission_form.save() pdf = doc.file.read() submission_form.pdf_document.file.seek(0) pdf = submission_form.pdf_document.file.read() return pdf_response(pdf, filename=filename)
def agenda_htmlemail(request, meeting_pk=None): meeting = get_object_or_404(Meeting, pk=meeting_pk) filename = '%s-%s-%s.pdf' % ( meeting.title, meeting.start.strftime('%d-%m-%Y'), _('agenda') ) pdf = render_pdf(request, 'db/meetings/xhtml2pdf/agenda.html', { 'meeting': meeting, }) for recipient in settings.AGENDA_RECIPIENT_LIST: htmlmail = unicode(render_html(request, 'meetings/email/invitation-with-agenda.html', { 'meeting': meeting, 'recipient': recipient, })) plainmail = whitewash(htmlmail) deliver(subject=_('Invitation to meeting'), message=plainmail, message_html=htmlmail, attachments=[(filename, pdf,'application/pdf'),], from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=settings.AGENDA_RECIPIENT_LIST) return HttpResponseRedirect(reverse('ecs.meetings.views.upcoming_meetings'))
def timetable_pdf(request, meeting_pk=None): meeting = get_object_or_404(Meeting, pk=meeting_pk) timetable = {} for entry in meeting: for user in entry.users: if user in timetable: timetable[user].append(entry) else: timetable[user] = [entry] timetable = sorted([{ 'user': key, 'entries': sorted(timetable[key], key=lambda x:x.timetable_index), } for key in timetable], key=lambda x:x['user']) for row in timetable: first_entry = row['entries'][0] times = [{'start': first_entry.start, 'end': first_entry.end, 'index': first_entry.timetable_index}] for entry in row['entries'][1:]: if times[-1]['end'] == entry.start: times[-1]['end'] = entry.end else: times.append({'start': entry.start, 'end': entry.end, 'index': entry.timetable_index}) row['times'] = ', '.join(['%s - %s' % (x['start'].strftime('%H:%M'), x['end'].strftime('%H:%M')) for x in times]) filename = '%s-%s-%s.pdf' % ( meeting.title, meeting.start.strftime('%d-%m-%Y'), _('time slot') ) pdf = render_pdf(request, 'db/meetings/xhtml2pdf/timetable.html', { 'meeting': meeting, 'timetable': timetable, }) return pdf_response(pdf, filename=filename)
def get_agenda_pdf(self, request): return render_pdf(request, 'meetings/pdf/agenda.html', { 'meeting': self, })