def genpdfresult(request, fight_id): if request.method == "POST" or True: trn = request.user.profile.tournament fight = get_object_or_404(Fight, pk=fight_id, round__tournament=trn) context = context_generator.result(fight) fileprefix = "result-round-%d-room-%s-v" % (fight.round.order, fight.room.name) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) res = render_to_pdf.delay( trn.default_templates.get(type=Template.RESULTS).id, pdf.id, context=context) pdf.task_id = res.id pdf.save() pdf.tags.add(PdfTag.objects.get(tournament=trn, type=Template.RESULTS)) fight.pdf_result = pdf fight.save() return redirect("fight:publish")
def genpdfrank(request, round_nr): if request.method == "POST" or True: trn = request.user.profile.tournament round = get_object_or_404(Round, order=round_nr, tournament=trn) context = context_generator.ranking(round) fileprefix = "ranking-round-%d-v" % (round.order) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) res = render_to_pdf.delay( trn.default_templates.get(type=Template.RANKING).id, pdf.id, context=context) pdf.task_id = res.id pdf.save() pdf.tags.add(PdfTag.objects.get(tournament=trn, type=Template.RANKING)) round.pdf_ranking = pdf round.save() return redirect("fight:publish")
def geninvoice(request, a_id): if request.method == "POST" or True: trn = request.user.profile.tournament acc = get_object_or_404(Account, pk=a_id, owners=request.user.profile.active) context = context_generator.invoice(acc, request.user.profile.active) fileprefix = "invoice-account-%d-v" % (acc.id) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) pdf.invoice_account = acc pdf.save() res = render_to_pdf.delay( trn.default_templates.get(type=Template.INVOICE).id, pdf.id, context=context) pdf.task_id = res.id pdf.save() if PdfTag.objects.filter(tournament=trn, type=Template.INVOICE).exists(): pdf.tags.add( PdfTag.objects.get(tournament=trn, type=Template.INVOICE)) return redirect("account:list_account", account=acc.id)
def genpdfjuryfeedback(request, fight_id): if request.method == "POST": trn = request.user.profile.tournament fight = get_object_or_404(Fight, pk=fight_id, round__tournament=trn) context = context_generator.juryfeedback(fight) fileprefix = "jury-feedback-round-%d-room-%s-v" % (fight.round.order, fight.room.name) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) res = render_to_pdf.delay( trn.default_templates.get(type=Template.JURYFEEDBACK).id, pdf.id, context=context) pdf.task_id = res.id pdf.save() try: pdf.tags.add( PdfTag.objects.get(tournament=trn, type=Template.JURYFEEDBACK)) except: messages.add_message(request, messages.WARNING, "No PDF Tag found for Jury Round") fight.pdf_jury_feedback = pdf fight.save() return redirect("jury:plan") return HttpResponseNotAllowed(['POST'])
def genpdfproblemselect(request, round_nr): if request.method == "POST": trn = request.user.profile.tournament round = get_object_or_404(Round, order=round_nr, tournament=trn) context = context_generator.problem_select(round) fileprefix = "problem-selection-round-%d-v" % (round.order) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) res = render_to_pdf.delay( trn.default_templates.get(type=Template.PROBLEMSELECT).id, pdf.id, context=context) pdf.task_id = res.id pdf.save() try: pdf.tags.add( PdfTag.objects.get(tournament=trn, type=Template.PROBLEMSELECT)) except: messages.add_message(request, messages.WARNING, "No PDF Tag found for Problem Select") round.pdf_problem_select = pdf round.save() return redirect("plan:plan") return HttpResponseNotAllowed(['POST'])
def done(self, request, cleaned_data): ps = cleaned_data['persons'] if 'action' not in request.POST: ps.delete() elif request.POST['action'] == '_add_roles': news = cleaned_data['roles'] for att in ps: att.roles.add(*news) elif request.POST['action'] == '_del_roles': news = cleaned_data['roles'] for att in ps: if _is_superior_user(request.user, att): att.roles.remove(*news) elif request.POST['action'] == '_add_groups': news = cleaned_data['groups'] for att in ps: #TODO: only add if you have perm yourself att.groups.add(*news) elif request.POST['action'] == '_del_groups': news = cleaned_data['groups'] for att in ps: if _is_superior_user(request.user, att): att.groups.remove(*news) elif request.POST['action'] == '_team': assorole = TeamRole.objects.get( tournament=request.user.profile.tournament, type=TeamRole.ASSOCIATED) for att in ps: if not TeamMember.objects.filter(team=cleaned_data['team'], attendee=att).exists(): TeamMember.objects.create(team=cleaned_data['team'], attendee=att, role=assorole) elif request.POST['action'] == '_print': trn = request.user.profile.tournament template = cleaned_data['template'] context = context_generator.persons(ps) fileprefix = "persons-%s-v" % slugify(template.name) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) res = render_to_pdf.delay(template.id, pdf.id, context=context) pdf.task_id = res.id pdf.save() pdf.tags.add( PdfTag.objects.get(tournament=trn, type=Template.PERSONS)) elif request.POST['action'] == '_juror': conflict_field = cleaned_data['conflicting'] for att in ps: ju, cre = Juror.objects.get_or_create(attendee=att) if cre: try: # TODO: hat if member of 2 teams ori = {att.teammember_set.first().team.origin} except: ori = set() if conflict_field: try: apv = att.attendeepropertyvalue_set.filter( property=conflict_field).last() conflicting = set(apv.conflict_origins.all()) | ori except: conflicting = ori else: conflicting = ori ju.conflicting.set(conflicting) try: pj = att.active_user.possiblejuror_set.get( tournament=att.tournament, approved_by__isnull=False) exp = pj.experience except: exp = Juror.EXPERIENCE_LOW ju.experience = exp ju.save() return redirect('plan:persons')
def done_actions(self, request, cleaned_data): if request.POST['action'] == '_print': trn = request.user.profile.tournament template = cleaned_data['template'] context = context_generator.registration(cleaned_data['obj_list']) fileprefix = "registration-%s-v" % slugify(template.name) pdf = Pdf.objects.create( name="%s%d" % (fileprefix, _get_next_pdfname(trn, fileprefix)), tournament=trn) res = render_to_pdf.delay(template.id, pdf.id, context=context) pdf.task_id = res.id pdf.save() pdf.tags.add( PdfTag.objects.get(tournament=trn, type=Template.REGISTRATION)) elif request.POST['action'] == '_download': ap = cleaned_data["download"] response = HttpResponse(content_type='application/zip') zip_file = zipfile.ZipFile(response, 'w') for att in cleaned_data['obj_list']: try: apv = att.attendeepropertyvalue_set.filter( property=ap).last() img = apv.image_value file = os.path.join(settings.MEDIA_ROOT, img.name) zipname = os.path.join( "%d-%s" % (ap.id, slugify(ap.name)), "%d-%s-%s" % (att.id, slugify( att.full_name), img.name.split("/")[-1])) zip_file.write(file, zipname) except Exception as e: print(e) pass zip_file.close() response['Content-Disposition'] = 'attachment; filename={}'.format( "images.zip") return response elif request.POST['action'] == '_set_parameters': for att in cleaned_data['obj_list']: for ap in self.aps_forms: ap_set = cleaned_data["ap_%d_set" % ap.id] ap_val = cleaned_data["ap_%d" % ap.id] if ap_set: try: apv = att.attendeepropertyvalue_set.filter( property=ap).last() except: apv = None update_property(request, ap, apv, ap_val, "attendee-property-%d", AttendeePropertyValue, { "attendee": att, "author": request.user.profile }, copy_image=False, prelim=False) elif request.POST['action'] == '_mailto': pass