Skip to content

Commit 39e3c24

Browse files
authored
Django config + Initial SchemaLedger model (#2)
initial django app setup; added schemaledger model
1 parent a4d79a5 commit 39e3c24

File tree

158 files changed

+30811
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+30811
-0
lines changed

Diff for: .gitignore

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/django,python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=django,python
4+
5+
### Django ###
6+
*.log
7+
*.pot
8+
*.pyc
9+
__pycache__/
10+
local_settings.py
11+
db.sqlite3
12+
db.sqlite3-journal
13+
media
14+
15+
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
16+
# in your Git repository. Update and uncomment the following line accordingly.
17+
# <django-project-name>/staticfiles/
18+
19+
### Django.Python Stack ###
20+
# Byte-compiled / optimized / DLL files
21+
*.py[cod]
22+
*$py.class
23+
24+
# C extensions
25+
*.so
26+
27+
# Distribution / packaging
28+
.Python
29+
build/
30+
develop-eggs/
31+
dist/
32+
downloads/
33+
eggs/
34+
.eggs/
35+
lib/
36+
lib64/
37+
parts/
38+
sdist/
39+
var/
40+
wheels/
41+
pip-wheel-metadata/
42+
share/python-wheels/
43+
*.egg-info/
44+
.installed.cfg
45+
*.egg
46+
MANIFEST
47+
48+
# PyInstaller
49+
# Usually these files are written by a python script from a template
50+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
51+
*.manifest
52+
*.spec
53+
54+
# Installer logs
55+
pip-log.txt
56+
pip-delete-this-directory.txt
57+
58+
# Unit test / coverage reports
59+
htmlcov/
60+
.tox/
61+
.nox/
62+
.coverage
63+
.coverage.*
64+
.cache
65+
nosetests.xml
66+
coverage.xml
67+
*.cover
68+
*.py,cover
69+
.hypothesis/
70+
.pytest_cache/
71+
pytestdebug.log
72+
73+
# Translations
74+
*.mo
75+
76+
# Django stuff:
77+
78+
# Flask stuff:
79+
instance/
80+
.webassets-cache
81+
82+
# Scrapy stuff:
83+
.scrapy
84+
85+
# Sphinx documentation
86+
docs/_build/
87+
doc/_build/
88+
89+
# PyBuilder
90+
target/
91+
92+
# Jupyter Notebook
93+
.ipynb_checkpoints
94+
95+
# IPython
96+
profile_default/
97+
ipython_config.py
98+
99+
# pyenv
100+
.python-version
101+
102+
# pipenv
103+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
104+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
105+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
106+
# install all needed dependencies.
107+
#Pipfile.lock
108+
109+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
110+
__pypackages__/
111+
112+
# Celery stuff
113+
celerybeat-schedule
114+
celerybeat.pid
115+
116+
# SageMath parsed files
117+
*.sage.py
118+
119+
# Environments
120+
.env
121+
.venv
122+
env/
123+
venv/
124+
ENV/
125+
env.bak/
126+
venv.bak/
127+
pythonenv*
128+
129+
# Spyder project settings
130+
.spyderproject
131+
.spyproject
132+
133+
# Rope project settings
134+
.ropeproject
135+
136+
# mkdocs documentation
137+
/site
138+
139+
# mypy
140+
.mypy_cache/
141+
.dmypy.json
142+
dmypy.json
143+
144+
# Pyre type checker
145+
.pyre/
146+
147+
# pytype static type analyzer
148+
.pytype/
149+
150+
# profiling data
151+
.prof
152+
153+
### Python ###
154+
# Byte-compiled / optimized / DLL files
155+
156+
# C extensions
157+
158+
# Distribution / packaging
159+
160+
# PyInstaller
161+
# Usually these files are written by a python script from a template
162+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
163+
164+
# Installer logs
165+
166+
# Unit test / coverage reports
167+
168+
# Translations
169+
170+
# Django stuff:
171+
172+
# Flask stuff:
173+
174+
# Scrapy stuff:
175+
176+
# Sphinx documentation
177+
178+
# PyBuilder
179+
180+
# Jupyter Notebook
181+
182+
# IPython
183+
184+
# pyenv
185+
186+
# pipenv
187+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
188+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
189+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
190+
# install all needed dependencies.
191+
192+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
193+
194+
# Celery stuff
195+
196+
# SageMath parsed files
197+
198+
# Environments
199+
200+
# Spyder project settings
201+
202+
# Rope project settings
203+
204+
# mkdocs documentation
205+
206+
# mypy
207+
208+
# Pyre type checker
209+
210+
# pytype static type analyzer
211+
212+
# profiling data
213+
214+
# End of https://www.toptal.com/developers/gitignore/api/django,python
215+
216+
.idea/
217+
.vscode/

Diff for: Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Dockerfile
2+
3+
FROM python:3.7-buster
4+
5+
# install nginx
6+
RUN apt-get update && apt-get install nginx vim -y --no-install-recommends
7+
COPY nginx.default /etc/nginx/sites-available/default
8+
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
9+
&& ln -sf /dev/stderr /var/log/nginx/error.log
10+
11+
# copy source and install dependencies
12+
RUN mkdir -p /opt/app
13+
RUN mkdir -p /opt/app/pip_cache
14+
RUN mkdir -p /opt/app/openlxp-xss
15+
COPY requirements.txt start-server.sh start-app.sh /opt/app/
16+
RUN chmod +x /opt/app/start-server.sh
17+
RUN chmod +x /opt/app/start-app.sh
18+
COPY ./app /opt/app/openlxp-xss/
19+
WORKDIR /opt/app
20+
RUN pip install -r requirements.txt --cache-dir /opt/app/pip_cache
21+
RUN chown -R www-data:www-data /opt/app
22+
WORKDIR /opt/app/openlxp-xss/
23+
24+
# start server
25+
EXPOSE 8020
26+
STOPSIGNAL SIGTERM

Diff for: app/.flake8

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
exclude =
3+
migrations
4+
__pycache__,
5+
manage.py,
6+
settings.py

Diff for: app/core/__init__.py

Whitespace-only changes.

Diff for: app/core/admin.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.contrib import admin
2+
3+
from core.models import SchemaLedger
4+
5+
6+
# Register your models here.
7+
@admin.register(SchemaLedger)
8+
class SchemaLedgerAdmin(admin.ModelAdmin):
9+
list_display = ('id', 'schema_name', 'schema_iri', 'status', )

Diff for: app/core/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CoreConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'core'

Diff for: app/core/management/__init__.py

Whitespace-only changes.

Diff for: app/core/management/commands/__init__.py

Whitespace-only changes.

Diff for: app/core/management/commands/waitdb.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import time
2+
3+
from django.core.management.base import BaseCommand
4+
from django.db import connection
5+
from django.db.utils import OperationalError
6+
from django.utils.translation import ngettext
7+
8+
9+
class Command(BaseCommand):
10+
"""This command waits on for the database to be ready before proceeding"""
11+
12+
def handle(self, *args, **options):
13+
wait = 2
14+
15+
while True:
16+
try:
17+
connection.ensure_connection()
18+
break
19+
except OperationalError:
20+
plural_time = ngettext("second", "seconds", wait)
21+
self.stdout.write(
22+
self.style.WARNING(
23+
f"Database unavailable, retrying after {wait} "
24+
f"{plural_time}! "
25+
)
26+
)
27+
time.sleep(wait)
28+
self.stdout.write(
29+
self.style.SUCCESS("Database connections successful"))

Diff for: app/core/migrations/0001_initial.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 3.1.10 on 2021-05-11 22:22
2+
3+
import django.utils.timezone
4+
import model_utils.fields
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='SchemaLedger',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
21+
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
22+
('schema_name', models.CharField(max_length=255)),
23+
('schema_iri', models.CharField(max_length=255)),
24+
('schema_metadata', models.FileField(upload_to='schemas/')),
25+
('status', models.CharField(max_length=50)),
26+
],
27+
options={
28+
'abstract': False,
29+
},
30+
),
31+
]

Diff for: app/core/migrations/__init__.py

Whitespace-only changes.

Diff for: app/core/models.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.db import models
2+
from model_utils.models import TimeStampedModel
3+
4+
5+
class SchemaLedger(TimeStampedModel):
6+
"""Model for Uploaded Schemas"""
7+
schema_name = models.CharField(max_length=255)
8+
schema_iri = models.CharField(max_length=255)
9+
schema_metadata = models.FileField(upload_to='schemas/')
10+
status = models.CharField(max_length=50)

Diff for: app/core/tests/__init__.py

Whitespace-only changes.

Diff for: app/core/tests/test_models_unit.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.test import SimpleTestCase, tag
2+
3+
from core.models import SchemaLedger
4+
5+
6+
@tag('unit')
7+
class ModelTests(SimpleTestCase):
8+
9+
def test_schema_ledger(self):
10+
"""Test that creating a SchemaLedger is successful"""
11+
schema_name = 'test_name'
12+
schema_iri = 'test_iri'
13+
schema_metadata = 'file.csv'
14+
status = 'PASS'
15+
16+
schema = SchemaLedger(schema_name=schema_name,
17+
schema_iri=schema_iri,
18+
schema_metadata=schema_metadata,
19+
status=status)
20+
21+
self.assertEqual(schema.schema_name, schema_name)
22+
self.assertEqual(schema.schema_iri, schema_iri)
23+
self.assertEqual(schema.status, status)

Diff for: app/core/views.py

Whitespace-only changes.

Diff for: app/manage.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
10+
'openlxp_xss_project.settings')
11+
try:
12+
from django.core.management import execute_from_command_line
13+
except ImportError as exc:
14+
raise ImportError(
15+
"Couldn't import Django. Are you sure it's installed and "
16+
"available on your PYTHONPATH environment variable? Did you "
17+
"forget to activate a virtual environment?"
18+
) from exc
19+
execute_from_command_line(sys.argv)
20+
21+
22+
if __name__ == '__main__':
23+
main()

Diff for: app/openlxp_xss_project/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)