Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
python-version: 3.9
architecture: x64
- run: pip install -e .[dev]
- run: isort --check-only libfjordweb setup.py
- run: black --check libfjordweb setup.py
- run: flake8 libfjordweb setup.py
- run: isort --check-only libfjordweb fjorddemo setup.py
- run: black --check libfjordweb fjorddemo setup.py
- run: flake8 libfjordweb fjorddemo setup.py
- run: mypy --install-types --non-interactive -p libfjordweb
- run: mypy --install-types --non-interactive -p fjorddemo
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM python:3.9

CMD [ "/bin/bash", "-c", "--", "while true; do sleep 30; done;" ]

37 changes: 37 additions & 0 deletions docs/develop.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Develop this library
====================

The git repository comes with a dev container and a sample Django app to see the library running and help you develop it.


To set up, run the dev container and:

.. code-block::

pip install -e .[dev]
python manage.py migrate


To run the web server in one terminal:

.. code-block::

python manage.py runserver 0.0.0.0:8000

Open another terminal, and run the worker:

.. code-block::

celery -A libfjordweb.celery worker -l debug -c 1


To lint code:

.. code-block::

isort libfjordweb fjorddemo setup.py
black libfjordweb fjorddemo setup.py
flake8 libfjordweb fjorddemo setup.py
mypy --install-types --non-interactive -p libfjordweb
mypy --install-types --non-interactive -p fjorddemo

1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ The application consists of:
migration-from-lib-cove-web.rst
hosting/index.rst
used-by.rst
develop.rst

Empty file added fjorddemo/__init__.py
Empty file.
Empty file added fjorddemo/app/__init__.py
Empty file.
Empty file added fjorddemo/app/admin.py
Empty file.
5 changes: 5 additions & 0 deletions fjorddemo/app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class FjordDemoAppConfig(AppConfig):
name = "fjorddemo.app"
27 changes: 27 additions & 0 deletions fjorddemo/app/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django import forms
from django.conf import settings


class NewJSONUploadForm(forms.Form):
file_field_names = ["file_upload"]
file_upload = forms.FileField(
widget=forms.FileInput(
attrs={
"accept": ",".join(
settings.ALLOWED_JSON_CONTENT_TYPES
+ settings.ALLOWED_JSON_EXTENSIONS
)
}
),
label="",
)


class NewJSONTextForm(forms.Form):
file_field_names: list = []
paste = forms.CharField(label="Paste (JSON only)", widget=forms.Textarea)


class NewJSONURLForm(forms.Form):
file_field_names: list = []
url = forms.URLField(label="URL")
Empty file.
Empty file added fjorddemo/app/models.py
Empty file.
25 changes: 25 additions & 0 deletions fjorddemo/app/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os

from libfjordweb.process.common_tasks.task_with_state import TaskWithState


class DetailsOnJSON(TaskWithState):
""""""

state_filename: str = "details_on_json.json"

def process_get_state(self, process_data: dict):

out: dict = {}

supplied_data_json_files = [
i for i in self.supplied_data_files if i.content_type == "application/json"
]
if len(supplied_data_json_files) == 1:
out["data_size"] = os.path.getsize(
supplied_data_json_files[0].upload_dir_and_filename()
)
else:
raise Exception("Can't find JSON original data!")

return out, process_data
36 changes: 36 additions & 0 deletions fjorddemo/app/templates/fjorddemo/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends 'libfjordweb/base.html' %}
{% load i18n %}
{% load static %}

{% block after_head %}
{% endblock %}

{% block banner %}
{% endblock %}

{% block page_header %}
{% endblock %}

{% block full_width_header %}

<h1>Lib Fjord Web Demo App</h1>

{% endblock %}

{% block link %}
{% endblock %}

{% block bottomcontent1 %}
{% endblock %}

{% block topcontent1 %}
{% endblock %}

{% block bottomcontent3 %}
{% endblock %}

{% block about %}
{% endblock %}

{% block version_link %}
{% endblock %}
7 changes: 7 additions & 0 deletions fjorddemo/app/templates/fjorddemo/explore.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends request.current_app_base_template %}

{% block content %}

<p>The data you uploaded is {{ data_size }} size.</p>

{% endblock %}
29 changes: 29 additions & 0 deletions fjorddemo/app/templates/fjorddemo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends request.current_app_base_template %}

{% block content %}

<h2>Upload</h2>

<form method="POST" action="{% url 'new_json' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ forms.json.upload_form }}
<button type="submit">Submit</button>
</form>

<h2>Enter Directly</h2>

<form method="POST" action="{% url 'new_json' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ forms.json.text_form }}
<button type="submit">Submit</button>
</form>

<h2>URL</h2>

<form method="POST" action="{% url 'new_json' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ forms.json.url_form }}
<button type="submit">Submit</button>
</form>

{% endblock %}
84 changes: 84 additions & 0 deletions fjorddemo/app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import logging

from django.conf import settings
from django.shortcuts import render

from fjorddemo.app.forms import (
NewJSONTextForm,
NewJSONUploadForm,
NewJSONURLForm,
)
from libfjordweb.models import SuppliedDataFile
from libfjordweb.views import ExploreDataView, InputDataView

logger = logging.getLogger(__name__)


def index(request):
forms = {
"json": {
form_name: form_class()
for form_name, form_class in JSON_FORM_CLASSES.items()
},
}

return render(request, "fjorddemo/index.html", {"forms": forms})


JSON_FORM_CLASSES: dict = {
"upload_form": NewJSONUploadForm,
"text_form": NewJSONTextForm,
"url_form": NewJSONURLForm,
}


class NewJSONInput(InputDataView):
form_classes: dict = JSON_FORM_CLASSES # type: ignore
input_template = "fjorddemo/index.html" # type: ignore
allowed_content_types = settings.ALLOWED_JSON_CONTENT_TYPES
content_type_incorrect_message = "This does not appear to be a JSON file."
allowed_file_extensions = settings.ALLOWED_JSON_EXTENSIONS
file_extension_incorrect_message = "This does not appear to be a JSON file."
supplied_data_format = "json" # type: ignore

def get_active_form_key(self, forms, request_data):
if "paste" in request_data:
return "text_form"
elif "url" in request_data:
return "url_form"
else:
return "upload_form"

def save_file_content_to_supplied_data(
self, form_name, form, request, supplied_data
):
if form_name == "upload_form":
supplied_data.save_file(request.FILES["file_upload"])
elif form_name == "text_form":
supplied_data.save_file_contents(
"input.json",
form.cleaned_data["paste"],
"application/json",
None,
)
elif form_name == "url_form":
supplied_data.save_file_from_source_url(
form.cleaned_data["url"], content_type="application/json"
)


class ExploreView(ExploreDataView):
explore_template = "fjorddemo/explore.html" # type: ignore

def default_explore_context(self, supplied_data):
return {
# Misc
"supplied_data_files": SuppliedDataFile.objects.filter(
supplied_data=supplied_data
),
"created_datetime": supplied_data.created.strftime(
"%A, %d %B %Y %I:%M%p %Z"
),
"created_date": supplied_data.created.strftime("%A, %d %B %Y"),
"created_time": supplied_data.created.strftime("%I:%M%p %Z"),
}
Loading