Skip to content

Commit

Permalink
Merge pull request #38 from rafaelpezzuto/better-upload
Browse files Browse the repository at this point in the history
Altera envio de pacotes para envio por segundo plano e faz melhorias gerais
  • Loading branch information
rafaelpezzuto authored Dec 17, 2021
2 parents 668fbd5 + 4f1a032 commit 346ea9c
Show file tree
Hide file tree
Showing 21 changed files with 1,237 additions and 68 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ python manage.py makemigrations

# Migrate database (this operation will create all the necessary tables)
python manage.py migrate

# Create the superuser (take note of the credentials)
python manage.py createsuperuser
```

__Add default groups to the application database__
Expand All @@ -85,6 +82,9 @@ __Add example users to the application database (only in development environment
python manage.py loaddata user
```

__Override superuser credentials__
python manage.py createsuperuser

__Run the application__

```shell
Expand Down Expand Up @@ -200,7 +200,13 @@ __Make sure PostgreSQL and MongoDB databases are in the same network as the spf
---

## List of environment variables

- BASES_PATH: Isis Bases root directory
- BASES_PDF_PATH: Isis Base "PDF"
- BASES_TRANSLATION_PATH: Isis Base "Translation"
- BASES_WORK_PATH: Isis Base "Work"
- BASES_XML_PATH: Isis Base "XML"
- CISIS_PATH: CISIS root directory
- HTDOCS_IMG_REVISTAS_PATH: HTDOCS Image directory
- CELERY_BROKER_URL: RabbitMQ address (`pyamqp://user:pass@host:port`)
- DATABASE_CONNECT_URL: OPAC/Kernel database (MongoDB) string connection (`mongodb://user:pass@host:port/opac`)
- DJANGO_ALLOWED_HOSTS: `localhost;127.0.0.1;[::1]`
Expand Down
40 changes: 34 additions & 6 deletions app/core/controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from datetime import datetime
from django.contrib.auth.models import Group, User
from core.models import GROUP_MANAGER, SCOPE_ALL_USERS, IngressPackage, Event
from django.contrib.auth.models import (
Group,
User,
)
from core.models import (
GROUP_MANAGER,
SCOPE_ALL_USERS,
IngressPackage,
MigrationPackage,
Event,
)


def _is_privileged_user(user):
Expand All @@ -26,6 +35,10 @@ def get_user_from_username(username):
return User.objects.get(username=username)


def get_user_from_id(user_id):
return User.objects.get(id=user_id)


def get_users(include_superuser=False):
return User.objects.filter(is_superuser=include_superuser)

Expand Down Expand Up @@ -56,12 +69,16 @@ def get_groups():
return Group.objects.all()


def add_event(user, event_name, annotation=None):
def get_event_from_id(event_id):
return Event.objects.get(id=event_id)


def add_event(user, event_name, annotation=None, status=None):
event = Event()
event.user = user
event.name = event_name
event.annotation = annotation
event.status = Event.Status.INITIATED
event.status = status or Event.Status.INITIATED
event.save()

return event
Expand All @@ -76,12 +93,23 @@ def update_event(event, args):
return event


def add_ingress_package(user, event_datetime, package_name):
def add_ingress_package(user, event_datetime, package_name, status):
ip = IngressPackage()
ip.user = user
ip.datetime = event_datetime
ip.package_name = package_name
ip.status = IngressPackage.Status.RECEIVED
ip.status = status or IngressPackage.Status.RECEIVED
ip.save()

return ip


def add_migration_package(user, event_datetime, path):
mp = MigrationPackage()
mp.user = user
mp.datetime = event_datetime
mp.path = path
mp.status = MigrationPackage.Status.RECEIVED
mp.save()

return mp
23 changes: 23 additions & 0 deletions app/core/locale/es/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-10 19:43+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: static/js/main.js:69
msgid "Completed"
msgstr "Completado"
23 changes: 23 additions & 0 deletions app/core/locale/pt/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-10 19:43+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: static/js/main.js:69
msgid "Completed"
msgstr "Completado"
63 changes: 63 additions & 0 deletions app/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 3.2.6 on 2021-12-09 23:48

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='ValidationSchema',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('schema_name', models.CharField(max_length=200, null=True)),
],
),
migrations.CreateModel(
name='Validation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, null=True)),
('validation_schema', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='core.validationschema')),
],
),
migrations.CreateModel(
name='MigrationPackage',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('path', models.CharField(max_length=200)),
('datetime', models.DateTimeField(null=True)),
('status', models.CharField(choices=[('R', 'Received')], max_length=1)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='IngressPackage',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('package_name', models.CharField(max_length=200)),
('datetime', models.DateTimeField()),
('status', models.CharField(choices=[('R', 'Received'), ('Q', 'Queued for validation'), ('D', 'Validating'), ('F', 'Validation failure'), ('V', 'Validated')], max_length=1)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('datetime', models.DateTimeField(auto_now=True)),
('name', models.CharField(choices=[('RP', 'Retrieve package'), ('UP', 'Upload package'), ('SV', 'Start validation'), ('FV', 'Finalize validation'), ('CUG', 'Change user groups'), ('MID', 'Identify documents to migrate'), ('MSF', 'Start migration by id file'), ('MSD', 'Start migration by ISIS database'), ('MAC', 'Start migration by acronym'), ('MVY', 'Start migration by volume or year')], max_length=3)),
('status', models.CharField(choices=[('I', 'Initiated'), ('C', 'Completed'), ('F', 'Failed')], max_length=1)),
('annotation', models.CharField(max_length=200, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
]
15 changes: 13 additions & 2 deletions app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ class Status(models.TextChoices):
status = models.CharField(max_length=1, choices=Status.choices, blank=False, null=False)


class MigratePackage(models.Model):
...
class MigrationPackage(models.Model):
class Status(models.TextChoices):
RECEIVED = 'R', _('Received')

user = models.ForeignKey(User, on_delete=models.PROTECT)
path = models.CharField(max_length=200)
datetime = models.DateTimeField(null=True)
status = models.CharField(max_length=1, choices=Status.choices, blank=False, null=False)


class Event(models.Model):
Expand All @@ -41,6 +47,11 @@ class Name(models.TextChoices):
START_VALIDATION = 'SV', _('Start validation')
FINALIZE_VALIDATION = 'FV', _('Finalize validation')
CHANGE_USER_GROUPS = 'CUG', _('Change user groups')
IDENTIFY_DOCUMENTS_TO_MIGRATE = 'MID', _('Identify documents to migrate')
START_MIGRATION_BY_ID_FILE = 'MSF', _('Start migration by id file')
START_MIGRATION_BY_ISIS_DB = 'MSD', _('Start migration by ISIS database')
START_MIGRATION_BY_ACRONYM = 'MAC', _('Start migration by acronym')
START_MIGRATION_BY_AVY = 'MVY', _('Start migration by volume or year')

# quem realiza o evento
user = models.ForeignKey(User, on_delete=models.PROTECT)
Expand Down
32 changes: 32 additions & 0 deletions app/core/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,35 @@
.is-no-rounded {
border-radius: 0;
}

.strike {
display: block;
text-align: center;
overflow: hidden;
white-space: nowrap;
}

.strike > span {
position: relative;
display: inline-block;
}

.strike > span:before,
.strike > span:after {
content: "";
position: absolute;
top: 50%;
width: 9999px;
height: 1px;
background: rgba(0,0,0,.125);
}

.strike > span:before {
right: 100%;
margin-right: 15px;
}

.strike > span:after {
left: 100%;
margin-left: 15px;
}
6 changes: 6 additions & 0 deletions app/core/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ function hideLoader(loader, button){
loader.style.display = 'none';
button.removeAttribute('disabled');
}

function setEventStatusCompleted(object){
object.innerHTML = gettext('Completed');
object.classList.remove('bg-warning');
object.classList.add('bg-success');
}
Loading

0 comments on commit 346ea9c

Please sign in to comment.