Skip to content

Commit

Permalink
Added is_local field to team
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Feb 11, 2021
1 parent 85732d6 commit 9f11cf0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
6 changes: 3 additions & 3 deletions huntserver/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ class TeamAdminForm(forms.ModelForm):

class Meta:
model = models.Team
fields = ['team_name', 'hunt', 'location', 'join_code', 'playtester', 'playtest_start_date',
'playtest_end_date', 'num_available_hints', 'num_unlock_points', 'unlockables',
'num_unlock_points']
fields = ['team_name', 'hunt', 'location', 'join_code', 'playtester', 'is_local',
'playtest_start_date', 'playtest_end_date', 'num_available_hints',
'num_unlock_points', 'unlockables', 'num_unlock_points', ]

def __init__(self, *args, **kwargs):
super(TeamAdminForm, self).__init__(*args, **kwargs)
Expand Down
11 changes: 10 additions & 1 deletion huntserver/info_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def registration(request):
elif(re.match(".*[A-Za-z0-9].*", request.POST.get("team_name"))):
join_code = ''.join(random.choice("ACDEFGHJKMNPRSTUVWXYZ2345679") for _ in range(5))
team = Team.objects.create(team_name=request.POST.get("team_name"), hunt=curr_hunt,
location=request.POST.get("need_room"),
# location=request.POST.get("need_room"),
location="remote",
is_local=(request.POST.get("team_is_local") is not None),
join_code=join_code)
request.user.person.teams.add(team)
logger.info("User %s created team %s" % (str(request.user), str(team)))
Expand Down Expand Up @@ -76,6 +78,13 @@ def registration(request):
logger.info("User %s changed the location for team %s from %s to %s" %
(str(request.user), str(team.team_name), old_location, team.location))
messages.success(request, "Location successfully updated")
elif(request.POST["form_type"] == "new_affiliation" and team is not None):
old_affiliation = team.is_local
team.is_local = (request.POST.get("team_is_local") is not None)
team.save()
logger.info("User %s changed the affiliation for team %s from %s to %s" %
(str(request.user), str(team.team_name), old_affiliation, team.is_local))
messages.success(request, "Affiliation successfully updated")
elif(request.POST["form_type"] == "new_name" and team is not None and
not team.hunt.in_reg_lockdown):
if(curr_hunt.team_set.filter(team_name__iexact=request.POST.get("team_name")).exists()):
Expand Down
18 changes: 18 additions & 0 deletions huntserver/migrations/0076_team_is_local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.13 on 2021-02-10 21:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('huntserver', '0075_auto_20210208_0939'),
]

operations = [
migrations.AddField(
model_name='team',
name='is_local',
field=models.BooleanField(default=False, help_text='Is this team from CMU (or your organization)'),
),
]
3 changes: 3 additions & 0 deletions huntserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ class Team(models.Model):
max_length=80,
blank=True,
help_text="The physical location that the team is solving at")
is_local = models.BooleanField(
default=False,
help_text="Is this team from CMU (or your organization)")
join_code = models.CharField(
max_length=5,
help_text="The 5 character random alphanumeric password needed for a user to join a team")
Expand Down
32 changes: 30 additions & 2 deletions huntserver/templates/registration.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h3>The code to join this team is <b>{{registered_team.join_code}}</b></h3>
{% endif %}
</div>
<br>
<div>
<!-- <div>
<span> <b> Team Location: </b> {{ registered_team.location }} </span>
<a href='#' class='edit_button'>[Change Location]</a>
<form method="Post" style="display: none;">
Expand All @@ -44,6 +44,28 @@ <h3>The code to join this team is <b>{{registered_team.join_code}}</b></h3>
<input name="team_location" value="{{ registered_team.location }}" type="text">
<input type="submit" value="Change Location">
</form>
</div> -->
<div>
<span>
<b> CMU Team: </b>
{% if registered_team.is_local %}
Yes
{% else %}
No
{% endif %}
</span>
<a href='#' class='edit_button'>[Change]</a>
<form method="Post" style="display: none;">
{% csrf_token %}
<input type="hidden" name="form_type" value="new_affiliation">
<b> CMU Team: </b>
{% if registered_team.is_local %}
<input name="team_is_local" value="team_is_local" type="checkbox" checked>
{% else %}
<input name="team_is_local" value="team_is_local" type="checkbox">
{% endif %}
<input type="submit" value="Change">
</form>
</div>
<br>
<b> Team Members: </b>
Expand Down Expand Up @@ -82,7 +104,7 @@ <h2>Create New Team</h2>
Please enter a new team name:
<input class="form-control" name="team_name" type="text">
<br>
{% if not curr_hunt.in_reg_lockdown %}
<!-- {% if not curr_hunt.in_reg_lockdown %}
Does your team need a room for the hunt?
<select id="room_select" class="form-control" name="need_room">
<option value="need_a_room">Yes</option>
Expand All @@ -99,6 +121,12 @@ <h2>Create New Team</h2>
<option value="off_campus">Our team is off-campus</option>
</select>
{% endif %}
<br> -->
<input name="team_is_local" value="team_is_local" type="checkbox">
Check this box if at least half of the team will be composed of CMU students.
<br>
<small>Don't worry about getting this precisely correct. This only affects how your team shows up on the leaderboard and does not affect eligibility for prizes.<small>
<br>
<br>
<input class="btn btn-primary" type="submit" value="Create and Join Team">
</form>
Expand Down

0 comments on commit 9f11cf0

Please sign in to comment.