def _badge_categories_print(meeting, **kwargs): app = flask.current_app categories = kwargs.get("categories") person_type = kwargs.get("person_type") if 'color' in kwargs: kwargs.pop("categories", None) temp = path(app.config['BADGES_PATH']) if not temp.exists(): temp.makedirs() for category in meeting.get_categories(): color = category.data['badge_color'].replace(' ', '-') filename = color + '-left.png' if not app.config['BADGES_LOGOS'].joinpath(filename).exists(): generate_badge_logo(color) meta = dict(meeting_id=meeting.id, categories=categories, photos=app.config['UPLOADED_PHOTOS_DEST'], person_type=person_type) context = dict(background_path=app.config['UPLOADED_BACKGROUNDS_DEST'], badge_logo_path=app.config['BADGES_LOGOS'], path=app.root_path, person_type=person_type) context.update(kwargs) task = workers.render_participant_pdf \ .delay("participant/badges_simple.html", meta=meta, temp=temp, height="2.15in", width="3.4in", context=context) task_status_url = flask.url_for('participant.task_status', meeting_id=meeting.id, task_id=task.id) return flask.jsonify({ "task_id": task.id, "url": task_status_url })
def badge_print(meeting_id, person_id, person_type): app = flask.current_app meeting = sugar.get_object_or_404(models.Meeting, id=meeting_id) if person_type == 'person': person = sugar.get_person_or_404(meeting_id, person_id) else: person = sugar.get_media_person_or_404(meeting_id, person_id) badge = flask.request.args.get('badge', None) # create a temporary folder and save participant photo to disk temp = path(tempfile.mkdtemp()) photo = person.data.get('photo', None) if photo: person.photo_url = app.config['UPLOADED_PHOTOS_DEST'] / photo else: person.photo_url = None if badge and badge == 'nostripe': color = 'all-white' else: category = person.category_model(meeting.id) color = category.data['badge_color'].replace(' ', '-') filename = color + '-left.png' if not app.config['BADGES_LOGOS'].joinpath(filename).exists(): generate_badge_logo(color) # save badge as html context = dict(meeting=meeting, person=person, path=app.root_path, background_path=app.config['UPLOADED_BACKGROUNDS_DEST'], badge_logo_path=app.config['BADGES_LOGOS'], badge=badge, person_type=person_type) return sugar.render_pdf("participant/person_badge_simple.html", temp=temp, height="2.15in", width="3.4in", context=context, filename=secure_filename(person.name), use_wkhtmltopdf=True)