Commit 55411191 authored by Jose Emmanuel B. Laurel's avatar Jose Emmanuel B. Laurel

Test: tested homepage

parents 81e2ed6a 94964d9e
from django.forms import ModelForm
from .models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = ["announcement_title", "announcement_body", "author", "pub_date"]
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-05-26 11:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('announcements', '0017_announcement_announce_image'),
]
operations = [
migrations.AlterField(
model_name='announcement',
name='announce_image',
field=models.ImageField(blank=True, default='faceless.png', null=True, upload_to=''),
),
]
......@@ -8,7 +8,7 @@ class Announcement(models.Model):
announcement_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published")
reaction_list = models.ForeignKey('Reaction', on_delete=models.CASCADE, related_name='+', default=1)
announce_image = models.ImageField(default="faceless_9ltCukV.png", null=True, blank=True)
announce_image = models.ImageField(default="faceless.png", null=True, blank=True)
def __str__(self):
return self.announcement_title
......
......@@ -11,4 +11,10 @@
{% else %}
<p> No announcements here! </p>
{% endif %}
<form action="add">
<input type="Submit" value="Make an announcement!">
</form>
{% endblock %}
\ No newline at end of file
{% extends "announcement/base.html" %}
{% block content %}
<h1> NEW ANNOUNCEMENT </h1>
<form action="{% url 'add' %}" method="POST">
{% csrf_token %}
<h3> Title: </h3> <input type="text" name="Title">
<h3> Body: </h3> <textarea rows="5" cols="60" name="Body" placeholder="Type your announcement here..."> </textarea>
<br>
<br>
<select class="custom-select mb-4" name="Author">
<option selected> Choose an author </option>
{% for author in Author %}
<option value="{{ author.pk }}"> {{ author.first_name }} {{ author.last_name }} </option>
{% endfor %}
</select>
<br>
<br>
<button class="button" type="submit"> Save Announcement </button>
</form>
<br>
<br>
<a href="{% url 'showAnnouncements' %}"> Go back </a>
{% endblock %}
\ No newline at end of file
{% extends "announcement/base.html" %}
{% block content %}
<form method="POST" action = "{% url 'announcements:newannounce' %}">
{% csrf_token %}
{{ announce_form.as_p }}
<button class="button" type="submit"> Save </button>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
from django.conf import settings
from .views import showAnnouncements
urlpatterns = [
path('', views.index, name='index'),
path("<int:announcement_id>", views.detail, name="detail"),
path('', showAnnouncements.as_view(), name='showAnnouncements'),
path("<int:announcement_id>/", views.detail, name="detail"),
path("add/", views.add, name="add"),
#path("add/newAnnounce", views.newAnnounce, name="newAnnounce")
]
\ No newline at end of file
from django.http import Http404
from django.shortcuts import render
from .models import Announcement, Reaction
from django.http import Http404, HttpResponse
from django.shortcuts import render, redirect
from .models import Announcement, Reaction
from homepage.models import WidgetUser
import datetime
from .forms import AnnouncementForm
from django.views import View
# Create your views here.
#def show_announcements(request):
#announcement = Announcement.objects.all()
#return render(request, 'announcement/announcement_board.html', {'announcements': announcement})
def index(request):
announce_list = Announcement.objects.order_by("pub_date")
......@@ -16,6 +16,30 @@ def index(request):
}
return render(request, "announcement/announcement_page.html", context)
class showAnnouncements(View):
def get(self, request):
announce_list = Announcement.objects.order_by("pub_date")
context = {
"announce_list": announce_list,
}
return render(request, "announcement/announcement_page.html", context)
def add(request):
author = WidgetUser.objects.all()
context = {
"Author": author,
}
if request.method == "POST":
title = request.POST.get("Title")
body = request.POST.get("Body")
author = request.POST.get("Author")
pub_date = datetime.datetime.now()
announcement = Announcement.objects.create(author_id = author, announcement_title = title, announcement_body = body, pub_date = pub_date)
return redirect('add')
return render(request, "announcement/create_announcement.html", context)
def detail(request, announcement_id):
try:
announce = Announcement.objects.get(pk=announcement_id)
......@@ -24,3 +48,4 @@ def detail(request, announcement_id):
reacts = Reaction.objects.filter(announcement_id=announce).order_by("reaction_name")
return render(request, "announcement/announcement_board.html", {"announce": announce, "reacts": reacts})
from django import forms
from django.db import models
from django.forms import ModelForm
from assignments.models import Assignment
from assignments.models import Course
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
class AssignmentForm(forms.Form):
assignment_name = forms.CharField(label='Assignment Name', max_length=100)
assignment_description = forms.CharField(label='Description', max_length=1000)
assignment_max_points = forms.IntegerField(label='Max Points')
assignment_course = forms.ModelChoiceField(label='Course', queryset=Course.objects.all())
\ No newline at end of file
{% load static %}
<p>
<h2>New Assignment</h2>
<form action="{% url 'assignment:addassignment' %}" method="POST">
{% csrf_token %}
{{form}}
<input type="hidden" name="next" value="{{ request.path }}">
<button type="submit">Save Assignment</button>
</form>
<button><a class="btn btn-secondary" href="{% url 'assignment:ShowCoursesView' %}">
Back
</a></button>
</p>
\ No newline at end of file
......@@ -14,4 +14,7 @@
{% else %}
<p>No courses registered.</p>
{% endif %}
<button><a class="btn btn-secondary" href="{% url 'assignment:AddAssignment' %}">
New Assignment
</a></button>
</p>
\ No newline at end of file
......@@ -2,9 +2,13 @@ from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
from .views import ShowCoursesView, add_assignment
from .views import AddAssignmentView
app_name = "assignment"
urlpatterns = [
path('', views.show_courses_page, name='ShowCoursesPage'),
path("assignment/<int:assignment_id>/details/", views.show_assignment_details, name='ShowAssignmentDetails')
path('', ShowCoursesView.as_view(), name='ShowCoursesView'),
path('<int:assignment_id>/details/', views.show_assignment_details, name='ShowAssignmentDetails'),
path('add/', AddAssignmentView.as_view(), name='AddAssignment'),
path('add/NewAssignment', views.add_assignment, name='addassignment')
]
\ No newline at end of file
from .models import Assignment, Course
from django.shortcuts import render
from django.http import Http404
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.views.generic import ListView,DetailView
from django.views import View
from .forms import AssignmentForm
# Create your views here.
course = Course.objects.order_by("course_code")
def show_courses_page(request):
course = Course.objects.order_by("course_code")
class ShowCoursesView(View):
def get(self, request):
context = {
"course": course,
"assignments": Assignment.objects.all()
}
return render(request, 'assignment_Courses_Ordered.html', context)
"""def show_courses_ordered(request):
context = {
"course": course,
"assignments": Assignment.objects.all()
}
return render(request, 'assignment_Courses_Ordered.html', context)"""
def show_assignment_details(request, assignment_id):
try:
assignment = Assignment.objects.get(pk=assignment_id)
assignment = Assignment.objects.get(assignment_id=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
......@@ -24,3 +35,24 @@ def show_assignment_details(request, assignment_id):
}
return render(request, "assignment_Assignment_Details.html", context)
class AddAssignmentView(View):
def get(self, request):
context = {
"form": AssignmentForm()
}
return render(request, 'assignment_Add_Assignment.html', context)
def add_assignment(request):
if request.method == "POST":
add_assignment_id = Assignment.objects.all().count() + 1
add_assignment_name = request.POST.get("assignment_name")
add_assignment_description = request.POST.get("assignment_description")
add_assignment_max_points = int(request.POST.get("assignment_max_points"))
add_assignment_passing_score = int(int(add_assignment_max_points)*60/100)
course_num = int(request.POST.get("assignment_course"))
add_assignment_course = Course.objects.get(pk=course_num)
assignment = Assignment.objects.create(assignment_id=add_assignment_id, assignment_name=add_assignment_name, assignment_description=add_assignment_description, assignment_max_points=add_assignment_max_points, assignment_passing_score=add_assignment_passing_score, assignment_course = add_assignment_course)
next = request.POST.get('next','/')
return HttpResponseRedirect(next)
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