Added back-end prototype
This commit is contained in:
parent
cc69fc425d
commit
0931fe73fa
6
.gitignore
vendored
6
.gitignore
vendored
@ -1 +1,5 @@
|
||||
/frontend/node_modules
|
||||
/frontend/node_modules
|
||||
/backend/webapp/db.sqlite3
|
||||
/backend/webapp/myvenv
|
||||
/backend/webapp/media
|
||||
*__pycache__
|
||||
|
41
backend/webapp/README.md
Normal file
41
backend/webapp/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
## Analiza dyskusji na forum (Development)
|
||||
|
||||
### Wymagania:
|
||||
|
||||
- Python
|
||||
- Django >= 3.0.5
|
||||
|
||||
### Środowisko wirtualne
|
||||
Zaczynamy od stworzenia i uruchomienia środowiska wirtualnego, przy pomocy poleceń:
|
||||
```bash
|
||||
$ python3 -m venv myvenv
|
||||
$ source myvenv/bin/activate
|
||||
```
|
||||
Powinniśmy ujrzeć (myvenv) poprzedzające nasza nazwę użytkownika w wierszu poleceń.
|
||||
|
||||
### Instalacja Django
|
||||
Pierwszym krokiem będzie zaktualizowanie menedżera pakietów języka Python:
|
||||
```bash
|
||||
$ python3 -m pip install --upgrade pip
|
||||
```
|
||||
Instalujemy pakietu Django przy pomocy listy wymagań:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Uruchomienie
|
||||
|
||||
Aby uruchomić wersję prototyp aplikacji, w pierwszej kolejności należy zainicjalizować bazę danych:
|
||||
```bash
|
||||
$ python manage.py migrate --run-syncdb
|
||||
```
|
||||
Następnie uruchamiamy serwer WWW:
|
||||
```bash
|
||||
$ python manage.py runserver
|
||||
```
|
||||
Aplikacja dostępna jest pod adresem `127.0.0.1:8000`
|
||||
Aby zakończyć działanie serwera, korzystamy w kombinacji klawiszy CTRL + C w terminalu, w którym uruchomiliśmy usługę.
|
||||
|
||||
Aby opuścić środowisko wirtualne, korzytamy z polecenia `deactivate`.
|
||||
|
||||
|
21
backend/webapp/manage.py
Executable file
21
backend/webapp/manage.py
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'prototype.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
0
backend/webapp/prototype/__init__.py
Normal file
0
backend/webapp/prototype/__init__.py
Normal file
16
backend/webapp/prototype/asgi.py
Normal file
16
backend/webapp/prototype/asgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for prototype project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'prototype.settings')
|
||||
|
||||
application = get_asgi_application()
|
0
backend/webapp/prototype/filehandler/__init__.py
Normal file
0
backend/webapp/prototype/filehandler/__init__.py
Normal file
6
backend/webapp/prototype/filehandler/apps.py
Normal file
6
backend/webapp/prototype/filehandler/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = 'filehandler'
|
7
backend/webapp/prototype/filehandler/forms.py
Normal file
7
backend/webapp/prototype/filehandler/forms.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django import forms
|
||||
from prototype.filehandler.models import Document
|
||||
|
||||
class DocumentForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Document
|
||||
fields = ('description', 'document', )
|
7
backend/webapp/prototype/filehandler/models.py
Normal file
7
backend/webapp/prototype/filehandler/models.py
Normal file
@ -0,0 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
from django.db import models
|
||||
|
||||
class Document(models.Model):
|
||||
description = models.CharField(max_length=255, blank=True)
|
||||
document = models.FileField(upload_to='documents/')
|
||||
uploaded_at = models.DateTimeField(auto_now_add=True)
|
@ -0,0 +1,19 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<ul>
|
||||
<li>
|
||||
<a href="{% url 'model_form_upload' %}">Moduł wysyłania pliku</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>Wysłane pliki:</p>
|
||||
<ul>
|
||||
{% for obj in documents %}
|
||||
<li>
|
||||
<a href="{{ obj.document.url }}">{{ obj.document.name }}</a>
|
||||
<small>(Wysłane: {{ obj.uploaded_at }}</small>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Wyślij</button>
|
||||
</form>
|
||||
|
||||
<p><a href="{% url 'home' %}">Powrót do strony głównej</a></p>
|
||||
{% endblock %}
|
22
backend/webapp/prototype/filehandler/views.py
Normal file
22
backend/webapp/prototype/filehandler/views.py
Normal file
@ -0,0 +1,22 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
|
||||
from prototype.filehandler.models import Document
|
||||
from prototype.filehandler.forms import DocumentForm
|
||||
|
||||
def home(request):
|
||||
documents = Document.objects.all()
|
||||
return render(request, 'core/home.html', { 'documents': documents})
|
||||
|
||||
def model_form_upload(request):
|
||||
if request.method == 'POST':
|
||||
form = DocumentForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('home')
|
||||
else:
|
||||
form = DocumentForm()
|
||||
return render(request, 'core/model_form_upload.html', {
|
||||
'form' : form
|
||||
})
|
127
backend/webapp/prototype/settings.py
Normal file
127
backend/webapp/prototype/settings.py
Normal file
@ -0,0 +1,127 @@
|
||||
"""
|
||||
Django settings for prototype project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.0.5.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.0/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'l@x1!0zws!($=!tz4n5f^p4z8o1j!r0wn8nz(jzg-k3i%b6(37'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ['127.0.0.1']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
'prototype.filehandler',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'prototype.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, 'prototype/templates')],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'django.template.context_processors.media',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'prototype.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'pl-pl'
|
||||
|
||||
TIME_ZONE = 'Europe/Warsaw'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
|
||||
MEDIA_URL = '/media/'
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
12
backend/webapp/prototype/templates/base.html
Normal file
12
backend/webapp/prototype/templates/base.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Prosty moduł przesyłania plików</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
30
backend/webapp/prototype/urls.py
Normal file
30
backend/webapp/prototype/urls.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""prototype URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
|
||||
from prototype.filehandler import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('prototype/form/', views.model_form_upload, name='model_form_upload'),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
16
backend/webapp/prototype/wsgi.py
Normal file
16
backend/webapp/prototype/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for prototype project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'prototype.settings')
|
||||
|
||||
application = get_wsgi_application()
|
1
backend/webapp/requirements.txt
Normal file
1
backend/webapp/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
Django~=3.0.5
|
Loading…
Reference in New Issue
Block a user