Skip to content

Commit

Permalink
Review sessions app (compserv#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
haolinzhu authored Sep 21, 2020
1 parent 46fecc9 commit 50f4bbf
Show file tree
Hide file tree
Showing 20 changed files with 606 additions and 3 deletions.
30 changes: 30 additions & 0 deletions hknweb/migrations/0011_reviewsession.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.8 on 2020-04-13 22:50

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('hknweb', '0010_announcement'),
]

operations = [
migrations.CreateModel(
name='ReviewSession',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('slug', models.CharField(max_length=255)),
('start_time', models.DateTimeField()),
('end_time', models.DateTimeField()),
('location', models.CharField(max_length=255)),
('description', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('created_by', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
16 changes: 16 additions & 0 deletions hknweb/migrations/0012_delete_reviewsession.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 2.2.8 on 2020-04-13 23:29

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('hknweb', '0011_reviewsession'),
]

operations = [
migrations.DeleteModel(
name='ReviewSession',
),
]
14 changes: 14 additions & 0 deletions hknweb/reviewsessions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib import admin
from .models import ReviewSession

@admin.register(ReviewSession)
class ReviewSessionAdmin(admin.ModelAdmin):

fields = ['name', 'slug', 'start_time', 'end_time', 'location', 'description', 'created_by', 'created_at']
# NOTE: created_by should be read only, but I don't know how to set it to default to current user
readonly_fields = ['created_at']
list_display = ('name', 'start_time', 'location', 'created_by', 'created_at')
list_filter = ['start_time', 'created_at', 'location', 'created_by']
search_fields = ['name', 'created_by__username', 'created_by__first_name', 'created_by__last_name']
ordering = ['-created_at']
autocomplete_fields = ['created_by']
4 changes: 4 additions & 0 deletions hknweb/reviewsessions/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.apps import AppConfig

class ReviewSessionsConfig(AppConfig):
name = 'reviewsessions'
37 changes: 37 additions & 0 deletions hknweb/reviewsessions/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django import forms
from .models import ReviewSession


class ReviewSessionForm(forms.ModelForm):
start_time = forms.DateTimeField(input_formats=('%m/%d/%Y %I:%M %p',))
end_time = forms.DateTimeField(input_formats=('%m/%d/%Y %I:%M %p',))

class Meta:
model = ReviewSession
fields = ('name', 'slug', 'location', 'description', 'start_time', 'end_time')

help_texts = {
'start_time': 'mm/dd/yyyy hh:mm, 24-hour time',
'end_time': 'mm/dd/yyyy hh:mm, 24-hour time',
'slug': 'e.g. <semester>-<name>',
}

widgets = {
'slug': forms.TextInput(attrs={'placeholder': 'e.g. <semester>-<name>'}),
}

labels = {
'slug': 'URL-friendly name',
}

class ReviewSessionUpdateForm(forms.ModelForm):
start_time = forms.DateTimeField(input_formats=('%m/%d/%Y %I:%M %p',))
end_time = forms.DateTimeField(input_formats=('%m/%d/%Y %I:%M %p',))

class Meta:
model = ReviewSession
fields = ['name', 'slug', 'start_time', 'end_time', 'location', 'description']

labels = {
'slug': 'URL-friendly name',
}
31 changes: 31 additions & 0 deletions hknweb/reviewsessions/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 2.2.12 on 2020-04-15 04:57

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


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='ReviewSession',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('slug', models.CharField(max_length=255)),
('start_time', models.DateTimeField()),
('end_time', models.DateTimeField()),
('location', models.CharField(max_length=255)),
('description', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('created_by', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
22 changes: 22 additions & 0 deletions hknweb/reviewsessions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import models
from django.contrib.auth.models import User

class ReviewSession(models.Model):
name = models.CharField(max_length=255)
slug = models.CharField(max_length=255)
start_time = models.DateTimeField()
end_time = models.DateTimeField()
location = models.CharField(max_length=255)
description = models.TextField()

created_by = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
created_at = models.DateTimeField(auto_now_add=True)

def get_absolute_url(self):
return '/reviewsessions/{}'.format(self.id)

def __repr__(self):
return "Event(name={}, location={})".format(self.name, self.location)

def __str__(self):
return self.name
58 changes: 58 additions & 0 deletions hknweb/reviewsessions/static/reviewsessions/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* #event-detail-title {
margin-bottom: 0.2em;
padding-left: 1em;
} */

#left-details {
padding-left: 2em;
width: 45%;
float: left;
}

#right-details {
text-align: center;
padding-right: 2em;
width: 45%;
float: right;
}

.table-icon {
width: 1.5em;
vertical-align: middle;
}

.message {
color: rgba(166, 60, 68, 1);
}

#add-review-session-title {
margin: 0;
margin-bottom: 1em;
font-weight: normal;
text-align: center;
}

#form {
position: relative;
}

.row {
margin-bottom: 1em;
}

@media screen and (min-width: 700px) {
.left-side {
display: inline-block;
width: 50%;
text-align: right;
}
#submit {
width: 100%;
text-align: center;
}
}

#button {
width: 100%;
text-align: center;
}
97 changes: 97 additions & 0 deletions hknweb/reviewsessions/templates/reviewsessions/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{% extends "base.html" %}
{% load static %}

{% block title %}Review Sessions{% endblock %}

{% block header %}
<!-- Scripts which make the calendar work:-->
<link rel="stylesheet" href="{% static "reviewsessions/style.css" %}">
<link rel="stylesheet" href="https://unpkg.com/@fullcalendar/[email protected]/main.css" />
<link rel="stylesheet" href="https://unpkg.com/@fullcalendar/[email protected]/main.css" />
<link rel="stylesheet" href="https://unpkg.com/@fullcalendar/[email protected]/main.css" />
<link rel="stylesheet" href="{% static "css/tachyons.css" %}" />

<script src="https://unpkg.com/@fullcalendar/[email protected]/main.js"></script>
<script src="https://unpkg.com/@fullcalendar/[email protected]/main.js"></script>
<script src="https://unpkg.com/@fullcalendar/[email protected]/main.js"></script>

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
// General options
plugins: [ 'dayGrid', 'timeGrid' ],
defaultView: 'dayGridMonth',
defaultDate: "{% now 'c' %}",
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
navLinks: true,
eventLimit: true,
aspectRatio: 1.75,
views: {
dayGrid: {
fixedWeekCount: false,
},
timeGrid: {
minTime: "8:00:00",
maxTime: "24:00:00",
nowIndicator: true,
}
},
// Review sessions
events: [{% for reviewsession in reviewsessions %}
{
title: "{{ reviewsession.name|safe }}",
start: '{{ reviewsession.start_time|date:"c" }}',
end: '{{ reviewsession.end_time|date:"c" }}',
url: '{{ reviewsession.id }}',
},
{% endfor %}]
});

calendar.render();
});
</script>
<style>
.fc-center h2 {
font-family: 'Source Sans Pro', sans-serif;
font-size: 30px;
font-weight: 400;
}
</style>

{% endblock %}

{% block heading %}
Upcoming Review Sessions
{% endblock %}

{% block content %}
<div class="center measure-verywide">
{% if messages %}
{% for message in messages %}
<h3 {% if messages.tags %} class="{{ message.tags }}" {% endif %} style="color: #0000A0;">{{ message }}</h3>
{% endfor %}
{% endif %}

<!-- Event type legend -->
<!-- <ul class="list w-100 flex flex-wrap justify-end">
{% for event_type in event_types %}
<li class="dib pa2 ml1 br2 white" style="background-color: {{event_type.color}};">{{event_type.type}}</li>
{% endfor %}
</ul> -->

<!-- FullCalendar -->
<section class="pb3" id='calendar'></section>

{% if perms.reviewsessions.add_reviewsession %}
<form action="new" method="GET" id="button">
<button type='submit'>Add a review session</button>
</form>
{% endif %}
<br>
</div>
{% endblock %}
Loading

0 comments on commit 50f4bbf

Please sign in to comment.