Skip to content

Commit

Permalink
Add attendee type to schema
Browse files Browse the repository at this point in the history
Signed-off-by: Nabarun Pal <pal.nabarun95@gmail.com>
  • Loading branch information
palnabarun committed Sep 24, 2020
1 parent 4ade3eb commit 0ce41c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion badges/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from typing import TypeVar, Union
from uuid import uuid4, UUID
from uuid import uuid4

from flask_sqlalchemy import SQLAlchemy
from psycopg2.errors import UniqueViolation
Expand All @@ -12,6 +12,7 @@


UUID_PATTERN = re.compile(r"^[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}$", re.IGNORECASE)
VALID_ATTENDEE_TYPES = ["attendee", "speaker", "volunteer"]


class Attendee(db.Model):
Expand All @@ -34,11 +35,23 @@ class Attendee(db.Model):
username = db.Column(TEXT, index=True)
twitter_id = db.Column(TEXT)
about = db.Column(TEXT)
type = db.Column(TEXT, default="attendee")

@property
def id(self) -> str:
return self.username or self.uuid

def set_type(self, type: str):
if type not in VALID_ATTENDEE_TYPES:
raise ValueError(
"Attendee type has to be one of {}".format(
", ".join(VALID_ATTENDEE_TYPES)
)
)

self.type = type
self.update()

def update(self):
db.session.add(self)
db.session.commit()
Expand Down
8 changes: 7 additions & 1 deletion badges/templates/badge.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ <h1 class="title">Your PyCon India 2020 Badge</h1>
</div>
<div class="badge-footer">
<div class="flex">
{% if attendee.type == "speaker" %}
<span style="background: #F10000; color: #ffffff;">Speaker</span>
{% elif attendee.type == "volunteer" %}
<span style="background: #F10000; color: #ffffff;">Volunteer</span>
{% else %}
<span style="background: #F10000; color: #ffffff;">Attendee</span>
<span style="background: #FFC600; color: #F10000;">No {{ attendee.booking_id }}</span>
{% endif %}
<span style="background: #FFC600; color: #F10000;"># {{ attendee.booking_id }}</span>
</div>
</div>
</div>
Expand Down

0 comments on commit 0ce41c4

Please sign in to comment.