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):
on_delete = models.CASCADE,
related_name = 'requirements'
)
image = models.ImageField(null=True, blank = True)
def __str__(self):
return 'Assignment name: {} :{}'.format(self.name, self.description)
......
......@@ -76,4 +76,9 @@ a:hover{
#details h4{
font-size: 20px;
font-weight: 500;
}
#button a{
font-weight: 900px;
padding: 5em;
}
\ No newline at end of file
......@@ -10,7 +10,11 @@
</div>
<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>
<h3>{{object.name}} </h3>
<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 @@
<h1> List of courses: </h1>
</div>
{% 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%}
\ 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.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Assignment, Course
from .forms import AssignmentForm
class MainView(View):
def get(self, request):
......@@ -13,10 +15,32 @@ class MainView(View):
return render(request, 'assignments.html',{
'course': course,
'assignment': assignment,
'form': AssignmentForm(),
})
class AssignmentListView(ListView):
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):
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
from django.urls import path, include
import Announcements.views as Announcements_views
import Forum.views as Forum_views
from Assignments.views import AssignmentDetailView
from Assignments.views import AssignmentDetailView, AssignmentPostView
from Homepage.views import UserPageView
urlpatterns = [
......@@ -33,6 +33,7 @@ urlpatterns = [
path('announcements/<int:announcement_id>/details', Announcements_views.details, name='announcement_details'),
path('assignments/', include('Assignments.urls', namespace="Assignments")),
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