Skip to content

Commit fa82dac

Browse files
authored
Merge pull request #100 from HackAssistant/friends_improvements
Friends improvements
2 parents 5b1a146 + 2370322 commit fa82dac

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

app/hackathon_variables.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
ADMINS = [('Admins', '[email protected]')]
2121

2222
SUPPORTED_RESUME_EXTENSIONS = ['.pdf']
23+
FRIENDS_MAX_CAPACITY = None

event/templates/checkin_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h1 class="">{% translate 'Checkin users' %}{% if admin %} {% translate 'admin'
4747
let scanner = new Scanner('qr-video', (content) => {
4848
if (content.data) {
4949
scanner.stop()
50-
window.location.href = '{% url 'checkin_user' 'replace' %}'.replace('replace', content.data)
50+
window.location.href = '{% url 'checkin_user' 'replace' %}'.replace('replace', encodeURIComponent(content.data))
5151
}
5252
}, {
5353
popup: true,

friends/models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from django.conf import settings
55
from django.db import models
66

7+
from application.models import Application, Edition
8+
79

810
def get_random_string():
911
# With combination of lower, upper case and numbers
@@ -16,5 +18,23 @@ class FriendsCode(models.Model):
1618
code = models.CharField(default=get_random_string, max_length=getattr(settings, "FRIEND_CODE_LENGTH", 13))
1719
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
1820

21+
STATUS_NOT_ALLOWED_TO_JOIN_TEAM = [Application.STATUS_CONFIRMED,
22+
Application.STATUS_INVITED,
23+
Application.STATUS_ATTENDED]
24+
1925
def get_members(self):
2026
return FriendsCode.objects.filter(code=self.code)
27+
28+
def is_closed(self):
29+
edition_pk = Edition.get_default_edition()
30+
return FriendsCode.objects.filter(
31+
code=self.code,
32+
user__application_set__edition_id=edition_pk,
33+
user__application_set__status__in=self.STATUS_NOT_ALLOWED_TO_JOIN_TEAM
34+
).exists()
35+
36+
def reached_max_capacity(self):
37+
friends_max_capacity = getattr(settings, 'FRIENDS_MAX_CAPACITY', None)
38+
if friends_max_capacity is not None and isinstance(friends_max_capacity, int):
39+
return FriendsCode.objects.filter(code=self.code).count() >= friends_max_capacity
40+
return False

friends/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ def join(self, **kwargs):
6363
form = FriendsForm(self.request.POST)
6464
if form.is_valid():
6565
code = form.cleaned_data.get("friends_code", None)
66-
if code is not None and FriendsCode.objects.filter(code=code).exists():
66+
friend_code = FriendsCode.objects.filter(code=code).first()
67+
if friend_code is None:
68+
form.add_error("friends_code", "Invalid code!")
69+
elif friend_code.reached_max_capacity():
70+
form.add_error("friends_code", "This team is already full")
71+
elif friend_code.is_closed():
72+
form.add_error("friends_code", "This team has one application invited and cannot be joined")
73+
else:
6774
return self.create(code=code)
68-
form.add_error("friends_code", "Invalid code!")
6975
context = self.get_context_data()
7076
context.update({"friends_form": form})
7177
return self.render_to_response(context)

0 commit comments

Comments
 (0)