Added events

This commit is contained in:
Zakary Timson 2018-02-26 22:02:50 -05:00
parent 9a48e3f724
commit 2c9bc11290
23 changed files with 313 additions and 1 deletions

View File

@ -41,6 +41,7 @@ INSTALLED_APPS = [
'bootstrap_admin', 'bootstrap_admin',
'case_law', 'case_law',
'charter_members.apps.CharterMembersConfig', 'charter_members.apps.CharterMembersConfig',
'events',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',

View File

@ -11,6 +11,7 @@ import main.views
import case_law.views import case_law.views
import charter_members.views import charter_members.views
import expert_witnesses.views import expert_witnesses.views
import events.views
import forum.views import forum.views
import newsletters.views import newsletters.views
import newsroom.views import newsroom.views
@ -39,6 +40,8 @@ urlpatterns = [
url(r'^contact/', main.views.contact, name='contact'), url(r'^contact/', main.views.contact, name='contact'),
url(r'^experts/(?P<id>\d+)', expert_witnesses.views.viewer, name='expert'), url(r'^experts/(?P<id>\d+)', expert_witnesses.views.viewer, name='expert'),
url(r'^experts/', expert_witnesses.views.browser, name='experts'), url(r'^experts/', expert_witnesses.views.browser, name='experts'),
url(r'^events/register', events.views.register, name='register'),
url(r'^events/', events.views.view, name='events'),
url(r'^forum/post/(?P<post>\d*)', forum.views.viewPost, name='post'), url(r'^forum/post/(?P<post>\d*)', forum.views.viewPost, name='post'),
url(r'^forum/(?P<thread>\d*)?', forum.views.view, name='forum'), url(r'^forum/(?P<thread>\d*)?', forum.views.view, name='forum'),
url(r'^login/', main.views.login, name='login'), url(r'^login/', main.views.login, name='login'),

0
events/__init__.py Normal file
View File

9
events/admin.py Normal file
View File

@ -0,0 +1,9 @@
from django.contrib import admin
from .models import Event
@admin.register(Event)
class EventAdmit(admin.ModelAdmin):
fields = ['title', 'date', 'location', 'max_attendees', 'cost', 'description']
list_display = ['title', 'date', 'location', 'max_attendees', 'cost']

5
events/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class EventsConfig(AppConfig):
name = 'events'

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-27 00:36
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import tinymce.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Attendees',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('paid', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('date', models.DateField()),
('location', models.CharField(max_length=255)),
('description', tinymce.models.HTMLField()),
('max_attendees', models.IntegerField(blank=True, null=True)),
('cost', models.DecimalField(decimal_places=2, max_digits=6)),
],
),
migrations.AddField(
model_name='attendees',
name='event',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event'),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-27 00:38
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='event',
name='date',
field=models.DateTimeField(),
),
]

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-27 01:00
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0002_auto_20180226_1938'),
]
operations = [
migrations.RemoveField(
model_name='attendees',
name='event',
),
migrations.AddField(
model_name='event',
name='attendees',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='events.Attendees'),
),
]

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-27 01:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0003_auto_20180226_2000'),
]
operations = [
migrations.RemoveField(
model_name='event',
name='attendees',
),
migrations.AddField(
model_name='event',
name='attendees',
field=models.ManyToManyField(to='events.Attendees'),
),
]

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-27 01:39
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0004_auto_20180226_2001'),
]
operations = [
migrations.AlterField(
model_name='event',
name='cost',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=6),
),
migrations.AlterField(
model_name='event',
name='location',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View File

24
events/models.py Normal file
View File

@ -0,0 +1,24 @@
from django.db import models
from tinymce import HTMLField
class Attendees(models.Model):
name = models.CharField(max_length=255)
paid = models.BooleanField(default=False)
def __str__(self):
return self.name
class Event(models.Model):
title = models.CharField(max_length=255)
date = models.DateTimeField()
location = models.CharField(max_length=255, null=True, blank=True)
description = HTMLField()
max_attendees = models.IntegerField(blank=True, null=True)
cost = models.DecimalField(max_digits=6, decimal_places=2, default=0.00)
attendees = models.ManyToManyField(Attendees)
def __str__(self):
return self.title

View File

@ -0,0 +1,82 @@
{% extends 'base.html' %}
{% load static %}
{% block head %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.2/fullcalendar.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.8.2/fullcalendar.css" />
<script>
function register(id) {
$.ajax({
url: '{% url 'register' %}',
method: 'post',
data: {id: id}
}).done(function() {window.location += '?id=' + id})
}
$(function() {
$('[id^=details-]').hide();
if(window.location.search.indexOf('id=') != -1) {
var id = new RegExp(/id=(\d+)/).exec(window.location);
$('#details-' + id[1]).show();
}
$('#calendar').fullCalendar({
events: [
{% for event in events %}
{id: {{ event.id }}, title: '{{event.title}}', start: '{{event.date|date:'c'}}', backgroundColor: '#4ec8ff'},
{% endfor %}
],
eventClick: function(calEvent) {
$('[id^=details-]').hide();
$('#details-' + calEvent.id).show();
}
});
});
</script>
{% endblock %}
{% block body %}
<div class="container-fluid bg-dark-primary">
<div class="row p-3">
<div class="col-8 bg-white p-3 rounded">
<div id="calendar"></div>
</div>
<div class="col-4 pr-0">
<div class="ml-3 rounded bg-white h-100 p-3" style="position:relative">
{% for event in events %}
<div id="details-{{ event.id }}" style="display:none">
<h3>{% if event.attendees.all|length >= event.max_attendees %}<strong>(FULL)</strong>{% endif %} {{ event.title }}</h3>
<h6 class="text-muted">{{ event.date }}</h6>
<br>
<h6><strong>Description:</strong></h6>
<p>{{ event.description|safe }}</p>
{% if event.location %}
<h6><strong>Where:</strong> {{ event.location }}</h6>
{% endif %}
{% if event.cost %}
<h6><strong>Cost: </strong> ${{ event.cost }}</h6>
{% endif %}
{% if event.attendees.all %}
<h6><strong>Attendees ({{ event.attendees.all|length }}{% if event.max_attendees %}/{{ event.max_attendees }}{% endif %}):</strong></h6>
{% for attendee in event.attendees.all %}
{{attendee.name}},
{% endfor %}
{% endif %}
{% if request.user.is_authenticated %}
{% if not event.max_attendees or event.attendees.all|length < event.max_attendees %}
<div class="fixed-bottom p-3" style="position:absolute">
<button class="btn btn-primary float-right" onclick="register({{ event.id }})">Register</button>
</div>
{% endif %}
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock %}

3
events/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

18
events/views.py Normal file
View File

@ -0,0 +1,18 @@
from django.http import JsonResponse
from django.shortcuts import render
from .models import Attendees, Event
def view(request):
events = Event.objects.all()
return render(request, 'events.html', {'events': events})
def register(request):
event = Event.objects.get(id=request.POST.get('id'))
attendee = Attendees(name='{} {}'.format(request.user.first_name, request.user.last_name), paid=False)
attendee.save()
event.attendees.add(attendee)
event.save()
return JsonResponse({'success': True})

BIN
media/Newsletter/ubuntu.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (venv)" project-jdk-type="Python SDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="FacetManager">
<facet type="django" name="Django">
<configuration>
<option name="rootFolder" value="" />
<option name="settingsModule" value="settings.py" />
<option name="manageScript" value="manage.py" />
<option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Django" />
</component>
</module>

0
oacpl.sqlite3 Normal file
View File

View File

@ -59,9 +59,10 @@
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">HOME</a> data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">HOME</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown"> <div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'home' %}">Front Page</a> <a class="dropdown-item" href="{% url 'home' %}">Front Page</a>
<a class="dropdown-item" href="{% url 'events' %}">Events</a>
<a class="dropdown-item" href="{% url 'members' %}">Members</a>
<a class="dropdown-item" href="{% url 'newsletters' %}">Newsletters</a> <a class="dropdown-item" href="{% url 'newsletters' %}">Newsletters</a>
<a class="dropdown-item" href="{% url 'newsroom' %}">Newsroom</a> <a class="dropdown-item" href="{% url 'newsroom' %}">Newsroom</a>
<a class="dropdown-item" href="{% url 'members' %}">Members</a>
</div> </div>
</li> </li>
<li class="nav-item text-dark-primary"> <li class="nav-item text-dark-primary">