Example #1
0
def CheckIn(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  if request.method == 'GET':
    return render_to_response('reg6/staff/checkin.html',
      {'title': 'Attendee Check In',
      })

  attendees = []
  if request.POST['last_name']:
    attendees = models.Attendee.objects.filter(valid=True,
      last_name__icontains=request.POST['last_name'])
  if not attendees:
    attendees = models.Attendee.objects.filter(valid=True,
      zip=request.POST['zip'])
  for att in attendees:
    if att.checked_in:
      try:
        rp = models.Reprint.objects.get(attendee=att)
        count = rp.count
      except:
        count = 0
      att.rp_count = count + 1

  return render_to_response('reg6/staff/checkin.html',
    {'title': 'Attendee Check In',
     'attendees': attendees,
     'last': request.POST['last_name'],
     'zip': request.POST['zip'],
     'search': 1,
    })
Example #2
0
def index(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')
  return render_to_response('reg6/staff/index.html',
    {'title': 'Staff Page',
    })
Example #3
0
def Reprint(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  if request.method == 'GET':
    return HttpResponseRedirect('/reg6/staff/checkin/')

  if request.POST['id']:
    REPRINT_TEMPLATE = 'reg6/staff/reprint.html'
    try:
      attendee = models.Attendee.objects.get(id=int(request.POST['id']))
      reprint = None
      try:
        reprint = models.Reprint.objects.get(attendee=attendee)
      except:
        reprint = models.Reprint()
        reprint.attendee = attendee
        reprint.count = 0
      reprint.count += 1
      reprint.save()
      return render_to_response(REPRINT_TEMPLATE,
        {'title': 'Attendee Reprint',
         'reprint': reprint,
        })
    except:
      return render_to_response(REPRINT_TEMPLATE,
        {'title': 'Attendee Reprint Error',
         'reprint': None,
        })
  else:
    return render_to_response(REPRINT_TEMPLATE,
      {'title': 'Attendee Reprint Invalid',
       'reprint': None,
      })
Example #4
0
def index(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Review Presentations Overview'

  all = models.Presentation.objects.filter(valid=True)

  approved = all.filter(status='Approved')
  pending = all.filter(status='Pending')
  denied = all.filter(status='Denied')
  cancelled = all.filter(status='Cancelled')
  alternate = all.filter(status='Alternate')

  my_reviews = models.Review.objects.filter(name=request.user)
  (reviewed, unreviewed) = separate_unreviewed_presentations(my_reviews, all)

  return render_to_response('simple_cfp/review/review_index.html',
    {'title': TITLE,
     'all': all,
     'approved': approved,
     'pending': pending,
     'denied': denied,
     'cancelled': cancelled,
     'alternate': alternate,
     'reviewed': reviewed,
     'unreviewed': unreviewed,
    })
Example #5
0
def getpgp(request):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    response = HttpResponse(mimetype="text/plain")

    item = models.Item.objects.get(name=settings.SCALEREG_PGP_KSP_ITEM_NAME)
    for attendee in item.attendee_set.all():
        if attendee.valid:
            valid = "V"
        else:
            valid = "I"

        full_name = "%s %s" % (attendee.first_name, attendee.last_name)
        full_name = full_name.replace(",", " ")
        email = attendee.email.replace(",", " ")

        qindex = settings.SCALEREG_PGP_QUESTION_ID_START
        (key, size, keytype) = GetAttendeePGPData(attendee, qindex)
        response.write("%s,%d,%s,%s,%s,%s,%s\n" % (valid, 1, full_name, email, key, size, keytype))
        qindex += PGP_KEY_QUESTION_INDEX_OFFSET
        (key, size, keytype) = GetAttendeePGPData(attendee, qindex)
        if key != "no pgp key":
            response.write("%s,%d,%s,%s,%s,%s,%s\n" % (valid, 2, full_name, email, key, size, keytype))
    return response
Example #6
0
def Audience(request, id=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Audience'

  try:
    audience = models.Audience.objects.get(id=id)
  except models.Audience.DoesNotExist:
    audience = None
  if not audience:
    return HttpResponseServerError('Unknown id')
  presentations = models.Presentation.objects.filter(audiences=audience)

  my_reviews = models.Review.objects.filter(name=request.user)
  my_reviews = [ r for r in my_reviews
                 if audience in r.presentation.audiences.all() ]
  (reviewed, unreviewed) = separate_unreviewed_presentations(my_reviews,
                                                             presentations)

  return render_to_response('simple_cfp/review/review_list.html',
    {'title': TITLE + ': ' + audience.name,
     'reviewed': reviewed,
     'unreviewed': unreviewed,
    })
Example #7
0
def Speaker(request, id=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Speaker'

  try:
    speaker = models.Speaker.objects.get(id=id)
  except models.Speaker.DoesNotExist:
    speaker = None
  if not speaker:
    return HttpResponseServerError('Unknown id')
  presentations = models.Presentation.objects.filter(speaker=speaker)

  my_reviews = models.Review.objects.filter(name=request.user)
  my_reviews = [ r for r in my_reviews if r.presentation.speaker == speaker ]
  (reviewed, unreviewed) = separate_unreviewed_presentations(my_reviews,
                                                             presentations)

  return render_to_response('simple_cfp/review/review_list.html',
    {'title': TITLE + ': ' + speaker.first_name + ' ' + speaker.last_name,
     'reviewed': reviewed,
     'unreviewed': unreviewed,
     'speaker': speaker,
    })
Example #8
0
def FinishCheckIn(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  if request.method != 'POST':
    return HttpResponseRedirect('/reg6/')

  if 'id' not in request.POST:
    return handler500(request, msg='No ID')

  try:
    attendee = models.Attendee.objects.get(id=request.POST['id'])
  except models.Attendee.DoesNotExist:
    return handler500(request, msg='We could not find your registration')

  try:
    attendee.checked_in = True
    attendee.save()
  except:
    return handler500(request, msg='We encountered a problem with your checkin')

  return render_to_response('reg6/staff/finish_checkin.html',
    {'title': 'Attendee Check In',
     'attendee': attendee,
    })
Example #9
0
def CashPayment(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  tickets = models.Ticket.objects.filter(cash=True)
  if request.method == 'GET':
    return render_to_response('reg6/staff/cash.html',
      {'title': 'Cash Payment',
       'tickets': tickets,
      })

  for var in ['FIRST', 'LAST', 'EMAIL', 'ZIP', 'TICKET']:
    if var not in request.POST:
      return handler500(request, msg='missing data: no %s field' % var)

  try:
    ticket = models.Ticket.objects.get(name=request.POST['TICKET'])
  except:
    return handler500(request, msg='cannot find ticket type')

  order = models.Order()
  bad_order_nums = [ x.order_num for x in models.TempOrder.objects.all() ]
  bad_order_nums += [ x.order_num for x in models.Order.objects.all() ]
  order.order_num = GenerateOrderID(bad_order_nums)
  assert order.order_num
  order.valid = True
  order.name = '%s %s' % (request.POST['FIRST'], request.POST['LAST'])
  order.address = 'Cash'
  order.city = 'Cash'
  order.state = 'Cash'
  order.zip = request.POST['ZIP']
  order.email = request.POST['EMAIL']
  order.payment_type = 'cash'
  order.amount = ticket.price

  attendee = models.Attendee()
  attendee.first_name = request.POST['FIRST']
  attendee.last_name = request.POST['LAST']
  attendee.zip = request.POST['ZIP']
  attendee.email = request.POST['EMAIL']
  attendee.valid = True
  attendee.checked_in = True
  attendee.can_email = True
  attendee.order = order
  attendee.badge_type = ticket
  try:
    attendee.save()
    order.save()
  except: # FIXME catch the specific db exceptions
    attendee.delete()
    order.delete()
    return handler500(request, msg='cannot save order, bad data?')

  return render_to_response('reg6/staff/cash.html',
    {'title': 'Cash Payment',
     'success': True,
     'tickets': tickets,
    })
Example #10
0
def ReviewPresentation(request, id=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Review Presentations'

  try:
    presentation = models.Presentation.objects.get(id=id)
  except models.Presentation.DoesNotExist:
    presentation = None
  if presentation and not presentation.valid:
    presentation = None
  if not presentation:
    return HttpResponseServerError('Unknown id')

  comments = models.Comment.objects.filter(presentation=presentation)

  if request.method == 'POST':
    action = request.POST.get('action')
    if action == 'comment':
      comment_data = request.POST.get('comment')
      if comment_data:
        comment = models.Comment()
        comment.presentation = presentation
        comment.name = request.user
        comment.comment = comment_data
        try:
          comment.save()
        except:
          pass
      # Fall through to default GET response
    elif action == 'delete':
      id = request.POST.get('delete')
      if id:
        try:
          comment = models.Comment.objects.get(id=id)
        except models.Comment.DoesNotExist:
          comment = None
        if comment and comment.name == request.user:
          comment.delete()
      # Fall through to default GET response
    else:
      pass # Ignore, fall through to default GET response

  (score, num_reviews) = get_presentation_score(presentation)

  return render_to_response('simple_cfp/scores/scores_presentation.html',
    {'title': TITLE,
     'comments': comments,
     'num_reviews': num_reviews,
     'presentation': presentation,
     'score': score,
    })
Example #11
0
def index(request):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    model_list = get_model_list(request.user)
    model_list.insert(0, {"name": "Dashboard", "url": "dashboard/"})

    return render_to_response(
        "reports/index.html", {"user": request.user, "title": "Reports", "model_list": model_list}
    )
Example #12
0
def index(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations Scores Overview'

  presentations = models.Presentation.objects.all()
  presentations = process_presentations(presentations)

  return render_to_response('simple_cfp/scores/scores_index.html',
    {'title': TITLE,
     'presentations': presentations,
    })
Example #13
0
def StatusIndex(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'List of Status'
  TYPE = 'status'

  status = models.STATUS_CHOICES
  return render_to_response('simple_cfp/scores/scores_by_type_index.html',
    {'title': TITLE,
     'type': TYPE,
     'list': status,
    })
Example #14
0
def CategoryIndex(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'List of Categories'
  TYPE = 'category'

  categories = models.Category.objects.all()
  categories = [ (obj.id, obj.name) for obj in categories ]
  return render_to_response('simple_cfp/scores/scores_by_type_index.html',
    {'title': TITLE,
     'type': TYPE,
     'list': categories,
    })
Example #15
0
def AudienceIndex(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'List of Audiences'
  TYPE = 'audience'

  audiences = models.Audience.objects.all()
  audiences = [ (obj.id, obj.name) for obj in audiences ]
  return render_to_response('simple_cfp/review/review_by_type_index.html',
    {'title': TITLE,
     'type': TYPE,
     'list': audiences,
    })
Example #16
0
def SpeakerIndex(request):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'List of Speakers'
  TYPE = 'speaker'

  speakers = models.Speaker.objects.all()
  speakers = [ (obj.id, '%s %s' % (obj.first_name, obj.last_name))
               for obj in speakers ]
  return render_to_response('simple_cfp/scores/scores_by_type_index.html',
    {'title': TITLE,
     'type': TYPE,
     'list': speakers,
    })
Example #17
0
def Status(request, status=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Status'

  if status not in [ choice[0] for choice in models.STATUS_CHOICES ]:
    status = None
  if not status:
    return HttpResponseServerError('Unknown status')
  presentations = models.Presentation.objects.filter(status=status)
  presentations = process_presentations(presentations)

  return render_to_response('simple_cfp/scores/scores_index.html',
    {'title': TITLE,
     'presentations': presentations,
    })
Example #18
0
def Category(request, id=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Category'

  try:
    category = models.Category.objects.get(id=id)
  except models.Category.DoesNotExist:
    category = None
  if not category:
    return HttpResponseServerError('Unknown id')
  presentations = models.Presentation.objects.filter(categories=category)
  presentations = process_presentations(presentations)

  return render_to_response('simple_cfp/scores/scores_list.html',
    {'title': TITLE + ': ' + category.name,
     'presentations': presentations,
    })
Example #19
0
def Audience(request, id=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Audience'

  try:
    audience = models.Audience.objects.get(id=id)
  except models.Audience.DoesNotExist:
    audience = None
  if not audience:
    return HttpResponseServerError('Unknown id')
  presentations = models.Presentation.objects.filter(audiences=audience)
  presentations = process_presentations(presentations)

  return render_to_response('simple_cfp/scores/scores_list.html',
    {'title': TITLE + ': ' + audience.name,
     'presentations': presentations,
    })
Example #20
0
def Speaker(request, id=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Speaker'

  try:
    speaker = models.Speaker.objects.get(id=id)
  except models.Speaker.DoesNotExist:
    speaker = None
  if not speaker:
    return HttpResponseServerError('Unknown id')
  presentations = models.Presentation.objects.filter(speaker=speaker)
  presentations = process_presentations(presentations)

  return render_to_response('simple_cfp/scores/scores_list.html',
    {'title': TITLE + ': ' + speaker.first_name + ' ' + speaker.last_name,
     'presentations': presentations,
     'speaker': speaker,
    })
Example #21
0
def badorder(request):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    response = HttpResponse(mimetype="text/plain")
    response.write("Bad orders:\n")
    order_invitees = models.Order.objects.filter(payment_type="invitee")
    order_exhibitors = models.Order.objects.filter(payment_type="exhibitor")
    order_speakers = models.Order.objects.filter(payment_type="speaker")
    order_press = models.Order.objects.filter(payment_type="press")
    free_orders = order_invitees | order_exhibitors | order_speakers | order_press
    for f in free_orders.filter(amount__gt=0):
        response.write("Free Order costs money: %s %s\n" % (f.order_num, f.name))

    bad_orders = models.Order.objects.filter(valid=False)
    for g in bad_orders:
        for f in g.attendee_set.all():
            if f.valid:
                response.write("Invalid Order: %d %s %s\n" % (f.id, f.first_name, f.last_name))

    valid_orders = models.Order.objects.filter(valid=True)
    order_verisign = valid_orders.filter(payment_type="verisign")
    order_google = valid_orders.filter(payment_type="google")
    order_cash = valid_orders.filter(payment_type="cash")
    paid_orders = order_verisign | order_google | order_cash
    valid_upgrades = models.Upgrade.objects.filter(valid=True)
    for f in paid_orders:
        if f.attendee_set.count() == 0 and not valid_upgrades.filter(old_order=f):
            response.write("Empty Order: %s %s\n" % (f.order_num, f.name))
    for f in paid_orders.filter(amount__lte=0):
        response.write("Paid Order with $0 cost: %s %s\n" % (f.order_num, f.name))

    attendees = models.Attendee.objects.filter(valid=True)
    no_order = attendees.filter(order__isnull=True)
    for f in no_order:
        response.write("No order: %d %s %s\n" % (f.id, f.first_name, f.last_name))

    return response
Example #22
0
def Status(request, status=None):
  can_access = services_perm_checker(request.user, request.path)
  if not can_access:
    return HttpResponseRedirect('/accounts/profile/')

  TITLE = 'Presentations by Status'

  if status not in [ choice[0] for choice in models.STATUS_CHOICES ]:
    status = None
  if not status:
    return HttpResponseServerError('Unknown status')
  presentations = models.Presentation.objects.filter(status=status)

  my_reviews = models.Review.objects.filter(name=request.user)
  my_reviews = [ r for r in my_reviews if r.presentation.status == status ]
  (reviewed, unreviewed) = separate_unreviewed_presentations(my_reviews,
                                                             presentations)

  return render_to_response('simple_cfp/review/review_list.html',
    {'title': TITLE + ': ' + status,
     'reviewed': reviewed,
     'unreviewed': unreviewed,
    })
Example #23
0
def object_list(
    request,
    queryset,
    paginate_by=None,
    page=None,
    allow_empty=False,
    template_name=None,
    template_loader=loader,
    extra_context=None,
    context_processors=None,
    template_object_name="object",
    mimetype=None,
):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    model_list = get_model_list(request.user)
    can_access = False
    for f in model_list:
        if re.compile("/reports/%s.*" % f["url"]).match(request.path):
            can_access = True
            break
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    all_fields = [f.name for f in queryset.model._meta.fields]

    if not extra_context:
        extra_context = {}

    if "admin_user" not in extra_context:
        if request.user.is_staff:
            extra_context["admin_user"] = True

    if "title" not in extra_context:
        extra_context["title"] = queryset.model._meta.verbose_name_plural.title()

    if "field_list" not in extra_context:
        extra_context["field_list"] = all_fields

    filter_select = {}
    for i in xrange(len(all_fields)):
        name = all_fields[i]
        filter = Filter(name)
        field_type = type(queryset.model._meta.fields[i])
        if field_type == BooleanField:
            filter.items[-1] = Item("All", -1)
            filter.items[0] = Item("False", 0)
            filter.items[1] = Item("True", 1)
        else:
            continue
        filter_select[name] = filter

    urlparts = []
    for f in request.GET:
        if not f.startswith("filter__"):
            continue
        urlparts.append("%s=%s&" % (f, request.GET[f]))
        name = f[8:]
        field_type = type(queryset.model._meta.fields[all_fields.index(name)])
        if name and name in filter_select:
            if field_type == BooleanField:
                filter = filter_select[name]
                try:
                    value = int(request.GET[f])
                except ValueError:
                    continue
                if value in filter.items and value != -1:
                    filter.selected = value
                    query_string = "%s = %%s" % paranoid_strip(name)
                    queryset = queryset.extra(where=[query_string], params=[value])
    extra_context["filter_select"] = filter_select.values()
    extra_context["urlpart"] = "".join([part for part in urlparts])

    extra_context["numbers"] = queryset.count()

    return django_object_list(
        request,
        queryset,
        paginate_by,
        page,
        allow_empty,
        template_name,
        template_loader,
        extra_context,
        context_processors,
        template_object_name,
        mimetype,
    )
Example #24
0
def checkpgp(request):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    if request.method == "GET":
        response = HttpResponse()
        response.write('<html><head></head><body><form method="post">')
        response.write("<p>email address(es) to check</p>")
        response.write('<textarea name="data" rows="25" cols="80"></textarea>')
        response.write('<br /><input type="submit" /></form>')
        response.write("</body></html>")
        return response

    if "data" not in request.POST:
        return HttpResponse("No Data")

    item = models.Item.objects.get(name=settings.SCALEREG_PGP_KSP_ITEM_NAME)
    attendees = item.attendee_set

    response = HttpResponse(mimetype="text/plain")
    data = request.POST["data"].split("\n")

    qpgp = []
    start = settings.SCALEREG_PGP_QUESTION_ID_START
    stop = start + 2 * PGP_KEY_QUESTION_INDEX_OFFSET
    for i in range(start, stop):
        qpgp.append(models.Question.objects.get(id=i))

    for email in data:
        email = email.strip()
        if not email:
            continue
        response.write("----\n")
        attendee = None
        try:
            attendee = attendees.get(email=email)
        except:
            pass

        if not attendee:
            attendees_with_email = models.Attendee.objects.filter(email=email)
            response.write("ERROR: ")
            if attendees_with_email:
                response.write("found attendee with email %s, " "but not signed up for KSP\n" % email)
            else:
                response.write("cannot find attendee with email %s\n" % email)
            continue

        try:
            answer = attendee.answers.get(question=qpgp[0])
            response.write("fingerprint 1: %s\n" % answer)
        except:
            response.write("no fingerprint 1\n")
        try:
            answer = attendee.answers.get(question=qpgp[1])
            response.write("size 1: %s\n" % answer)
        except:
            response.write("no size 1\n")
        try:
            answer = attendee.answers.get(question=qpgp[2])
            response.write("type 1: %s\n" % answer)
        except:
            response.write("no type 1\n")
        try:
            answer = attendee.answers.get(question=qpgp[3])
            response.write("fingerprint 2: %s\n" % answer)
        except:
            response.write("no fingerprint 2\n")
        try:
            answer = attendee.answers.get(question=qpgp[4])
            response.write("size 2: %s\n" % answer)
        except:
            response.write("no size 2\n")
        try:
            answer = attendee.answers.get(question=qpgp[5])
            response.write("type 2: %s\n" % answer)
        except:
            response.write("no type 2\n")

    return response
Example #25
0
def putpgp(request):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    if request.method == "GET":
        response = HttpResponse()
        response.write('<html><head></head><body><form method="post">')
        response.write("<p>email, nth (1 or 2), fingerprint, size, type (RSA or DSA)</p>")
        response.write('<textarea name="data" rows="25" cols="80"></textarea>')
        response.write('<br /><input type="submit" /></form>')
        response.write("</body></html>")
        return response

    if "data" not in request.POST:
        return HttpResponse("No Data")

    item = models.Item.objects.get(name=settings.SCALEREG_PGP_KSP_ITEM_NAME)
    attendees = item.attendee_set.filter(valid=True)

    response = HttpResponse(mimetype="text/plain")
    data = request.POST["data"].split("\n")

    qpgp = []
    start = settings.SCALEREG_PGP_QUESTION_ID_START
    stop = start + 2 * PGP_KEY_QUESTION_INDEX_OFFSET
    for i in range(start, stop):
        qpgp.append(models.Question.objects.get(id=i))

    for entry in data:
        entry = entry.strip()
        if not entry:
            continue
        entry_split = entry.split(",")
        if len(entry_split) != 5:
            response.write("bad data: %s<br />\n" % entry)
            continue
        (email, nth, fingerprint, size, keytype) = entry_split
        email = email.strip()
        nth = nth.strip()
        fingerprint = fingerprint.strip()
        size = size.strip()
        keytype = keytype.strip()

        if nth == "1":
            qfingerprint = qpgp[0]
            qsize = qpgp[1]
            qkeytype = qpgp[2]
        elif nth == "2":
            qfingerprint = qpgp[3]
            qsize = qpgp[4]
            qkeytype = qpgp[5]
        else:
            response.write("bad data (nth): %s<br />\n" % entry)
            continue

        try:
            int(size)
        except:
            response.write("bad size: %s\n" % size)
            continue

        if keytype not in ("RSA", "DSA"):
            response.write("bad fingerprint type: %s" % keytype)
            continue

        try:
            attendee = attendees.get(email=email)
        except:
            response.write("cannot find %s\n" % email)
            continue
        change = True
        try:
            afingerprint = attendee.answers.get(question=qfingerprint)
            asize = attendee.answers.get(question=qsize)
            akeytype = attendee.answers.get(question=qkeytype)
        except:
            change = False

        if change:
            afingerprint.text = fingerprint
            try:
                afingerprint.save()
                response.write("change part 1/3 ok: %s %s => %s\n" % (attendee.email, afingerprint, fingerprint))
            except:
                response.write("change part 1/3 error: %s %s => %s\n" % (attendee.email, afingerprint, fingerprint))
            asize.text = size
            try:
                asize.save()
                response.write("change part 2/3 ok: %s %s => %s\n" % (attendee.email, asize, size))
            except:
                response.write("change part 2/3 error: %s %s => %s\n" % (attendee.email, asize, size))
            akeytype.text = keytype
            try:
                akeytype.save()
                response.write("change part 3/3 ok: %s %s => %s\n" % (attendee.email, akeytype, keytype))
            except:
                response.write("change part 3/3 error: %s %s => %s\n" % (attendee.email, akeytype, keytype))
        else:
            afingerprint = models.TextAnswer()
            afingerprint.question = models.Question.objects.get(id=qfingerprint.id)
            afingerprint.text = fingerprint
            try:
                afingerprint.save()
                response.write("add part 1/4 ok: %s %s => %s\n" % (attendee.email, afingerprint, fingerprint))
            except:
                response.write("add part 1/4 error: %s %s => %s\n" % (attendee.email, afingerprint, fingerprint))
                continue
            asize = models.TextAnswer()
            asize.question = models.Question.objects.get(id=qsize.id)
            asize.text = size
            try:
                asize.save()
                response.write("add part 2/4 ok: %s %s => %s\n" % (attendee.email, asize, size))
            except:
                response.write("add part 2/4 error: %s %s => %s\n" % (attendee.email, asize, size))
                continue
            akeytype = models.TextAnswer()
            akeytype.question = models.Question.objects.get(id=qkeytype.id)
            akeytype.text = keytype
            try:
                akeytype.save()
                response.write("add part 3/4 ok: %s %s => %s\n" % (attendee.email, akeytype, keytype))
            except:
                response.write("add part 3/4 error: %s %s => %s\n" % (attendee.email, akeytype, keytype))
                continue

            try:
                attendee.answers.add(afingerprint)
                attendee.answers.add(asize)
                attendee.answers.add(akeytype)
                attendee.save()
                response.write("add part 4/4 ok: %s\n" % attendee.email)
            except:
                response.write("add part 4/4 error: %s\n" % attendee.email)
                continue
    return response
Example #26
0
def dashboard(request):
    can_access = services_perm_checker(request.user, request.path)
    if not can_access:
        return HttpResponseRedirect("/accounts/profile/")

    today = datetime.date.today()
    days_30 = today - datetime.timedelta(days=30)
    days_7 = today - datetime.timedelta(days=7)

    orders_data = {}
    orders_data["by_type"] = []
    orders = models.Order.objects.filter(valid=True)
    orders_data["numbers"] = orders.count()
    orders_data["revenue"] = sum([x.amount for x in orders])
    orders_30 = orders.filter(date__gt=days_30)
    orders_data["numbers_30"] = orders_30.count()
    orders_data["revenue_30"] = sum([x.amount for x in orders_30])
    orders_7 = orders_30.filter(date__gt=days_7)
    orders_data["numbers_7"] = orders_7.count()
    orders_data["revenue_7"] = sum([x.amount for x in orders_7])
    for pt in models.PAYMENT_CHOICES:
        orders_pt = orders.filter(payment_type=pt[0])
        data_pt = {}
        data_pt["name"] = pt[1]
        data_pt["numbers"] = orders_pt.count()
        data_pt["revenue"] = sum([x.amount for x in orders_pt])
        orders_pt_30 = orders_pt.filter(date__gt=days_30)
        data_pt["numbers_30"] = orders_pt_30.count()
        orders_pt_7 = orders_pt_30.filter(date__gt=days_7)
        data_pt["numbers_7"] = orders_pt_7.count()
        orders_data["by_type"].append(data_pt)

    attendees_data = {}
    attendees = models.Attendee.objects.filter(valid=True)
    num_attendees = attendees.count()
    attendees_data["numbers"] = num_attendees
    attendees_data["checked_in"] = attendees.filter(checked_in=True).count()

    type_attendees_data = {}
    ticket_attendees_data = {}
    for att in attendees:
        att_type = att.badge_type.type
        if att_type not in type_attendees_data:
            type_attendees_data[att_type] = Attendee(att_type)
        type_attendees_data[att_type].count += 1
        if att.checked_in:
            type_attendees_data[att_type].checked_in += 1

        att_ticket = att.badge_type.name
        if att_ticket not in ticket_attendees_data:
            ticket_attendees_data[att_ticket] = Count(att_ticket)
        ticket_attendees_data[att_ticket].count += 1
    type_attendees_data = type_attendees_data.items()
    type_attendees_data.sort()
    type_attendees_data = [v[1] for v in type_attendees_data]
    for t in type_attendees_data:
        t.CalcPercentage(num_attendees)
    ticket_attendees_data = ticket_attendees_data.items()
    ticket_attendees_data.sort()
    ticket_attendees_data = [v[1] for v in ticket_attendees_data]
    for t in ticket_attendees_data:
        t.CalcPercentage(num_attendees)

    promo_attendees_data = {}
    promo_attendees_data[None] = Count("None")
    for att in attendees:
        if att.promo:
            promo = att.promo.name
        else:
            promo = None
        if promo not in promo_attendees_data:
            promo_attendees_data[promo] = Count(promo)
        promo_attendees_data[promo].count += 1
    promo_attendees_data = promo_attendees_data.items()
    promo_attendees_data.sort()
    promo_attendees_data = [v[1] for v in promo_attendees_data]
    for p in promo_attendees_data:
        p.CalcPercentage(num_attendees)

    zipcode_orders_data = {}
    for x in orders:
        if x.zip not in zipcode_orders_data:
            zipcode_orders_data[x.zip] = Count(x.zip)
        zipcode_orders_data[x.zip].count += 1
    zipcode_orders_data = zipcode_orders_data.items()
    zipcode_orders_data.sort()
    zipcode_orders_data = [v[1] for v in zipcode_orders_data]
    for zip in zipcode_orders_data:
        zip.CalcPercentage(orders_data["numbers"])

    zipcode_attendees_data = {}
    for att in attendees:
        if att.zip not in zipcode_attendees_data:
            zipcode_attendees_data[att.zip] = Count(att.zip)
        zipcode_attendees_data[att.zip].count += 1
    zipcode_attendees_data = zipcode_attendees_data.items()
    zipcode_attendees_data.sort()
    zipcode_attendees_data = [v[1] for v in zipcode_attendees_data]
    for zip in zipcode_attendees_data:
        zip.CalcPercentage(num_attendees)

    questions_data = []
    questions = models.Question.objects.all()

    all_answers = {}
    for ans in models.Answer.objects.all():
        all_answers[ans.text] = Count(ans.text)

    for att in attendees:
        for ans in att.answers.all():
            all_answers[ans.text].count += 1

    for q in questions:
        possible_answers = q.answer_set.all()
        q_data = SurveyQuestion(q.text)
        for ans in possible_answers:
            a_data = all_answers[ans.text]
            a_data.CalcPercentage(num_attendees)
            q_data.answers.append(a_data)
        a_data = Count("No Answer")
        a_data.count = num_attendees - sum([x.count for x in q_data.answers])
        a_data.CalcPercentage(num_attendees)
        q_data.answers.append(a_data)
        questions_data.append(q_data)

    addon_attendees_data = {}
    unique_addon_attendees_data = Count("Unique")
    for att in attendees:
        if len(att.ordered_items.all()) > 0:
            unique_addon_attendees_data.count += 1
        for add in att.ordered_items.all():
            if add.name not in addon_attendees_data:
                addon_attendees_data[add.name] = Count(add.name)
            addon_attendees_data[add.name].count += 1
    addon_attendees_data = addon_attendees_data.items()
    addon_attendees_data.sort()
    addon_attendees_data = [v[1] for v in addon_attendees_data]
    for zip in addon_attendees_data:
        zip.CalcPercentage(num_attendees)
    unique_addon_attendees_data.CalcPercentage(num_attendees)

    return render_to_response(
        "reports/dashboard.html",
        {
            "title": "Dashboard",
            "addon_attendees": addon_attendees_data,
            "attendees": attendees_data,
            "orders": orders_data,
            "promo_attendees": promo_attendees_data,
            "questions": questions_data,
            "ticket_attendees": ticket_attendees_data,
            "type_attendees": type_attendees_data,
            "unique_addon_attendees": unique_addon_attendees_data,
            "zipcode_attendees": zipcode_attendees_data,
            "zipcode_orders": zipcode_orders_data,
        },
    )