def test_pdf_badge_with_custom_logos(app, user, brand_dir): category = MeetingCategoryFactory(category_type=Category.PARTICIPANT) ParticipantFactory.create_batch(5, meeting=category.meeting) right_logo = (StringIO('Right'), 'right.png') left_logo = (StringIO('Left'), 'left.jpg') upload_new_logo(app, user, category.meeting.id, 'PRODUCT_LOGO', right_logo) upload_new_logo(app, user, category.meeting.id, 'PRODUCT_SIDE_LOGO', left_logo) with app.test_request_context(): g.meeting = category.meeting participants = Participant.query.all() context = {'participants': participants} renderer = PdfRenderer('meetings/printouts/badges_pdf.html', height='2.15in', width='3.4in', context=context) renderer._render_template() with open(renderer.template_path, 'r') as content_file: content = content_file.read() product_logos = PyQuery(content)('.logo') for logo in product_logos: assert logo.attrib['src'] == Logo('PRODUCT_LOGO').url side_logos = PyQuery(content)('.side-logo') for logo in side_logos: assert logo.attrib['src'] == Logo('PRODUCT_SIDE_LOGO').url
def _process_distribution(meeting_id, printout_type, title, flag): if printout_type == 'distribution': view_class = DocumentDistribution else: view_class = PigeonHoles g.meeting = Meeting.query.get(meeting_id) query = view_class._get_query(flag) participants = groupby(query, key=attrgetter('language')) flag = g.meeting.custom_fields.filter_by(slug=flag).first() context = { 'participants': participants, 'title': title, 'printout_type': view_class.printout_type, 'table_class': view_class.table_class, 'flag': flag, 'template': 'meetings/printouts/_distribution_table.html' } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='landscape', context=context).as_rq()
def post(self, participant_id): participant = self.get_participant(participant_id) form = AcknowledgeEmailForm(request.form) if form.validate(): context = { 'participant': participant, 'template': 'meetings/printouts/acknowledge_detail.html' } attachment = PdfRenderer('meetings/printouts/printout.html', width=ACK_W, height=ACK_H, orientation='portrait', as_attachment=True, context=context).as_attachment() if send_single_message(form.to.data, form.subject.data, form.message.data, attachment=attachment, attachment_name='registration_detail.pdf'): flash('Message successfully sent', 'success') return redirect( url_for('.participant_detail', participant_id=participant.id)) else: flash('Message failed to send', 'error') set_language(participant.lang) return render_template(self.template_name, participant=participant, form=form)
def _process_admission(meeting_id, flag, category_tags): g.meeting = Meeting.query.get(meeting_id) category_tags = (CategoryTag.query.filter( CategoryTag.id.in_(category_tags)).all()) query = Admission._get_query(flag, category_tags) participants = query.all() flag = g.meeting.custom_fields.filter_by(slug=flag).first() if not category_tags: title = 'General admission' else: title = (', '.join([tag.label for tag in category_tags]) + ' admission') context = { 'participants': participants, 'title': title, 'flag': flag, 'category_tags': category_tags, 'template': 'meetings/printouts/_admission_table.html' } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='landscape', context=context).as_rq()
def get(self, participant_id): participant = (Participant.query.current_meeting().filter_by( id=participant_id).first_or_404()) nostripe = request.args.get('nostripe') context = {'participant': participant, 'nostripe': nostripe} return PdfRenderer('meetings/participant/badge.html', width=BADGE_W, height=BADGE_H, footer=False, orientation='portrait', context=context).as_response()
def get(self, participant_id): participant = ( Participant.query.current_meeting().participants().filter_by( id=participant_id).first_or_404()) context = {'participant': participant} return PdfRenderer('meetings/participant/label.html', width=LABEL_W, height=LABEL_H, orientation="landscape", footer=False, context=context).as_response()
def get(self, participant_id): participant = ( Participant.query.current_meeting().participants().filter_by( id=participant_id).first_or_404()) context = {'participant': participant} language = getattr(participant, 'lang', 'english') set_language(language) return PdfRenderer('meetings/printouts/acknowledge_detail.html', width=ACK_W, height=ACK_H, orientation='portrait', footer=False, context=context).as_response()
def get(self, participant_id): participant = (Participant.query.current_meeting().filter_by( id=participant_id).first_or_404()) participant.set_representing() nostripe = request.args.get('nostripe') template_name = g.meeting.settings.get('badge_template', 'default') context = {'participant': participant, 'nostripe': nostripe} return PdfRenderer( 'meetings/participant/badge.html', width=BADGE_A6_W if template_name == 'default_a6' else BADGE_W, height=BADGE_A6_H if template_name == 'default_a6' else BADGE_H, footer=False, orientation='portrait', context=context).as_response()
def get(self, participant_id): participant = ( Participant.query.current_meeting().participants().filter_by( id=participant_id).first_or_404()) set_language(participant.lang) context = {'participant': participant} return PdfRenderer('meetings/participant/envelope.html', width=ENVEL_W, height=ENVEL_H, orientation="portrait", footer=False, context=context).as_response()
def _process_badges(meeting_id, flag, size, category_ids): g.meeting = Meeting.query.get(meeting_id) participants = Participant.query.current_meeting().participants() if category_ids: participants = participants.filter( Participant.category.has(Category.id.in_(category_ids))) if flag: attr = getattr(Participant, flag) participants = participants.filter(attr == True) context = {'participants': participants, 'printout_size': size} w, h = ('8.3in', '11.7in') if size == 'A4' else ('3.4in', '2.15in') return PdfRenderer('meetings/printouts/badges_pdf.html', width=w, height=h, orientation='portrait', footer=False, context=context).as_rq()
def _process_event_list(meeting_id, title, event_ids): g.meeting = Meeting.query.get(meeting_id) query = EventList._get_query(event_ids) count = query.count() participants = groupby(query, key=attrgetter('custom_field')) context = { 'participants': participants, 'count': count, 'title': title, 'template': 'meetings/printouts/_event_list_table.html' } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='landscape', context=context).as_rq()
def _process_delegation_list(meeting_id, title, flag): g.meeting = Meeting.query.get(meeting_id) query = DelegationsList._get_query(flag) participants = groupby(query, key=attrgetter('category')) flag = g.meeting.custom_fields.filter_by(slug=flag).first() context = { 'participants': participants, 'title': title, 'flag': flag, 'template': 'meetings/printouts/_delegation_list_table.html' } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='landscape', context=context).as_rq()
def _process_media(meeting_id, title, flag, category_ids): g.meeting = Meeting.query.get(meeting_id) query = MediaList._get_query(flag, category_ids) participants = query.all() flag = g.meeting.custom_fields.filter_by(slug=flag).first() context = { 'participants': participants, 'title': title, 'flag': flag, 'category_ids': category_ids, 'template': 'printouts/_media_table.html' } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='landscape', context=context).as_rq()
def _process_observers(meeting_id, title, flag, category_tags, categories): g.meeting = Meeting.query.get(meeting_id) query = ObserversList._get_query(flag, category_tags, categories) participants = query.all() count = query.count() events = g.meeting.custom_fields.filter_by(field_type=CustomField.EVENT) context = { 'participants': participants, 'count': count, 'events': events, 'title': title, 'template': 'printouts/_observers_pdf.html' } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='portrait', context=context).as_rq()
def _process_verification(meeting_id, title, category_ids, template_name=None): g.meeting = Meeting.query.get(meeting_id) query = VerificationList._get_query(category_ids) count = query.count() participants = query template_name = template_name or 'printouts/_verification_table_pdf.html' context = { 'participants': participants, 'count': count, 'title': title, 'category_ids': category_ids, 'template': template_name } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='portrait', context=context).as_rq()
def _process_provisional_list(meeting_id, title, flag, template_name=None): g.meeting = Meeting.query.get(meeting_id) query = ProvisionalList._get_query(flag) count = query.count() participants = query flag = g.meeting.custom_fields.filter_by(slug=flag).first() template_name = (template_name or 'meetings/printouts/_provisional_list_pdf.html') context = { 'participants': participants, 'count': count, 'title': title, 'flag': flag, 'template': template_name } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='portrait', context=context).as_rq()
def _process_provisional_list(meeting_id, title, flag, template_name=None, selected_field_ids=None, categories=None): g.meeting = Meeting.query.get(meeting_id) flag = g.meeting.custom_fields.filter_by(slug=flag).first() template_name = (template_name or 'meetings/printouts/_provisional_list_pdf.html') with db.session.no_autoflush: grouped_participants, count = ProvisionalList.get_participants( flag=flag, categories_ids=categories, selected_field_ids=selected_field_ids, page=0, page_size=0, ) context = { 'grouped_participants': grouped_participants, 'count': count, 'title': title, 'flag': flag, 'selected_field_ids': selected_field_ids, 'template': template_name } return PdfRenderer('meetings/printouts/printout.html', title=title, height='11.693in', width='8.268in', margin=_PRINTOUT_MARGIN, orientation='portrait', context=context).as_rq()