Implement view/edit membership details
This commit is contained in:
parent
8e40d45934
commit
791027bae5
@ -23,6 +23,79 @@
|
|||||||
<h1>No membership records</h1>
|
<h1>No membership records</h1>
|
||||||
<p>This email address is not associated with a current membership.</p>
|
<p>This email address is not associated with a current membership.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Membership details</p>
|
<h1>Membership details</h1>
|
||||||
|
|
||||||
|
<form class="ui form" method="POST" action="{{ url('membership') }}">
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Member number</label>
|
||||||
|
<div class="nine wide column">{{ member.id }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Student ID</label>
|
||||||
|
<input class="nine wide column" type="text" name="student_id" value="{{ member.student_id }}">
|
||||||
|
</div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Student email</label>
|
||||||
|
<div class="nine wide column">{{ member.email }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">First name</label>
|
||||||
|
<input class="nine wide column" type="text" name="first_name" value="{{ member.first_name }}">
|
||||||
|
</div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Last name</label>
|
||||||
|
<input class="nine wide column" type="text" name="last_name" value="{{ member.last_name }}">
|
||||||
|
</div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Phone number</label>
|
||||||
|
<input class="nine wide column" type="text" name="phone" value="{{ member.phone }}">
|
||||||
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Year level</label>
|
||||||
|
<select id="drop_year" class="ui dropdown eleven wide column" name="year">
|
||||||
|
<option value="">Year level</option>
|
||||||
|
{% for year in years %}
|
||||||
|
<option value="{{ year[0] }}">{{ year[1] }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">MSA membership</label>
|
||||||
|
<select id="drop_msa" class="ui dropdown eleven wide column" name="is_msa">
|
||||||
|
<option value="">MSA membership</option>
|
||||||
|
<option value="0">No, I am not an MSA member</option>
|
||||||
|
<option value="1">Yes, I am an MSA member</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<div class="ui required inline grid field">
|
||||||
|
<label class="three wide column">Membership expiry</label>
|
||||||
|
<div class="nine wide column">{{ member.expires.strftime('%d %B %Y') }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
{% if errors %}
|
||||||
|
<div class="ui visible error message"><ul>
|
||||||
|
{% for error in errors %}
|
||||||
|
<li>{{ error }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul></div>
|
||||||
|
{% endif %}
|
||||||
|
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
|
||||||
|
<input class="ui primary button" type="submit" name='submit' value="Save">
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
{{ super() }}
|
||||||
|
{% if member %}
|
||||||
|
<script>
|
||||||
|
$('.ui.dropdown').dropdown();
|
||||||
|
$('#drop_year').dropdown('set selected', '{{ member.year }}');
|
||||||
|
$('#drop_msa').dropdown('set selected', '{{ '1' if member.is_msa else '0' }}');
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
class Member(models.Model):
|
class Member(models.Model):
|
||||||
email = models.CharField(max_length=100)
|
email = models.CharField(max_length=100)
|
||||||
|
|
||||||
@ -25,8 +27,7 @@ class Member(models.Model):
|
|||||||
student_id = models.CharField(max_length=8)
|
student_id = models.CharField(max_length=8)
|
||||||
is_msa = models.BooleanField()
|
is_msa = models.BooleanField()
|
||||||
|
|
||||||
year = models.IntegerField(
|
YEARS = (
|
||||||
choices = (
|
|
||||||
(0, 'Year A'),
|
(0, 'Year A'),
|
||||||
(1, 'Year 1'),
|
(1, 'Year 1'),
|
||||||
(2, 'Year 2'),
|
(2, 'Year 2'),
|
||||||
@ -37,8 +38,33 @@ class Member(models.Model):
|
|||||||
(98, 'PhD'),
|
(98, 'PhD'),
|
||||||
(99, 'Intermission'),
|
(99, 'Intermission'),
|
||||||
)
|
)
|
||||||
)
|
year = models.IntegerField(choices=YEARS)
|
||||||
|
|
||||||
phone = models.CharField(max_length=20)
|
phone = models.CharField(max_length=20)
|
||||||
|
|
||||||
expires = models.DateField()
|
expires = models.DateField()
|
||||||
|
|
||||||
|
def validation_problems(self):
|
||||||
|
result = []
|
||||||
|
|
||||||
|
if not self.email.strip():
|
||||||
|
result.append('Email is required')
|
||||||
|
if not self.first_name.strip():
|
||||||
|
result.append('First name is required')
|
||||||
|
if not self.last_name.strip():
|
||||||
|
result.append('Last name is required')
|
||||||
|
if not self.student_id.strip():
|
||||||
|
result.append('Student ID is required')
|
||||||
|
if not any(x[0] == self.year for x in Member.YEARS):
|
||||||
|
result.append('A valid year is required')
|
||||||
|
if not self.phone.strip():
|
||||||
|
result.append('Phone number is required')
|
||||||
|
|
||||||
|
if not self.email.strip().endswith('@student.monash.edu'):
|
||||||
|
result.append('Email must be a Monash student email address')
|
||||||
|
if not re.match(r'^[0-9]{8}$', self.student_id.strip()):
|
||||||
|
result.append('Student ID must be an 8 digit number')
|
||||||
|
if not re.match(r'^[0-9+ ]+$', self.phone.strip()):
|
||||||
|
result.append('Phone number must contain only numbers and +')
|
||||||
|
|
||||||
|
return result
|
||||||
|
@ -16,7 +16,11 @@
|
|||||||
|
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.conf import settings
|
||||||
|
from django.db import transaction
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render, redirect
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
@ -26,5 +30,28 @@ def index(request):
|
|||||||
member = models.Member.objects.get(email=request.user.email)
|
member = models.Member.objects.get(email=request.user.email)
|
||||||
except models.Member.DoesNotExist:
|
except models.Member.DoesNotExist:
|
||||||
member = None
|
member = None
|
||||||
|
return render(request, 'ssmembership/index.html', {'member': member, 'years': models.Member.YEARS})
|
||||||
|
|
||||||
|
if request.method != 'POST':
|
||||||
|
return render(request, 'ssmembership/index.html', {'member': member, 'years': models.Member.YEARS})
|
||||||
|
|
||||||
|
# Update membership
|
||||||
|
member.student_id = request.POST['student_id']
|
||||||
|
member.first_name = request.POST['first_name']
|
||||||
|
member.last_name = request.POST['last_name']
|
||||||
|
member.phone = request.POST['phone']
|
||||||
|
member.year = int(request.POST['year'])
|
||||||
|
member.is_msa = True if request.POST['is_msa'] == '1' else '0'
|
||||||
|
|
||||||
|
errors = member.validation_problems()
|
||||||
|
if not member or len(errors) > 0:
|
||||||
|
return render(request, 'ssmembership/index.html', {
|
||||||
|
'member': member,
|
||||||
|
'years': models.Member.YEARS,
|
||||||
|
'errors': errors
|
||||||
|
})
|
||||||
|
|
||||||
|
member.save()
|
||||||
|
return render(request, 'ssmembership/index.html', {'member': member, 'years': models.Member.YEARS})
|
||||||
|
|
||||||
return render(request, 'ssmembership/index.html', {'member': member})
|
return render(request, 'ssmembership/index.html', {'member': member})
|
||||||
|
Loading…
Reference in New Issue
Block a user