Added newsroom

This commit is contained in:
Zakary Timson 2018-02-25 23:48:34 -05:00
parent ec8095c64d
commit e07dd1681b
12 changed files with 136 additions and 0 deletions

View File

@ -51,6 +51,7 @@ INSTALLED_APPS = [
'forum.apps.ForumConfig',
'main.apps.MainConfig',
'newsletters.apps.NewslettersConfig',
'newsroom',
'tinymce',
'widget_tweaks',
'variables'

View File

@ -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'))

0
newsroom/__init__.py Normal file
View File

20
newsroom/admin.py Normal file
View File

@ -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

5
newsroom/apps.py Normal file
View File

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

View File

@ -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)),
],
),
]

View File

22
newsroom/models.py Normal file
View File

@ -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

View File

@ -0,0 +1,37 @@
{% extends 'base.html' %}
{% block body %}
<style>
.newsletter-header {
cursor: pointer;
user-select: none;
}
.newsletter-header:hover {
background-color: rgba(0, 0, 0, 0.1)
}
</style>
<div class="container-fluid bg-dark-primary">
<div class="container py-3">
{% for release in pressRelease %}
<div class="col-12 p-0 mb-3 bg-white newsletter">
<div class="p-3 newsletter-header" style="overflow:hidden" data-toggle="collapse"
data-target="#newsletter-body-{{ release.id }}" aria-expanded="false"
aria-controls="newsletter-body-{{ release.id }}">
<h2 class="float-left">{{ release.title }}</h2>
<span class="text-muted float-right">{{ release.created }}</span>
</div>
<div id="newsletter-body-{{ release.id }}" class="bg-light-blue collapse">
<div class="p-3" style="overflow:hidden;">
{% for attachment in release.attachments.all %}
<a class="inline" href="/media/{{ attachment }}" target="_blank" download>{{ attachment.name }}</a>
<br>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}

3
newsroom/tests.py Normal file
View File

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

9
newsroom/views.py Normal file
View File

@ -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})

View File

@ -60,6 +60,7 @@
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'home' %}">Front Page</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 'members' %}">Members</a>
</div>
</li>