Commit 5ccb5b67 authored by Odair M.'s avatar Odair M.
Browse files

Merge branch 'degree_app' into 'master'

Degree app

See merge request adega/adega!17
parents e5e2f770 794b1045
from django.db import models
from django.contrib.auth.models import User
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):
user = models.OneToOneField(User)
......@@ -43,6 +43,8 @@ INSTALLED_APPS = [
'adega',
'public',
'degree',
'educator',
'uploads'
]
......
from django.contrib import admin
from .models import Degree
admin.site.register(Degree)
from django.apps import AppConfig
class DegreeConfig(AppConfig):
name = 'degree'
from django.db import models
from django.contrib.auth.models import User
class Degree(models.Model):
name = models.CharField(max_length=40)
code = models.CharField(max_length=40)
manager = models.ForeignKey(User)
def __str__(self):
return self.code
def clean_code(self):
if '/' in self.code:
raise ValidationError('Valor inválido: O código não pode conter "/"')
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
from .models import Educator
admin.site.register(Educator)
from django.apps import AppConfig
class EducatorConfig(AppConfig):
name = 'educator'
from django.db import models
from django.contrib.auth.models import User
from degree.models import Degree
class Educator(models.Model):
user = models.OneToOneField(User)
degree = models.ManyToManyField(Degree)
def __str__(self):
return "{}".format(self.user.username)
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
......@@ -23,7 +23,7 @@ def make_analysis(modeladmin, request, queryset):
class SubmissionAdmin(admin.ModelAdmin):
date_hierarchy = 'timestamp'
list_display = ('author', 'course', 'processed', 'last', 'timestamp')
list_display = ('author', 'degree', 'processed', 'last', 'timestamp')
actions = [make_analysis]
......
......@@ -5,11 +5,11 @@ from django.utils import timezone
from os import path
from django.conf import settings
from adega.models import Course
from degree.models import Degree
def get_path(instance, filename):
return '{}/{}/{}'.format(instance.course, instance.id, filename)
return '{}/{}/{}'.format(instance.degree, instance.id, filename)
class Submission(models.Model):
......@@ -26,7 +26,7 @@ class Submission(models.Model):
historico = 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)
......@@ -45,11 +45,11 @@ class Submission(models.Model):
done_in = models.DateTimeField(null=True)
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):
return 'Submission (from: {}, to: {}, on: {})'.format(self.author.first_name,
self.course.name,
self.degree.name,
self.timestamp)
def set_done(self, time):
......
......@@ -10,7 +10,7 @@ def upload(request):
if request.method == 'POST' and request.FILES['historico'] and request.FILES['matricula']:
submission = Submission.objects.create(author=request.user)
submission.course = '21A'
submission.degree = request.user.educator.degree
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