Skip to content

Commit

Permalink
Closes #301 - Add qr's autoregistration page
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeG committed Apr 5, 2018
1 parent d38ce65 commit 36edbf2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 43 deletions.
58 changes: 26 additions & 32 deletions eventol/manager/templates/registration/attendee/by-autoreadqr.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
<div class="col-md-10 col-md-offset-1" style="font-weight: 500;">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<h1><i class="fa fa-info-warning"></i> {% trans "You are logged in!" %}</h1>
<p>{% trans 'Please close your session, do not leave it open!. This page can remain open without the
need of anybody being logged in. You will be logged out in 30 seconds.' %}
<p>{% blocktrans %} Please close your session, do not leave it open!. This page can remain open without the
need of anybody being logged in. You will be logged out in 30 seconds. {% endblocktrans %}
<a href="{% url 'account_logout' %}?next={{ request.get_full_path|urlencode }}"></a></p>
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-md-10 col-md-offset-1" style="font-weight: 500;">
<h1><i class="fa fa-info-circle"></i> {% trans "Registration Instructions" %}</h1>
<p>
{% trans 'Please scan your ticket using the webcam' %}<br />
{% trans 'Center the QR Code in the camera display below' %}
</p>
</div>
<div class="alert alert-info alert-dismissable">
<div class="row">
<div class="col-md-10 col-md-offset-1" style="font-weight: 500;">
<h1><i class="fa fa-info-circle"></i> {% trans "Registration Instructions" %}</h1>
<p>
{% trans "Please scan your ticket using the webcam" %}<br />
{% trans "Center the QR Code in the camera display below" %}
</p>
</div>
</div>
</div>
{% endblock %}

Expand All @@ -43,7 +45,7 @@ <h1><i class="fa fa-info-circle"></i> {% trans "Registration Instructions" %}</h
{% block buttons %}
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div id="qr_reader" class="qrcode" style="width:300px;height:300px; margin: 0 auto;"></div>
<div id="qr_reader" class="qrcode" style="width:100%;height:50vh; margin: 0 auto; display: flex; justify-content: center;"></div>
<span id="error" class="center"></span>
</div>
</div>
Expand All @@ -54,28 +56,20 @@ <h1><i class="fa fa-info-circle"></i> {% trans "Registration Instructions" %}</h
<script src="{% static "manager/bower_components/html5-qrcode/lib/html5-qrcode.min.js" %}"></script>
<script>
$(document).ready(function () {
$('#QRModal').on('show.bs.modal', function (e) {
$('#qr_reader').empty();//Prevents stacking
$('#qr_reader').html5_qrcode(function (data) {
var url = '{% url "attendance_by_autoreadqr" event_slug event_uid %}';
$(location).attr(
"href",
url + '/?event_registration_code={{ event_registration_code }}&ticket=' + data
);
},
function (readError) {
// From module docs:
// The readError wil be called quite often, it is really only useful for debugging.
// console.log(readError);
}, function (videoError) {
$('#error').html(
'{% trans "There is a problem with the camera. Please, enable access or try manual entry." %}');
}
$('#qr_reader').empty();//Prevents stacking
$('#qr_reader').html5_qrcode(function (data) {
var url = '{% url "attendance_by_autoreadqr" event_slug event_uid %}';
$(location).attr(
"href",
url + '/?event_registration_code={{ event_registration_code }}&ticket=' + data
);
});
$('#QRModal').on('hidden.bs.modal', function (e) {
$('#qr_reader').html5_qrcode_stop()
});
},
function (readError) {},
function (videoError) {
$('#error').html(
'{% trans "There is a problem with the camera. Please, enable access or try manual entry." %}');
}
);
});
</script>
{% endblock %}
29 changes: 18 additions & 11 deletions eventol/manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def attendance_by_autoreadqr(request, event_slug, event_uid):
'index',
args=[event_slug, event_uid]
)
event_registration_code = request.GET('event_registration_code', '')
event_registration_code = request.GET.get('event_registration_code', '')
user = request.user
# Show page w/ reg code for collaborators/organizers
if not event_registration_code \
Expand All @@ -801,7 +801,7 @@ def attendance_by_autoreadqr(request, event_slug, event_uid):
)

# Check if reg code is valid
if not Event.objects.filter(uid=event_uid, registration_code=event_registration_code).exists():
if not event_registration_code or not Event.objects.filter(uid=event_uid, registration_code=event_registration_code).exists():
messages.error(request, _('The registration code does not seems to be valid for this event'))
return redirect(event_index_url)

Expand All @@ -811,18 +811,25 @@ def attendance_by_autoreadqr(request, event_slug, event_uid):
return redirect(event_index_url)

# Check ticket
ticket_code = request.GET('ticket', '')
ticket_code = request.GET.get('ticket', '')
if ticket_code:
try:
attendee = Attendee.objects.get(event=event, ticket__code=ticket_code)
if AttendeeAttendanceDate.objects.filter(attendee=attendee, date=timezone.localdate()).exists():
event_user = EventUser.objects.filter(event=event, ticket__code=ticket_code)
attendee = Attendee.objects.filter(event=event, ticket__code=ticket_code)
if event_user.exists():
event_user = event_user.first()
if EventUserAttendanceDate.objects.filter(event_user=event_user, date__date=timezone.localdate()).exists():
messages.info(request, _('You are already registered and present! Go have fun'))
else:
AttendeeAttendanceDate.objects.create(
attendee=attendee
)
EventUserAttendanceDate.objects.create(event_user=event_user)
messages.info(request, _('You are now marked as present in the event, have fun!'))
elif attendee.exists():
attendee = attendee.first()
if AttendeeAttendanceDate.objects.filter(attendee=attendee, date__date=timezone.localdate()).exists():
messages.info(request, _('You are already registered and present! Go have fun'))
else:
AttendeeAttendanceDate.objects.create(attendee=attendee)
messages.info(request, _('You are now marked as present in the event, have fun!'))
except Attendee.DoesNotExist:
else:
messages.error(request, _('The ticket code is not valid for this event'))

return render(
Expand Down Expand Up @@ -1334,7 +1341,7 @@ def view_ticket(request, event_slug, event_uid):
if event_user:
ticket = generate_ticket(event_user)
response = HttpResponse(cairosvg.svg2pdf(bytestring=ticket), content_type='application/pdf')
response["Content-Disposition"] = 'filename=Ticket-' + str(ticket) + '.pdf'
response["Content-Disposition"] = 'filename=Ticket-' + str(event_user.ticket.code) + '.pdf'
return response
else:
messages.error(request, "You are not registered for this event")
Expand Down

0 comments on commit 36edbf2

Please sign in to comment.