Skip to content

Commit

Permalink
Add committee model
Browse files Browse the repository at this point in the history
  • Loading branch information
adamisntdead committed Aug 19, 2021
1 parent c4b40eb commit 98f9637
Show file tree
Hide file tree
Showing 9 changed files with 612 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ Temporary Items

# End of https://www.toptal.com/developers/gitignore/api/python,django,macos

seed.py
seed_members.py
5 changes: 4 additions & 1 deletion committee/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin

# Register your models here.
from .models import Committee, CommitteeMember

admin.site.register(Committee)
admin.site.register(CommitteeMember)
40 changes: 40 additions & 0 deletions committee/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 3.2.6 on 2021-08-19 08:15

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Committee',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start_year', models.PositiveIntegerField(help_text='The starting year of the committee')),
('current', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='CommitteeMember',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('index', models.PositiveSmallIntegerField(help_text='Ordering to use on the website')),
('position', models.CharField(max_length=100)),
('name', models.CharField(max_length=100)),
('college', models.CharField(blank=True, choices=[('CAI', 'Gonville & Caius'), ('CTH', "St Catharine's"), ('CHR', "Christ's"), ('CHU', 'Churchill'), ('CL', 'Clare'), ('CLH', 'Clare Hall'), ('CC', 'Corpus Christi'), ('DOW', 'Downing'), ('ED', "St Edmund's"), ('EM', 'Emmanuel'), ('F', 'Fitzwilliam'), ('G', 'Girton'), ('HO', 'Homerton'), ('HH', 'Hughes Hall'), ('JE', 'Jesus'), ('JN', "St John's"), ('K', "King's"), ('LC', 'Lucy Cavendish'), ('M', 'Magdalene'), ('MUR', 'Murray Edwards'), ('N', 'Newnham'), ('PEM', 'Pembroke'), ('PET', 'Peterhouse'), ('Q', "Queens'"), ('R', 'Robinson'), ('SE', 'Selwyn'), ('SID', 'Sidney Sussex'), ('TH', 'Trinity Hall'), ('T', 'Trinity'), ('W', 'Wolfson'), ('DAR', 'Darwin'), ('NA', 'N/A')], max_length=6)),
('email', models.CharField(max_length=100, null=True)),
('is_publications', models.BooleanField(default=False)),
('photo', models.CharField(max_length=100, null=True)),
('committee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='committee.committee')),
],
options={
'ordering': ['index'],
},
),
]
26 changes: 25 additions & 1 deletion committee/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
from django.db import models
from members.models import COLLEGES

# Create your models here.
class Committee(models.Model):
"""Represents a whole committee for a given year, e.g. 2021-2022."""
start_year = models.PositiveIntegerField(help_text="The starting year of the committee")
current = models.BooleanField(default=False)

def __str__(self):
return f'Committee ({self.start_year} - {self.start_year + 1})'

class CommitteeMember(models.Model):
"""Represents an individual committee member."""
index = models.PositiveSmallIntegerField(help_text="Ordering to use on the website")
position = models.CharField(max_length=100)
name = models.CharField(max_length=100)
college = models.CharField(max_length=6, choices=COLLEGES, blank=True)
email = models.CharField(max_length=100, null=True)
is_publications = models.BooleanField(default=False)
photo = models.CharField(max_length=100, null=True)
committee = models.ForeignKey(Committee, on_delete=models.CASCADE)

class Meta:
ordering = ['index']

def __str__(self):
return f'{self.position} ({self.committee.start_year}): {self.name}, {self.college}'
4 changes: 2 additions & 2 deletions committee/templates/committee/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>Current committee ({{ year }} - {{ year | add:1 }})</h1>
<h3 class="committee-header">
{{ member.position }}: {{ member.name }}
<br>
<span class="committee-college">{{ member.college }}</span>
<span class="committee-college">{{ member.get_college_display }}</span>
</h3>
{% if member.email %}
<p class="committee-email">
Expand All @@ -40,7 +40,7 @@ <h2>Publications Subcommittee</h2>
<h3 class="committee-header">
{{ member.position }}: {{ member.name }}
<br>
<span class="committee-college">{{ member.college }}</span>
<span class="committee-college">{{ member.get_college_display }}</span>
</h3>
{% if member.email %}
<p class="committee-email">
Expand Down
100 changes: 16 additions & 84 deletions committee/views.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,24 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader

# TODO: Make a committee model
from .models import CommitteeMember, Committee

committee = {
"year": "2021",
"committee": [
{
"position": "President",
"name": "Parth Shimpi",
"college": "Gonville and Caius",
"email": "president",
"photo": "parthnew"
},
{
"position": "Vice President",
"name": "Kathryn Bowers",
"college": "Magdalene",
"email": "vice-president",
"photo": "kathryn"
},
{
"position": "Treasurer",
"name": "Fong Tsz Lo",
"college": "Magdalene",
"email": "junior-treasurer"
},
{
"position": "Events Manager",
"name": "Nikita Kamath",
"college": "St Catharine's",
"email": "events-manager",
"photo": "nikita"
},
{
"position": "Events Manager",
"name": "Vishal Gupta",
"college": "St John's",
"email": "events-manager",
"photo": "vishal"
},
{
"position": "External Secretary",
"name": "Yan Yau Cheng",
"college": "Magdalene",
"email": "external-secretary",
"photo": "yan-yau"
},
{
"position": "Internal Secretary",
"name": "Ashutosh Tripathi",
"college": "Emmanuel",
"email": "internal-secretary"
},
{
"position": "Publicity Officer",
"name": "Gesa Dünnweber",
"college": "Gonville and Caius",
"email": "publicity",
"photo": "gesa"
},
{
"position": "Sponsorship Officer",
"name": "Etaash Katiyar",
"college":"Corpus Christi",
"email":"corporate-officer"
},
{
"position": "Webmaster",
"name": "Adam Kelly",
"college": "Gonville and Caius",
"email": "webmaster"
}
],
"publications": [
{
"position": "Eureka Editor",
"name": "Valentin Hübner",
"college": "Pembroke",
"email": "eureka-editor"
}
]
}
def index(request):
page_data = { "committee": [], "publications": [] }

committee = Committee.objects.filter(current=True)

if len(committee) == 0:
return render(request, 'committee/index.html', {})

page_data["year"] = committee[0].start_year

def index(request):
return render(request, 'committee/index.html', committee)
committee_members = CommitteeMember.objects.filter(committee_id=committee[0].id)

for member in committee_members:
type = "committee" if not member.is_publications else "publications"
page_data[type].append(member)

return render(request, 'committee/index.html', page_data)

def past(request):
return render(request, 'committee/past.html')
4 changes: 2 additions & 2 deletions members/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.6 on 2021-08-17 07:38
# Generated by Django 3.2.6 on 2021-08-19 08:15

from django.db import migrations, models

Expand All @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
('lastname', models.CharField(max_length=25)),
('crsid', models.CharField(max_length=8)),
('alternative_email', models.CharField(blank=True, max_length=35, null=True)),
('college', models.CharField(blank=True, choices=[('CAI', 'Gonville & Caius'), ('CTH', "St Catherine's"), ('CHR', "Christ's"), ('CHU', 'Churchill'), ('CL', 'Clare'), ('CLH', 'Clare Hall'), ('CC', 'Corpus Christi'), ('DOW', 'Downing'), ('ED', "St Edmund's"), ('EM', 'Emmanuel'), ('F', 'Fitzwilliam'), ('G', 'Girton'), ('HO', 'Homerton'), ('HH', 'Hughes Hall'), ('JE', 'Jesus'), ('JN', "St John's"), ('K', "King's"), ('LC', 'Lucy Cavendish'), ('M', 'Magdalene'), ('MUR', 'Murray Edwards'), ('N', 'Newnham'), ('PEM', 'Pembroke'), ('PET', 'Peterhouse'), ('Q', "Queens'"), ('R', 'Robinson'), ('SE', 'Selwyn'), ('SID', 'Sidney Sussex'), ('TH', 'Trinity Hall'), ('T', 'Trinity'), ('W', 'Wolfson'), ('DAR', 'Darwin'), ('NA', 'N/A')], max_length=6)),
('college', models.CharField(blank=True, choices=[('CAI', 'Gonville & Caius'), ('CTH', "St Catharine's"), ('CHR', "Christ's"), ('CHU', 'Churchill'), ('CL', 'Clare'), ('CLH', 'Clare Hall'), ('CC', 'Corpus Christi'), ('DOW', 'Downing'), ('ED', "St Edmund's"), ('EM', 'Emmanuel'), ('F', 'Fitzwilliam'), ('G', 'Girton'), ('HO', 'Homerton'), ('HH', 'Hughes Hall'), ('JE', 'Jesus'), ('JN', "St John's"), ('K', "King's"), ('LC', 'Lucy Cavendish'), ('M', 'Magdalene'), ('MUR', 'Murray Edwards'), ('N', 'Newnham'), ('PEM', 'Pembroke'), ('PET', 'Peterhouse'), ('Q', "Queens'"), ('R', 'Robinson'), ('SE', 'Selwyn'), ('SID', 'Sidney Sussex'), ('TH', 'Trinity Hall'), ('T', 'Trinity'), ('W', 'Wolfson'), ('DAR', 'Darwin'), ('NA', 'N/A')], max_length=6)),
('life_member', models.BooleanField()),
('membership_start', models.DateField()),
('membership_end', models.DateField(blank=True, null=True)),
Expand Down
3 changes: 2 additions & 1 deletion members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# see https://www.admin.cam.ac.uk/reporter/2016-17/special/04/section1.shtml
COLLEGES = (
("CAI", "Gonville & Caius"),
("CTH", "St Catherine's"),
("CTH", "St Catharine's"),
("CHR", "Christ's"),
("CHU", "Churchill"),
("CL", "Clare"),
Expand Down Expand Up @@ -38,6 +38,7 @@
)

class Member(models.Model):
"""Represents a member of the archimedeans."""
firstname = models.CharField(max_length=25)
lastname = models.CharField(max_length=25)
crsid = models.CharField(max_length=8)
Expand Down
Loading

0 comments on commit 98f9637

Please sign in to comment.