From ebb29495c241d712f392ebe7a05b64b0aa4d70ce Mon Sep 17 00:00:00 2001
From: Jomaro Rodrigues <jomaro.rodrigues@gmail.com>
Date: Sat, 24 Mar 2018 15:28:46 -0300
Subject: [PATCH] =?UTF-8?q?teste=20configura=C3=A7=C3=A3o?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Pipfile                       |  2 ++
 Pipfile.lock                  | 38 ++++++++++++++++++++++++++++++++++-
 postgres/config_db.sql        |  8 ++++++++
 src/adega/models.py           | 21 +++++++++++++++++++
 src/adega/settings.py         | 23 +++++++++++++++++++--
 src/adega/templates/base.html |  2 +-
 src/adega/wsgi.py             |  2 +-
 src/uploads/models.py         | 33 ++++++++++++++++++++++++++----
 8 files changed, 120 insertions(+), 9 deletions(-)
 create mode 100644 postgres/config_db.sql
 create mode 100644 src/adega/models.py

diff --git a/Pipfile b/Pipfile
index a71efcf..dfa9a64 100644
--- a/Pipfile
+++ b/Pipfile
@@ -20,3 +20,5 @@ pandas = "==0.22"
 xlrd = "*"
 django-extensions = "*"
 ujson = "*"
+eventlet = "*"
+gunicorn = "*"
diff --git a/Pipfile.lock b/Pipfile.lock
index 8356c5a..d4f81a3 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "36924d8179f463a93a6998ff08f3840a6e3125ae52f0dbf7a2a82a3563d8e337"
+            "sha256": "2b51b796db79b08a70f4bd79d2c02e9da78e85ff73af01b3a00fa06a7ae901d6"
         },
         "host-environment-markers": {
             "implementation_name": "cpython",
@@ -48,6 +48,42 @@
             ],
             "version": "==1.4.1"
         },
+        "eventlet": {
+            "hashes": [
+                "sha256:87b2afb22fb7601f77e9cb9481e3e8c557e8cac9df69b5b2dc0b38ec5c23d67a",
+                "sha256:46b7e565aaa06b5d1ba435cb355e09cf3002e34dc269671c93c960f9879d30e0"
+            ],
+            "version": "==0.22.1"
+        },
+        "greenlet": {
+            "hashes": [
+                "sha256:50643fd6d54fd919f9a0a577c5f7b71f5d21f0959ab48767bd4bb73ae0839500",
+                "sha256:c7b04a6dc74087b1598de8d713198de4718fa30ec6cbb84959b26426c198e041",
+                "sha256:b6ef0cabaf5a6ecb5ac122e689d25ba12433a90c7b067b12e5f28bdb7fb78254",
+                "sha256:fcfadaf4bf68a27e5dc2f42cbb2f4b4ceea9f05d1d0b8f7787e640bed2801634",
+                "sha256:b417bb7ff680d43e7bd7a13e2e08956fa6acb11fd432f74c97b7664f8bdb6ec1",
+                "sha256:769b740aeebd584cd59232be84fdcaf6270b8adc356596cdea5b2152c82caaac",
+                "sha256:c2de19c88bdb0366c976cc125dca1002ec1b346989d59524178adfd395e62421",
+                "sha256:5b49b3049697aeae17ef7bf21267e69972d9e04917658b4e788986ea5cc518e8",
+                "sha256:09ef2636ea35782364c830f07127d6c7a70542b178268714a9a9ba16318e7e8b",
+                "sha256:f8f2a0ae8de0b49c7b5b2daca4f150fdd9c1173e854df2cce3b04123244f9f45",
+                "sha256:1b7df09c6598f5cfb40f843ade14ed1eb40596e75cd79b6fa2efc750ba01bb01",
+                "sha256:75c413551a436b462d5929255b6dc9c0c3c2b25cbeaee5271a56c7fda8ca49c0",
+                "sha256:58798b5d30054bb4f6cf0f712f08e6092df23a718b69000786634a265e8911a9",
+                "sha256:42118bf608e0288e35304b449a2d87e2ba77d1e373e8aa221ccdea073de026fa",
+                "sha256:ad2383d39f13534f3ca5c48fe1fc0975676846dc39c2cece78c0f1f9891418e0",
+                "sha256:1fff21a2da5f9e03ddc5bd99131a6b8edf3d7f9d6bc29ba21784323d17806ed7",
+                "sha256:0fef83d43bf87a5196c91e73cb9772f945a4caaff91242766c5916d1dd1381e4"
+            ],
+            "version": "==0.4.13"
+        },
+        "gunicorn": {
+            "hashes": [
+                "sha256:75af03c99389535f218cc596c7de74df4763803f7b63eb09d77e92b3956b36c6",
+                "sha256:eee1169f0ca667be05db3351a0960765620dad53f53434262ff8901b68a1b622"
+            ],
+            "version": "==19.7.1"
+        },
         "numpy": {
             "hashes": [
                 "sha256:719d914f564f35cce4dc103808f8297c807c9f0297ac183ed81ae8b5650e698e",
diff --git a/postgres/config_db.sql b/postgres/config_db.sql
new file mode 100644
index 0000000..8b54d22
--- /dev/null
+++ b/postgres/config_db.sql
@@ -0,0 +1,8 @@
+CREATE DATABASE adega;
+
+CREATE USER adega WITH PASSWORD 'adega';
+
+ALTER ROLE myprojectuser SET client_encoding TO 'utf8';
+ALTER ROLE myprojectuser SET default_transaction_isolation TO 'read committed';
+ALTER ROLE myprojectuser SET timezone TO 'UTC-3';
+GRANT ALL PRIVILEGES ON DATABASE adega TO adega;
diff --git a/src/adega/models.py b/src/adega/models.py
new file mode 100644
index 0000000..c91c37b
--- /dev/null
+++ b/src/adega/models.py
@@ -0,0 +1,21 @@
+
+
+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)
diff --git a/src/adega/settings.py b/src/adega/settings.py
index 5d76a15..db345c8 100644
--- a/src/adega/settings.py
+++ b/src/adega/settings.py
@@ -62,7 +62,7 @@ ROOT_URLCONF = 'adega.urls'
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [], #[os.path.join(BASE_DIR, 'uploads/templates'),],
+        'DIRS': [],
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
@@ -89,6 +89,18 @@ DATABASES = {
     }
 }
 
+if not DEBUG:
+    DATABASES = {
+        'default': {
+            'ENGINE': 'django.db.backends.postgresql_psycopg2',
+            'NAME': 'adega',
+            'USER': 'adega',
+            'PASSWORD': 'adega',
+            'HOST': 'localhost',
+            'PORT': '',
+        }
+    }
+
 
 AUTHENTICATION_BACKENDS = ['public.auth.EmailBackend']
 
@@ -136,7 +148,14 @@ MESSAGE_TAGS = {
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/1.9/howto/static-files/
 
-STATIC_URL = '/static/'
+
+if not DEBUG:
+    FORCE_SCRIPT_NAME = '/adega/'
+
+    STATIC_URL = '/adega/static/'
+else:
+    STATIC_URL = '/static/'
+
 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 
 MEDIA_URL = '/script/base/'
diff --git a/src/adega/templates/base.html b/src/adega/templates/base.html
index dd9422b..22bc068 100644
--- a/src/adega/templates/base.html
+++ b/src/adega/templates/base.html
@@ -59,7 +59,7 @@
           <div class="col-md-4 offset-md-4">
             <h3>Mantido por</h3>
             <a href="http://pet.inf.ufpr.br">
-              <img src="/static/pet/logo_preto.png" width="75%">
+              <img src="{% static 'pet/logo_preto.png' %}" width="75%">
             </a>
           </div>
         </div>
diff --git a/src/adega/wsgi.py b/src/adega/wsgi.py
index 76b6451..0c13d98 100644
--- a/src/adega/wsgi.py
+++ b/src/adega/wsgi.py
@@ -11,6 +11,6 @@ import os
 
 from django.core.wsgi import get_wsgi_application
 
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "uploads.settings")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "adega.settings")
 
 application = get_wsgi_application()
diff --git a/src/uploads/models.py b/src/uploads/models.py
index ac914d6..5293b5d 100644
--- a/src/uploads/models.py
+++ b/src/uploads/models.py
@@ -5,18 +5,28 @@ from django.utils import timezone
 from os import path
 from django.conf import settings
 
+from adega.models import Course
+
 
 def get_path(instance, filename):
     return '{}/{}/{}'.format(instance.course, instance.id, filename)
 
 
 class Submission(models.Model):
+    STATUS_ONGOING = 0
+    STATUS_FINISHED = 1
+
+    STATUS = (
+        (STATUS_ONGOING, 'Em andamento'),
+        (STATUS_FINISHED, 'Terminado'),
+    )
+
     author = models.ForeignKey(User)
 
     historico = models.FileField(upload_to=get_path)
     matricula = models.FileField(upload_to=get_path)
 
-    course = models.CharField(max_length=10, default='21A')
+    course = models.ForeignKey(Course)
 
     timestamp = models.DateTimeField(default=timezone.now)
 
@@ -26,10 +36,25 @@ class Submission(models.Model):
 
     process_time = models.IntegerField(null=True)
 
+    relative_year = models.IntegerField(null=True)
+
+    relative_semester = models.IntegerField(null=True)
+
+    semester_status = models.IntegerField(null=True, choices=STATUS)
+
+    done_in = models.DateTimeField(null=True)
+
     def path(self):
-        return path.join(settings.MEDIA_ROOT, self.course, str(self.id))
+        return path.join(settings.MEDIA_ROOT, self.course.code, str(self.id))
 
     def __str__(self):
         return 'Submission (from: {}, to: {}, on: {})'.format(self.author.first_name,
-                                                              self.course,
-                                                              self.timestamp)
\ No newline at end of file
+                                                              self.course.name,
+                                                              self.timestamp)
+
+    def set_done(self, time):
+        self.processed = True
+        self.process_time = time
+        self.done_in = timezone.now()
+
+        self.save()
-- 
GitLab