Commit a124dc97 authored by Nics De Vega's avatar Nics De Vega

fixed merge conflicts in announcement_boardv2

parents 163e8db8 2d64e7fb
**/.env
db.sqlite3
.DS_Store
**/**/__pycache__
\ No newline at end of file
**/**/__pycache__/**
**/**/**/__pycache__/**
from django.db import models
from dashboard.models import WidgetUser
from django.urls import reverse
from django.utils import timezone
class Announcement(models.Model):
title = models.CharField(max_length=100,default="")
body = models.TextField(default="")
author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE)
pub_datetime = models.DateTimeField()
pub_datetime = models.DateTimeField(default=timezone.now)
def __str__(self):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse("announcement_board:announcement-details",kwargs={'pk':self.pk})
def get_reactions(self):
reacts = {'Like':0,'Love':0,'Angry':0}
for key in reacts.keys():
try:
reacts[key]=Reaction.objects.get(announcement=self,name=key).tally
except:
reacts[key]=0
return reacts
class Reaction(models.Model):
name = models.CharField(max_length=20,default="")
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Announcement{% endblock %}
{% block content %}
<h1>Add a new Announcement</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}{{object.title}}{% endblock %}
{% block content %}
<h1>{{object.title}}</h1>
<h3>by {{object.author.first_name}} {{object.author.last_name}}</h3>
<h3>{{object.pub_datetime|date:'m/d/Y, h:i A'}}</h3>
<h3>{{object.body}}</h3>
{%for key, value in object.get_reactions.items%}
<h3>{{key}}: {{value}}</h3>
{% endfor%}
<form action="../edit">
<input type="submit" value="Edit Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Announcement{% endblock %}
{% block content %}
<h1>Edit Announcement</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Announcement">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcement Board!</h1>
<h3>
{% for object in announcements %}
<a href="{{ object.get_absolute_url }}">
{{object.title}} by {{object.author.first_name}} {{object.author.last_name}}
</a>
<br>
{% endfor %}
</h3>
<form action="add">
<input type="submit" value="Add Announcement">
</form>
<h3>
<a href="../dashboard/">Dashboard</a><br>
<a href="../forum/">Forum</a><br>
<a href="../assignments/">Assignments</a><br>
<a href="../calendar/">Calendar</a><br>
</h3>
{% endblock %}
from django.urls import path
from .views import index
from .views import (
announcements, AnnouncementCreateView, AnnouncementDetailView, AnnouncementUpdateView
)
urlpatterns = [
path('',index,name='index')
path('',announcements, name='announcements'),
path('<int:pk>/details/',AnnouncementDetailView.as_view(),name='announcement-details'),
path('add/',AnnouncementCreateView.as_view(),name='announcement-add'),
path('<int:pk>/edit/',AnnouncementUpdateView.as_view(),name='announcement-edit'),
]
app_name = 'announcement_board'
from django.http import HttpResponse
from .models import Announcement, Reaction
from dashboard.models import WidgetUser
from .models import Announcement
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
def announcements(request):
return render (request, 'announcement_board/announcements.html',
{'announcements':Announcement.objects.order_by('-pub_datetime')})
def index(request):
class AnnouncementDetailView(DetailView):
model = Announcement
template_name = "announcement_board/announcement-details.html"
return_string = '<body>'
for announcement in Announcement.objects.all():
announcement_heading = '{} by {} {} published {}:<br>'.format(
announcement.title,
announcement.author.first_name,
announcement.author.last_name,
announcement.pub_datetime.strftime("%m/%d/%Y, %I:%M %p")
)
announcement_body = '{}<br>'.format(announcement.body)
announcement_reactions = ''
class AnnouncementCreateView(CreateView):
model = Announcement
template_name = "announcement_board/announcement-add.html"
fields = ['title','body','author']
announcement_reactions += 'Like: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Like').tally)
announcement_reactions += 'Love: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Love').tally)
announcement_reactions += 'Angry: {}<br>'.format(Reaction.objects.get(announcement=announcement,name='Angry').tally)
return_string += announcement_heading + announcement_body + announcement_reactions +'<br>'
html_string ='<html>{}</html>'.format(return_string)
return HttpResponse('Widget’s Announcement Board<br><br>Announcements:<br>'+html_string)
class AnnouncementUpdateView(UpdateView):
model = Announcement
template_name = "announcement_board/announcement-edit.html"
fields = ['title','body','author']
\ No newline at end of file
......@@ -118,7 +118,7 @@ TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
......
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