Skip to content
Snippets Groups Projects
Commit 1a80b590 authored by omdj17's avatar omdj17
Browse files

Merge branch 'postgres' into 'master'

Postgres

See merge request adega/adega!15
parents 2de8e121 f844033f
No related branches found
No related tags found
1 merge request!1WIP: Development
...@@ -13,10 +13,12 @@ ipython = "*" ...@@ -13,10 +13,12 @@ ipython = "*"
[packages] [packages]
django = "==1.11.10" Django = "==1.11.10"
django-widget-tweaks = "*" django-widget-tweaks = "*"
pandas = "==0.22" pandas = "==0.22"
"psycopg2" = "*"
xlrd = "*" xlrd = "*"
django-extensions = "*" django-extensions = "*"
ujson = "*" ujson = "*"
eventlet = "*"
gunicorn = "*"
"psycopg2" = "*"
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "36924d8179f463a93a6998ff08f3840a6e3125ae52f0dbf7a2a82a3563d8e337" "sha256": "506dfbad122a94230d6952bbf1da47476b37c68327808ca3e13ce247636d10b8"
}, },
"host-environment-markers": { "host-environment-markers": {
"implementation_name": "cpython", "implementation_name": "cpython",
...@@ -48,6 +48,42 @@ ...@@ -48,6 +48,42 @@
], ],
"version": "==1.4.1" "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": { "numpy": {
"hashes": [ "hashes": [
"sha256:719d914f564f35cce4dc103808f8297c807c9f0297ac183ed81ae8b5650e698e", "sha256:719d914f564f35cce4dc103808f8297c807c9f0297ac183ed81ae8b5650e698e",
...@@ -114,10 +150,10 @@ ...@@ -114,10 +150,10 @@
}, },
"python-dateutil": { "python-dateutil": {
"hashes": [ "hashes": [
"sha256:07009062406cffd554a9b4135cd2ff167c9bf6b7aac61fe946c93e69fad1bbd8", "sha256:6c0e72580272b561d8594362ab0e6b5b2191c703982150fc06ed45f7fae725be",
"sha256:8f95bb7e6edbb2456a51a1fb58c8dca942024b4f5844cae62c90aa88afe6e300" "sha256:14eb44faa298942c6385636bfd76bd5c21361632cf8ebc9c20d63fd00f6a069f"
], ],
"version": "==2.7.0" "version": "==2.7.1"
}, },
"pytz": { "pytz": {
"hashes": [ "hashes": [
......
...@@ -32,6 +32,13 @@ make install-user ...@@ -32,6 +32,13 @@ make install-user
pipenv install --dev pipenv install --dev
``` ```
Criar o banco de dados postgres
```
sudo -u postgres psql < postgres/create.sql
```
se você possui o arquivo do banco de dados compartilhado internamente pelos se você possui o arquivo do banco de dados compartilhado internamente pelos
desenvolvedores do projeto coloque-o na home do projeto, ele vem com um usuário desenvolvedores do projeto coloque-o na home do projeto, ele vem com um usuário
`pet` com senha `pet` pré-configurado para testes. `pet` com senha `pet` pré-configurado para testes.
......
#!/usr/bin/bash
(cd src; python manage.py collectstatic)
if ! sudo -u postgres psql adega
then
sudo -u postgres psql < postgres/create.sql
fi
python manage.py migrate
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/adega/src
ExecStart=/var/www/adega/venv/bin/gunicorn --access-logfile - -k eventlet --workers 4 --bind unix:/var/www/adega/adega.sock adega.wsgi:application
[Install]
WantedBy=multi-user.target
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
upstream adega {
server unix:/var/www/adega/adega.sock fail_timeout=10;
}
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
charset utf-8;
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /etc/ssl/adega/adega.crt;
ssl_certificate_key /etc/ssl/adega/adega.key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# modern configuration. tweak to your needs.
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
## verify chain of trust of OCSP response using Root CA and Intermediate certs
#ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
# resolver <IP DNS resolver>;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
autoindex on;
try_files $uri $uri/ =404;
disable_symlinks off;
}
location /adega {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
include proxy_params;
proxy_redirect off;
proxy_pass http://adega/;
}
location /adega/static {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /var/www;
autoindex on;
try_files $uri $uri/ =404;
disable_symlinks on;
}
location ~ /\.ht {
deny all;
}
}
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
upstream adega {
server unix:/var/www/adega/adega.sock fail_timeout=10;
}
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
charset utf-8;
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /etc/ssl/adega/adega.crt;
ssl_certificate_key /etc/ssl/adega/adega.key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# modern configuration. tweak to your needs.
ssl_protocols TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
## verify chain of trust of OCSP response using Root CA and Intermediate certs
#ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
# resolver <IP DNS resolver>;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
autoindex on;
try_files $uri $uri/ =404;
disable_symlinks off;
}
location /adega {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
include proxy_params;
proxy_redirect off;
proxy_pass http://adega/;
}
location /adega/static {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
root /var/www;
autoindex on;
try_files $uri $uri/ =404;
disable_symlinks on;
}
location ~ /\.ht {
deny all;
}
}
CREATE DATABASE adega;
CREATE USER adega WITH PASSWORD 'adega';
ALTER ROLE adega SET client_encoding TO 'utf8';
ALTER ROLE adega SET default_transaction_isolation TO 'read committed';
ALTER ROLE adega SET timezone TO 'UTC-3';
GRANT ALL PRIVILEGES ON DATABASE adega TO adega;
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)
...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'adega.urls' ...@@ -62,7 +62,7 @@ ROOT_URLCONF = 'adega.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], #[os.path.join(BASE_DIR, 'uploads/templates'),], 'DIRS': [],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
...@@ -82,10 +82,22 @@ WSGI_APPLICATION = 'adega.wsgi.application' ...@@ -82,10 +82,22 @@ WSGI_APPLICATION = 'adega.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
#}
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 'NAME': 'adega',
'USER': 'adega',
'PASSWORD': 'adega',
'HOST': 'localhost',
'PORT': '5432',
} }
} }
...@@ -136,11 +148,18 @@ MESSAGE_TAGS = { ...@@ -136,11 +148,18 @@ MESSAGE_TAGS = {
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/ # https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') if not DEBUG:
FORCE_SCRIPT_NAME = '/adega/'
STATIC_URL = '/adega/static/'
else:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
MEDIA_URL = '/script/base/' MEDIA_URL = '/script/base/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'script/base') MEDIA_ROOT = os.path.join(PROJECT_DIR, 'uploads')
# MEDIA_URL = None # a gente não quer ninguem fazendo download disso # MEDIA_URL = None # a gente não quer ninguem fazendo download disso
# MEDIA_ROOT = os.path.join(PROJECT_DIR, 'uploads') # MEDIA_ROOT = os.path.join(PROJECT_DIR, 'uploads')
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
<div class="col-md-4 offset-md-4"> <div class="col-md-4 offset-md-4">
<h3>Mantido por</h3> <h3>Mantido por</h3>
<a href="http://pet.inf.ufpr.br"> <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> </a>
</div> </div>
</div> </div>
......
...@@ -11,6 +11,6 @@ import os ...@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application 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() application = get_wsgi_application()
...@@ -15,10 +15,7 @@ def analyze(submission): ...@@ -15,10 +15,7 @@ def analyze(submission):
build_cache(dataframe) build_cache(dataframe)
submission.processed = True submission.set_done(round(time.clock() - start_time))
submission.process_time = round(time.clock() - start_time)
submission.save()
cpu_time = timedelta(seconds=round(time.clock() - start_time)) cpu_time = timedelta(seconds=round(time.clock() - start_time))
run_time = timedelta(seconds=round(time.time() - start_time_exec)) run_time = timedelta(seconds=round(time.time() - start_time_exec))
......
...@@ -5,18 +5,28 @@ from django.utils import timezone ...@@ -5,18 +5,28 @@ 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
def get_path(instance, filename): def get_path(instance, filename):
return '{}/{}/{}'.format(instance.course, instance.id, filename) return '{}/{}/{}'.format(instance.course, instance.id, filename)
class Submission(models.Model): class Submission(models.Model):
STATUS_ONGOING = 0
STATUS_FINISHED = 1
STATUS = (
(STATUS_ONGOING, 'Em andamento'),
(STATUS_FINISHED, 'Terminado'),
)
author = models.ForeignKey(User) author = models.ForeignKey(User)
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.CharField(max_length=10, default='21A') course = models.ForeignKey(Course)
timestamp = models.DateTimeField(default=timezone.now) timestamp = models.DateTimeField(default=timezone.now)
...@@ -26,10 +36,25 @@ class Submission(models.Model): ...@@ -26,10 +36,25 @@ class Submission(models.Model):
process_time = models.IntegerField(null=True) 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): 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): 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, self.course.name,
self.timestamp) self.timestamp)
\ No newline at end of file
def set_done(self, time):
self.processed = True
self.process_time = time
self.done_in = timezone.now()
self.save()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment