Commit 3ac628a2 authored by Franco Velasco's avatar Franco Velasco

Merge branch 'tan/assignments' into 'master'

Added POST functionality to Assignments

See merge request !20
parents 4f7f5afc 26c273cc
from django import forms
from .models import Assignment
class AssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
fields = '__all__'
# Generated by Django 4.0.4 on 2022-05-24 10:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Assignments', '0007_alter_assignment_course'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
]
...@@ -18,6 +18,7 @@ class Assignment(models.Model): ...@@ -18,6 +18,7 @@ class Assignment(models.Model):
on_delete = models.CASCADE, on_delete = models.CASCADE,
related_name = 'requirements' related_name = 'requirements'
) )
image = models.ImageField(null=True, blank = True)
def __str__(self): def __str__(self):
return 'Assignment name: {} :{}'.format(self.name, self.description) return 'Assignment name: {} :{}'.format(self.name, self.description)
......
...@@ -76,4 +76,9 @@ a:hover{ ...@@ -76,4 +76,9 @@ a:hover{
#details h4{ #details h4{
font-size: 20px; font-size: 20px;
font-weight: 500; font-weight: 500;
}
#button a{
font-weight: 900px;
padding: 5em;
} }
\ No newline at end of file
...@@ -10,7 +10,11 @@ ...@@ -10,7 +10,11 @@
</div> </div>
<div id = "details"> <div id = "details">
<img src="{%static 'images/jokebear.png'%}"> <a href = "/assignments"> > Back to home </a>
<br>
<!-- <img src="{%static 'images/jokebear.png'%}">-->
<img src = "{{object.image.url}}">
<h5> Assignment Name: </h5> <h5> Assignment Name: </h5>
<h3>{{object.name}} </h3> <h3>{{object.name}} </h3>
<h4> <b>Assignment Description:</b> {{object.description}} </h4> <h4> <b>Assignment Description:</b> {{object.description}} </h4>
......
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel = "stylesheet" href="{% static 'css/index.css' %}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@200;500;900&display=swap" rel="stylesheet">
{% endblock styles %}
{% block title %} Assignments {% endblock title%}
{% block content %}
<div id = "header">
<h1> Create a new assignment </h1>
</div>
<div id = "courses" style="margin: 5em;">
<a href = "/assignments"> > Back to home </a>
<form action="{% url 'Assignments:assignment-list' %}" method = "POST" style = "padding-top: 5em;" enctype = "multipart/form-data">
{% csrf_token %}
{{form}}
<input type = "submit" value = "Create New Subject">
</form>
</div>
{%endblock content%}
\ No newline at end of file
...@@ -17,5 +17,9 @@ ...@@ -17,5 +17,9 @@
<h1> List of courses: </h1> <h1> List of courses: </h1>
</div> </div>
{% include "Assignments/assignment_list.html" with assignments=assignment course=course %} {% include "Assignments/assignment_list.html" with assignments=assignment course=course %}
<div id = "button">
<a href = "/assignments/add" id = "assignment-button" style = "font-weight: 900px"> > New Assignment </a>
</div>
{%endblock content%} {%endblock content%}
\ No newline at end of file
from django.shortcuts import render from ast import Assign
from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from .models import Assignment, Course from .models import Assignment, Course
from .forms import AssignmentForm
class MainView(View): class MainView(View):
def get(self, request): def get(self, request):
...@@ -13,10 +15,32 @@ class MainView(View): ...@@ -13,10 +15,32 @@ class MainView(View):
return render(request, 'assignments.html',{ return render(request, 'assignments.html',{
'course': course, 'course': course,
'assignment': assignment, 'assignment': assignment,
'form': AssignmentForm(),
}) })
class AssignmentListView(ListView): class AssignmentListView(ListView):
model = Assignment model = Assignment
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = AssignmentForm()
return context
def post(self, request, *args, **kwargs):
form = AssignmentForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('/assignments')
return self.get(request, *args, **kwargs)
class AssignmentDetailView(DetailView): class AssignmentDetailView(DetailView):
model = Assignment model = Assignment
class AssignmentPostView(View):
def get(self,request):
return render(request, 'assignment_post.html',{
'form': AssignmentForm(),
})
...@@ -19,7 +19,7 @@ from django.contrib import admin ...@@ -19,7 +19,7 @@ from django.contrib import admin
from django.urls import path, include from django.urls import path, include
import Announcements.views as Announcements_views import Announcements.views as Announcements_views
import Forum.views as Forum_views import Forum.views as Forum_views
from Assignments.views import AssignmentDetailView from Assignments.views import AssignmentDetailView, AssignmentPostView
from Homepage.views import UserPageView from Homepage.views import UserPageView
urlpatterns = [ urlpatterns = [
...@@ -33,6 +33,7 @@ urlpatterns = [ ...@@ -33,6 +33,7 @@ urlpatterns = [
path('announcements/<int:announcement_id>/details', Announcements_views.details, name='announcement_details'), path('announcements/<int:announcement_id>/details', Announcements_views.details, name='announcement_details'),
path('assignments/', include('Assignments.urls', namespace="Assignments")), path('assignments/', include('Assignments.urls', namespace="Assignments")),
path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name ='assignment-detail'), path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name ='assignment-detail'),
path('assignments/add/', AssignmentPostView.as_view(), name = 'assignement-post'),
] ]
......
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