Commit 120b7ce8 authored by Nicolas Reichert's avatar Nicolas Reichert

updated announcements

parent fa560eba
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
\ No newline at end of file
from django import forms
from django.forms import Textarea
from .models import Announcement
class AnnouncementForm(forms.ModelForm):
class Meta:
model = Announcement
fields = ['announcement_title', 'announcement_body', 'author', 'image']
widgets = {
'post_body': Textarea(attrs={'placeholder': 'Type announcement body here', 'cols': 12, 'rows': 12}),
}
labels = {
'announcement_title': 'Title',
'announcement_body': 'Body',
}
from msilib.schema import Class
from django.db import models
from django.urls import reverse
# Create your models here.
class Announcement(models.Model):
......@@ -15,6 +16,10 @@ class Announcement(models.Model):
def __str__(self):
return '{}'.format(self.announcement_title)
def get_absolute_url(self):
return reverse('announcements:announcement-detail', kwargs={'pk': self.pk})
@property
def announcement_detail(self):
announcement = '<br>{} by {} dated {}:'.format(self.announcement_title, self.author.forum_name, self.pub_date)
......
......@@ -18,4 +18,5 @@
</li>
{% endfor %}
</ul>
<a class="button main" href="{% url 'announcements:announcement-create' %}">New Announcement</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/announcements_stylesheet.css' %}">
{% endblock %}
{% block app_header %}New Announcement{% endblock %}
{% block content %}
<div class="wrapper">
<form class="post" method="post" enctype="multipart/form-data">
{% csrf_token %}
<ul>
{{ form.as_p }}
</ul>
<input class="button main" type="submit" value="Save Announcement">
<br/>
<a class="button secondary" href="{% url 'announcements:index' %}">Back to Announcements</a>
</form>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import AnnouncementPageView, AnnouncementDetailView
from .views import AnnouncementPageView, AnnouncementDetailView, AnnouncementCreateView, AnnouncementUpdateView
urlpatterns = [
path('', AnnouncementPageView.as_view(), name='index'),
path('announcement/<int:pk>/details', AnnouncementDetailView.as_view(), name='announcement-detail'),
path('announcement/<int:pk>/details', AnnouncementDetailView.as_view(), name='announcement-detail'),
path('announcement/add', AnnouncementCreateView.as_view(), name='announcement-create'),
path('announcement/<int:pk>/update', AnnouncementUpdateView.as_view(), name='announcement-update')
]
app_name = "announcements"
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement, Reaction
from .forms import AnnouncementForm
# Create your views here.
class AnnouncementPageView(View):
def get(self, request):
return render(request, 'announcements/announcement.html', {
'announcement_list': Announcement.objects.all().order_by('-id'),
'reaction_list': Reaction.objects.all().order_by('-id')
'reaction_list': Reaction.objects.all().order_by('-id'),
'form': AnnouncementForm
})
def post(request):
if request.method == 'POST':
form = AnnouncementForm(request.POST)
if form.is_valid():
new_announcement = form.save()
return redirect('/announcements/', pk=new_announcement.pk)
else:
form = AnnouncementForm()
return render(request, 'announcement.html', {'form': form})
class AnnouncementDetailView(DetailView):
model = Announcement
class AnnouncementCreateView(CreateView):
model = Announcement
fields = ['announcement_title', 'announcement_body', 'author', 'image']
form = AnnouncementForm
class AnnouncementUpdateView(UpdateView):
model = Announcement
fields = ['announcement_title', 'announcement_body', 'author', 'image']
form = AnnouncementForm
\ No newline at end of file
No preview for this file type
......@@ -27,6 +27,33 @@ h3 {
text-align: center;
}
.button {
border-radius: 6px;
font-size: 20px;
display:block;
font-weight:bold;
margin: 0 auto;
padding: 20px 0px 20px 0px;
text-align:center;
text-decoration:none;
width: 80%;
}
.button.main {
background-color: #222;
color: #FFF !important;
}
.button.secondary {
background-color: #CCC;
color: #222;
}
.button:hover {
background-color: rgb(43, 30, 216);
color: #FFF !important;
}
.author {
font-weight: bold;
}
......@@ -67,4 +94,19 @@ h3 {
.title {
font-size: 20px;
font-weight: bold;
}
.wrapper {
margin: 0 auto;
width: 80%;
}
.wrapper form ul {
padding-left: 0px;
padding-bottom: 24px;
padding-top: 24px;
}
.wrapper form label {
font-weight:bold;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment