Skip to content

Commit

Permalink
get eventbrite id from url
Browse files Browse the repository at this point in the history
  • Loading branch information
elichad committed Nov 20, 2023
1 parent 52ede58 commit c6d2267
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
16 changes: 16 additions & 0 deletions amy/extrequests/templatetags/eventbrite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import template
import regex

register = template.Library()

# Eventbrite IDs are long strings of digits (~12 characters)
EVENTBRITE_ID_PATTERN = regex.compile(r"\d{10,}")


@register.simple_tag
def eventbrite_id_from_url(url: str) -> str:
if not isinstance(url, str):
return url

re = regex.search(EVENTBRITE_ID_PATTERN, url)
return re.group() if re else url
34 changes: 34 additions & 0 deletions amy/extrequests/tests/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from django.test import TestCase

from extrequests.templatetags.eventbrite import eventbrite_id_from_url
from amy.extrequests.templatetags.request_membership import (
membership_active,
membership_alert_type,
)

from workshops.models import Membership


Expand Down Expand Up @@ -98,3 +100,35 @@ def test_inactive(self):

# Assert
self.assertEqual(expected, result)


class TestEventbriteIdFromUrl(TestCase):
def test_long_url(self):
# Arrange
url = "https://www.eventbrite.com/e/online-instructor-training-7-8-november-2023-tickets-711575811407?aff=oddtdtcreator" # noqa: line too long

# Act
result = eventbrite_id_from_url(url)

# Assert
self.assertEqual(result, "711575811407")

def test_short_url(self):
# Arrange
url = "https://www.eventbrite.com/e/711575811407"

# Act
result = eventbrite_id_from_url(url)

# Assert
self.assertEqual(result, "711575811407")

def test_admin_url(self):
# Arrange
url = "https://www.eventbrite.com/myevent?eid=711575811407"

# Act
result = eventbrite_id_from_url(url)

# Assert
self.assertEqual(result, "711575811407")
9 changes: 9 additions & 0 deletions amy/templates/requests/all_trainingrequests.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% load tags %}
{% load state %}
{% load static %}
{% load eventbrite %}

{% block content %}
{% if requests %}
Expand All @@ -20,6 +21,7 @@
<th><input type="checkbox" select-all-checkbox /></th>
<th>Submitter</th>
<th>Reg. Code</th>
<th>Eventbrite ID</th>
<th>Affiliation
<i class="fas fa-question-circle"
data-toggle="popover" data-html="true" data-trigger="hover"
Expand Down Expand Up @@ -62,6 +64,13 @@
&lt;{{ req.email|urlize }}&gt;
</td>
<td>{{ req.member_code|default:"—" }}</td>
<td>
{% if req.eventbrite_url %}
{% eventbrite_id_from_url req.eventbrite_url %}
{% else %}
{% endif %}
</td>
<td>
{{ req.affiliation|default:"—" }}
{% if req.person %}
Expand Down
7 changes: 6 additions & 1 deletion amy/workshops/management/commands/fake_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ def fake_training_request(self, person_or_None):
underrepresented_choices = TrainingRequest._meta.get_field(
"underrepresented"
).choices
eventbrite_url = self.faker.url() if registration_code and randbool(0.5) else ""
eventbrite_url = ""
if registration_code and randbool(0.5):
eventbrite_url = (
"https://eventbrite.com/fake-"
f"{self.faker.random_number(digits=12, fix_len=True)}"
)
req = TrainingRequest.objects.create(
state=state,
person=person_or_None,
Expand Down

0 comments on commit c6d2267

Please sign in to comment.