def api_checkout(req, uid): if not req.user.is_staff: raise PermissionDenied user = get_object_or_404(MUser, id=MUser.get_real_id(uid)) user.profile.checked_in = False user.profile.save() return HttpResponse()
def recipt_view(req, rid=None): user = None # allow admins to access receipts using ids if rid is not None and req.user.is_authenticated() and req.user.is_staff: try: uid = int(rid) # guard the improbable case where hash is all numeric if uid < 999999: user = get_object_or_404(MUser, id=MUser.get_real_id(uid)) except: pass if user is None: if rid is not None: user = get_object_or_404(Profile, receipt_id=rid).user else: if not req.user.is_authenticated(): raise Http404 user = req.user registrations = Registration.objects.filter(profile=user.profile) workshops = user.profile.registered_workshops.all() if settings.DEBUG: template = 'magnovite/recipt.html' else: template = 'magnovite/dist/recipt.html' return render(req, template, { 'user': user, 'profile': user.profile, 'registrations': registrations, 'workshops': workshops })
def all_csv(req): if not req.user.is_superuser: raise PermissionDenied try: min_id = int(req.GET.get('from_id', '0')) except ValueError: return HttpResponse(status=400) EVENT_MAP = { 'DEFC':1, 'DANC':4, 'GCS':5, 'CTYC':6, 'WEBD':7, 'TEKH':8, 'PRJ':9, 'CADM':11, 'JYW':12, 'CANG':13, 'LDSC':14, 'BLDR':15, 'PPR':16, 'RBW':18, 'WATR':19, 'LINE':20, 'CDBG':21, 'THT':22, 'CMCS':23, 'ARTR':24, 'PHOT':25, 'DMBC':26, 'QUIZ':27, 'POTP':28, 'JAM':29, 'DBTE':31, 'INDM':32, 'WSEL':33, 'ACOU':34, 'KRKE':35, 'BBOY':36, 'SWTCH':37, 'OVNC':38, 'ANDV':39, 'GNFS':40, 'CADC':41, 'INSW':42, 'SOLO':44, } INV_EVENT_MAP = {v: k for k, v in EVENT_MAP.items()} base = Profile.objects.filter(id__gt=MUser.get_real_id(min_id)) not_none = base.filter(~Q(pack='none')).prefetch_related('user') only_group = base.filter(pack='none') only_group = only_group.annotate(Count('registered_events')) only_group = only_group.filter(registered_events__count__gt=0).prefetch_related('user') not_none = not_none.prefetch_related('registered_events') only_group = only_group.prefetch_related('registered_events') out = [] for obj in list(not_none) + list(only_group): if obj.pack == 'single': type = 'Single' elif obj.pack == 'multiple': type = 'Multiple' else: type = 'Group' event = '-' if type == 'Single': _event = obj.registered_events.first() if _event: event = INV_EVENT_MAP[_event.id] elif type == 'Group': for _event in obj.registered_events.all(): if event == '-': event = '' event = INV_EVENT_MAP[_event.id] + ', ' event = event.strip(' ,') out.append([ obj.user.get_id(), #id obj.name.title(), #name obj.college, #college type, # type event ]) # mark all selected as id printed not_none.update(id_printed=True) for obj in only_group: obj.id_printed = True obj.save() out = sorted(out, key=lambda x: int(x[0])) filename = 'mag_' + str(out[0][0]) + '_' + str(out[-1][0]) + '.csv' response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="' + filename + '"' writer = csv.writer(response) for row in out: writer.writerow(row) return response