Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Handled the problems with NFC cards not working independently across …
Browse files Browse the repository at this point in the history
…different events.
  • Loading branch information
miteshashar committed Jul 23, 2013
1 parent f109030 commit d79f5a3
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 25 deletions.
26 changes: 26 additions & 0 deletions alembic/versions/4cdaf9d17f49_removed_nfc_id_colum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Removed nfc_id column
Revision ID: 4cdaf9d17f49
Revises: 54f5351fbf9e
Create Date: 2013-07-24 00:18:53.214415
"""

# revision identifiers, used by Alembic.
revision = '4cdaf9d17f49'
down_revision = '54f5351fbf9e'

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('participant', u'nfc_id')
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('participant', sa.Column(u'nfc_id', sa.VARCHAR(length=80), nullable=True))
### end Alembic commands ###
26 changes: 26 additions & 0 deletions alembic/versions/4d30ec36e917_unique_constraint_is.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Unique constraint is now on nfc_id+event
Revision ID: 4d30ec36e917
Revises: a48e1f6838c
Create Date: 2013-07-24 00:22:01.199548
"""

# revision identifiers, used by Alembic.
revision = '4d30ec36e917'
down_revision = 'a48e1f6838c'

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint("uq_participant_nfc_id", "participant", ["event_id", "nfc_id"])
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("uq_participant_nfc_id", "participant")
### end Alembic commands ###
26 changes: 26 additions & 0 deletions alembic/versions/a48e1f6838c_reintroduced_nfc_id_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Reintroduced nfc_id column
Revision ID: a48e1f6838c
Revises: 4cdaf9d17f49
Create Date: 2013-07-24 00:19:56.136286
"""

# revision identifiers, used by Alembic.
revision = 'a48e1f6838c'
down_revision = '4cdaf9d17f49'

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.add_column('participant', sa.Column('nfc_id', sa.Unicode(length=80), nullable=True))
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('participant', 'nfc_id')
### end Alembic commands ###
3 changes: 2 additions & 1 deletion peopleflow/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Participant(db.Model, BaseMixin):
#: Date of registration
regdate = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
#:NFC ID
nfc_id = db.Column(db.Unicode(80), unique=True, nullable=True, default=None)
nfc_id = db.Column(db.Unicode(80), nullable=True, default=None)
#: Source of registration, whether online(True) or offline(False)
online_reg = db.Column(db.Boolean, default=True, nullable=True)
#: Order ID
Expand All @@ -56,6 +56,7 @@ class Participant(db.Model, BaseMixin):
#: Event the participant is attending
event_id = db.Column(db.Integer, db.ForeignKey('event.id'))

__table_args__ = (db.UniqueConstraint('event_id', 'nfc_id'),)

def __repr__(self):
return self.name
14 changes: 7 additions & 7 deletions peopleflow/templates/participants.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ <h1>{{ event.title }}- Venue Signup. </h1>
<a class="btn rfid_card {%- if p.attended %} assigned {%- else %} unassigned {%- endif %}"
rel="{{ p.id }}"
href="javascript:void(0);">
<span class="assign" data-url="{{ url_for('event_signin', event=event.id) }}">Assign Card</span>
<span class="assign" data-url="{{ url_for('event_signin', event=event.id, participant=p.id) }}">Assign Card</span>
<span class="unassign" data-url="{{ url_for('event_signout', event=event.id, participant=p.id) }}">Unassign Card</span>
<span class="unassign_confirm" data-url="{{ url_for('event_signout', event=event.id, participant=p.id) }}">Pls confirm (<span class="timeout"></span>)</span>
<span class="tap_card" data-url="{{ url_for('event_signin', event=event.id) }}">Tap the card (<span class="timeout"></span>)</span>
<span class="tap_card" data-url="{{ url_for('event_signin', event=event.id, participant=p.id) }}">Tap the card (<span class="timeout"></span>)</span>
</a>
<a class="btn print_card" data-url="{{ url_for('print_card') }}" data-method="POST" data-name='{{ p.name|e }}' data-twitter='{{ p.twitter }}'>Print</a>
</td>
Expand Down Expand Up @@ -124,14 +124,14 @@ <h1>{{ event.title }}- Venue Signup. </h1>

if( !assigned ) {
if( typeof card == 'undefined' ) return false;
ajax.data = {nfc_id: card, id: id};
ajax.data = {nfc_id: card};
ajax.success = function( response ) {
if( response == "success") {
if( response.status) {
$('a.rfid_card[rel=' + id + ']').removeClass('unassigned').addClass('assigned');
toastr.success('The badge has been assigned to ' + participant_name);
toastr.success(response.message);
}
else if( response == "id_used") {
toastr.warning('This badge is already assigned to someone.');
else {
toastr.warning(response.message);
}
stop_waiting();
};
Expand Down
36 changes: 21 additions & 15 deletions peopleflow/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,30 @@ def event(event):
utc=utc, tz=tz)


@app.route('/event/<event>/signin', methods=['POST'])
@app.route('/event/<event>/participant/<participant>/signin', methods=['POST'])
@lastuser.requires_permission('registrations')
@load_model(Event, {'id': 'event'}, 'event')
def event_signin(event):
pid = request.form['id']
participant = Participant.query.get(pid)
if participant.attended:
return "Already Signed in"
@load_models(
(Event, {'id': 'event'}, 'event'),
(Participant, {'id': 'participant'}, 'participant')
)
def event_signin(event, participant):
if participant.nfc_id is not None:
return jsonify(status=False, message=u"This participant has already been assigned a badge.")
else:
nfc_id = unicode(request.form['nfc_id'])
participant.nfc_id = nfc_id
participant.attended = True
participant.attend_date = datetime.utcnow()
try:
db.session.commit()
return "success"
except:
return "id_used"
someone = Participant.query.filter_by(nfc_id=nfc_id, event_id=event.id).first()
if someone:
return jsonify(status=False, message=u"This badge is already assigned to %s" % someone.name)
else:
participant.nfc_id = nfc_id
participant.attended = True
participant.attend_date = datetime.utcnow()
try:
db.session.commit()
return jsonify(status=True, message=u"The badge has been successfully assigned to %s" % participant.name)
except:
db.session.rollback()
return jsonify(status=False, message=u"There was an error assigning this badge to %s" % participant.name)


@app.route('/event/<event>/participant/<participant>/status', methods=['GET'])
Expand Down
5 changes: 3 additions & 2 deletions peopleflow/views/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class Part(ParticipantForm):
if form.validate_on_submit():
participant = Participant()
form.populate_obj(participant)
if Participant.query.filter_by(nfc_id=participant.nfc_id, event_id=event.id).first():
flash(u'This badge is already assigned to someone', 'error')
someone = Participant.query.filter_by(nfc_id=participant.nfc_id, event_id=event.id).first()
if someone:
flash(u'This badge is already assigned to %s' % someone.name, 'error')
return render_template('new_participant.html', form=form, event=event)
participant.phone = participant.phone.replace(' ','').replace('-','').strip()
participant.twitter = participant.twitter.replace('@','').strip()
Expand Down

0 comments on commit d79f5a3

Please sign in to comment.