From e07dd1681bab3ab383c73d74076a75add04f9ecb Mon Sep 17 00:00:00 2001 From: Zak Timson Date: Sun, 25 Feb 2018 23:48:34 -0500 Subject: [PATCH] Added newsroom --- OACPL/settings.base.py | 1 + OACPL/urls.py | 2 ++ newsroom/__init__.py | 0 newsroom/admin.py | 20 ++++++++++++++++ newsroom/apps.py | 5 ++++ newsroom/migrations/0001_initial.py | 36 ++++++++++++++++++++++++++++ newsroom/migrations/__init__.py | 0 newsroom/models.py | 22 +++++++++++++++++ newsroom/templates/newsroom.html | 37 +++++++++++++++++++++++++++++ newsroom/tests.py | 3 +++ newsroom/views.py | 9 +++++++ templates/base.html | 1 + 12 files changed, 136 insertions(+) create mode 100644 newsroom/__init__.py create mode 100644 newsroom/admin.py create mode 100644 newsroom/apps.py create mode 100644 newsroom/migrations/0001_initial.py create mode 100644 newsroom/migrations/__init__.py create mode 100644 newsroom/models.py create mode 100644 newsroom/templates/newsroom.html create mode 100644 newsroom/tests.py create mode 100644 newsroom/views.py diff --git a/OACPL/settings.base.py b/OACPL/settings.base.py index a560947..d6a351d 100644 --- a/OACPL/settings.base.py +++ b/OACPL/settings.base.py @@ -51,6 +51,7 @@ INSTALLED_APPS = [ 'forum.apps.ForumConfig', 'main.apps.MainConfig', 'newsletters.apps.NewslettersConfig', + 'newsroom', 'tinymce', 'widget_tweaks', 'variables' diff --git a/OACPL/urls.py b/OACPL/urls.py index 4c5b5ec..c46e368 100644 --- a/OACPL/urls.py +++ b/OACPL/urls.py @@ -13,6 +13,7 @@ import charter_members.views import expert_witnesses.views import forum.views import newsletters.views +import newsroom.views @login_required @@ -48,6 +49,7 @@ urlpatterns = [ url(r'^members', charter_members.views.all, name='members'), url(r'^newsletter/unsubscribe', newsletters.views.unsubscribe, name='unsubscribe'), url(r'^newsletter/', newsletters.views.newsletters, name='newsletters'), + url(r'^newsroom/', newsroom.views.newsroom, name='newsroom'), url(r'^resetToken', main.views.reset_token, name='reset token'), url(r'^reset/', main.views.reset, name='reset'), url(r'^tinymce/', include('tinymce.urls')) diff --git a/newsroom/__init__.py b/newsroom/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/newsroom/admin.py b/newsroom/admin.py new file mode 100644 index 0000000..611d729 --- /dev/null +++ b/newsroom/admin.py @@ -0,0 +1,20 @@ +from django.contrib import admin + +from .models import Attachment, PressRelease + + +admin.site.register(Attachment) + + +@admin.register(PressRelease) +class PressRelease(admin.ModelAdmin): + list_display = ['title', 'created', 'creator'] + fields = ['title', 'attachments'] + filter_horizontal = ['attachments'] + + def save_model(self, request, instance, form, change): + user = request.user + instance = form.save(commit=False) + instance.creator = user + instance.save() + return instance diff --git a/newsroom/apps.py b/newsroom/apps.py new file mode 100644 index 0000000..0024498 --- /dev/null +++ b/newsroom/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NewsroomConfig(AppConfig): + name = 'newsroom' diff --git a/newsroom/migrations/0001_initial.py b/newsroom/migrations/0001_initial.py new file mode 100644 index 0000000..0fb1def --- /dev/null +++ b/newsroom/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2018-02-26 04:09 +from __future__ import unicode_literals + +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='Attachment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file', models.FileField(upload_to='')), + ], + ), + migrations.CreateModel( + name='PressRelease', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255)), + ('created', models.DateTimeField(auto_now_add=True)), + ('attachments', models.ManyToManyField(to='newsroom.Attachment')), + ('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/newsroom/migrations/__init__.py b/newsroom/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/newsroom/models.py b/newsroom/models.py new file mode 100644 index 0000000..fa3c307 --- /dev/null +++ b/newsroom/models.py @@ -0,0 +1,22 @@ +from django.db import models +from django.contrib.auth.admin import User + + +class Attachment(models.Model): + file = models.FileField(upload_to='PressRelease') + + def name(self): + return self.file.name.replace('PressRelease/', '') + + def __str__(self): + return self.file.name + + +class PressRelease(models.Model): + title = models.CharField(max_length=255) + created = models.DateTimeField(auto_now_add=True) + creator = models.ForeignKey(User) + attachments = models.ManyToManyField(Attachment) + + def __str__(self): + return self.title diff --git a/newsroom/templates/newsroom.html b/newsroom/templates/newsroom.html new file mode 100644 index 0000000..7af3120 --- /dev/null +++ b/newsroom/templates/newsroom.html @@ -0,0 +1,37 @@ +{% extends 'base.html' %} + +{% block body %} + + +
+
+ {% for release in pressRelease %} + + {% endfor %} +
+
+{% endblock %} \ No newline at end of file diff --git a/newsroom/tests.py b/newsroom/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/newsroom/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/newsroom/views.py b/newsroom/views.py new file mode 100644 index 0000000..5ea4412 --- /dev/null +++ b/newsroom/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render + +from .models import PressRelease + + +def newsroom(request): + press_releases = PressRelease.objects.all() + + return render(request, 'newsroom.html', {'pressRelease': press_releases}) diff --git a/templates/base.html b/templates/base.html index 2a58016..ebed8aa 100644 --- a/templates/base.html +++ b/templates/base.html @@ -60,6 +60,7 @@