Commit 82bdd27b authored by Odair M.'s avatar Odair M.
Browse files

muda o nome course para degree

parent 07093e8e
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
class Course(models.Model):
name = models.CharField(max_length=40)
code = models.CharField(max_length=40)
manager = models.ForeignKey(User)
def clean_code(self):
if '/' in self.code:
raise ValidationError('Valor inválido: O código não pode conter "/"')
class Professor(models.Model): class Professor(models.Model):
user = models.OneToOneField(User) user = models.OneToOneField(User)
...@@ -23,7 +23,7 @@ def make_analysis(modeladmin, request, queryset): ...@@ -23,7 +23,7 @@ def make_analysis(modeladmin, request, queryset):
class SubmissionAdmin(admin.ModelAdmin): class SubmissionAdmin(admin.ModelAdmin):
date_hierarchy = 'timestamp' date_hierarchy = 'timestamp'
list_display = ('author', 'course', 'processed', 'last', 'timestamp') list_display = ('author', 'degree', 'processed', 'last', 'timestamp')
actions = [make_analysis] actions = [make_analysis]
......
...@@ -5,7 +5,7 @@ from django.utils import timezone ...@@ -5,7 +5,7 @@ from django.utils import timezone
from os import path from os import path
from django.conf import settings from django.conf import settings
from adega.models import Course from degree.models import Degree
def get_path(instance, filename): def get_path(instance, filename):
...@@ -26,7 +26,7 @@ class Submission(models.Model): ...@@ -26,7 +26,7 @@ class Submission(models.Model):
historico = models.FileField(upload_to=get_path) historico = models.FileField(upload_to=get_path)
matricula = models.FileField(upload_to=get_path) matricula = models.FileField(upload_to=get_path)
course = models.ForeignKey(Course) degree = models.ForeignKey(Degree)
timestamp = models.DateTimeField(default=timezone.now) timestamp = models.DateTimeField(default=timezone.now)
...@@ -45,11 +45,11 @@ class Submission(models.Model): ...@@ -45,11 +45,11 @@ class Submission(models.Model):
done_in = models.DateTimeField(null=True) done_in = models.DateTimeField(null=True)
def path(self): def path(self):
return path.join(settings.MEDIA_ROOT, self.course.code, str(self.id)) return path.join(settings.MEDIA_ROOT, self.degree.code, str(self.id))
def __str__(self): def __str__(self):
return 'Submission (from: {}, to: {}, on: {})'.format(self.author.first_name, return 'Submission (from: {}, to: {}, on: {})'.format(self.author.first_name,
self.course.name, self.degree.name,
self.timestamp) self.timestamp)
def set_done(self, time): def set_done(self, time):
......
...@@ -6,11 +6,12 @@ from django.contrib import messages ...@@ -6,11 +6,12 @@ from django.contrib import messages
from uploads.models import Submission from uploads.models import Submission
@login_required
def upload(request): def upload(request):
if request.method == 'POST' and request.FILES['historico'] and request.FILES['matricula']: if request.method == 'POST' and request.FILES['historico'] and request.FILES['matricula']:
submission = Submission.objects.create(author=request.user) submission = Submission.objects.create(author=request.user)
submission.course = '21A' submission.degree = request.user.degree
fs = FileSystemStorage(location=submission.path()) fs = FileSystemStorage(location=submission.path())
......
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