From 8e954b5c06f5a96df25bf3799ead29e47129343d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=A0krab=C3=A1nek?= Date: Thu, 24 Feb 2022 11:12:54 +0100 Subject: [PATCH] first commit --- .gitignore | 208 +++++++++++++++++- .../inspectionProfiles/profiles_settings.xml | 6 + djangoform/.idea/misc.xml | 7 + djangoform/.idea/workspace.xml | 48 ++++ djangoform/README.md | 124 +++++++++++ djangoform/form/__init__.py | 0 djangoform/form/admin.py | 5 + djangoform/form/apps.py | 6 + djangoform/form/forms.py | 7 + djangoform/form/migrations/0001_initial.py | 22 ++ djangoform/form/migrations/__init__.py | 0 djangoform/form/models.py | 9 + djangoform/form/templates/index.html | 18 ++ djangoform/form/tests.py | 3 + djangoform/form/views.py | 12 + djangoform/formfaktor/__init__.py | 0 djangoform/formfaktor/asgi.py | 16 ++ djangoform/formfaktor/settings.py | 127 +++++++++++ djangoform/formfaktor/urls.py | 23 ++ djangoform/formfaktor/wsgi.py | 16 ++ djangoform/manage.py | 22 ++ 21 files changed, 669 insertions(+), 10 deletions(-) create mode 100644 djangoform/.idea/inspectionProfiles/profiles_settings.xml create mode 100644 djangoform/.idea/misc.xml create mode 100644 djangoform/.idea/workspace.xml create mode 100644 djangoform/README.md create mode 100644 djangoform/form/__init__.py create mode 100644 djangoform/form/admin.py create mode 100644 djangoform/form/apps.py create mode 100644 djangoform/form/forms.py create mode 100644 djangoform/form/migrations/0001_initial.py create mode 100644 djangoform/form/migrations/__init__.py create mode 100644 djangoform/form/models.py create mode 100644 djangoform/form/templates/index.html create mode 100644 djangoform/form/tests.py create mode 100644 djangoform/form/views.py create mode 100644 djangoform/formfaktor/__init__.py create mode 100644 djangoform/formfaktor/asgi.py create mode 100644 djangoform/formfaktor/settings.py create mode 100644 djangoform/formfaktor/urls.py create mode 100644 djangoform/formfaktor/wsgi.py create mode 100644 djangoform/manage.py diff --git a/.gitignore b/.gitignore index 68fd522..70f2392 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,8 @@ -# ---> VisualStudioCode -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace -# Local History for Visual Studio Code -.history/ +# Created by https://www.toptal.com/developers/gitignore/api/pycharm+all,python,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm+all,python,visualstudiocode -# ---> JetBrains +### PyCharm+all ### # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 @@ -73,6 +66,9 @@ atlassian-ide-plugin.xml # Cursive Clojure plugin .idea/replstate.xml +# SonarLint plugin +.idea/sonarlint/ + # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties @@ -85,3 +81,195 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +### PyCharm+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/* + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope + +# End of https://www.toptal.com/developers/gitignore/api/pycharm+all,python,visualstudiocode \ No newline at end of file diff --git a/djangoform/.idea/inspectionProfiles/profiles_settings.xml b/djangoform/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/djangoform/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/djangoform/.idea/misc.xml b/djangoform/.idea/misc.xml new file mode 100644 index 0000000..cecd743 --- /dev/null +++ b/djangoform/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/djangoform/.idea/workspace.xml b/djangoform/.idea/workspace.xml new file mode 100644 index 0000000..c0cc2c7 --- /dev/null +++ b/djangoform/.idea/workspace.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + 1645689583524 + + + + \ No newline at end of file diff --git a/djangoform/README.md b/djangoform/README.md new file mode 100644 index 0000000..d053cc3 --- /dev/null +++ b/djangoform/README.md @@ -0,0 +1,124 @@ +# Django formuláře + +Nejprve si zjistíme, jestli jsme ve virtualním prostředí pro python +> *(venv) C:\pythonProjects\Django :* - ukazka cmd prostředí + +Můžeme pokračovat: +1. vytvoření virtualního prostředi + +> python -m venv .venv + + +2. Aktivace virtuálního prostředí + +> .venv\Scripts\activate.bat + + +3. Instalace frameworku Django + +> (.venv) pip install Django + + + +4. Založení Django projektu + +> (.venv) django-admin startproject **název_projektu** . + +Nezapomenout na TEČKU na konci příkazu (jinak to bude složitější složkování) + +5. Založení Django aplikace + +> (.venv) python manage.py startapp **název_aplikace** + +a následné přidání **název_aplikace** do *název_projektu/settings.py* do kolonky INSTALLED_APPS + +6. vytvoření základního modelu v *název_projektu/models.py* + +```python +from django.db import models + + +class feedbackModel(models.Model): + nazev = models.CharField(max_length=100) + zprava = models.TextField(max_length=10000) + + def __str__(self): + return self.nazev + " " + self.zprava +``` + +7. vytvoření souboru **forms.py** ve složce *název_aplikace* +8. Přídání IndexView do *nazev_projektu/urls.py* a *název_aplikace/views.py* + +urls.py -> přídáme jen to, co je ve "** **" +```python +from django.contrib import admin +from django.urls import path +**from form.views import indexView** + +urlpatterns = [ + path('admin/', admin.site.urls), + **path('',indexView),** +] +``` + +views.py +```python +from django.shortcuts import render +from .forms import feedbackForm + +def indexView(request): + form = feedbackForm + if request.method == "POST": + #print(request.POST) #potrebuju zkontrolovani + form = feedbackForm(request.POST) + if form.is_valid(): + form.save() + context = {'form':form} + return render(request,"index.html", context) +``` + +9. vytvoříme složku *templates* v složce s aplikaci a vytvoříme ve složce jestě soubor *index.html* + +```html +

Feedback formular

+ +
+ {% csrf_token %} + {{form}} + +
+``` +10. Přidat model do admin.py +```python +from django.contrib import admin +from .models import feedbackModel + +admin.site.register(feedbackModel) +``` + +11. zkontrolujeme databázi (migrujeme) a vytvoříme si SuperUser + +> manage.py makemigrations + +> manage.py migrate + +> manage.py createsuperuser + +12. HOTOVO - vložíme nějaké texty a zkontrolujeme admin panel + +Postup pro hezčí formulář + +1. nainstalovat crispy_forms +> (.venv) pip install django-crispy-forms + +2. vložit na začátek souboru index.html + +`{% load crispy_forms_tags %}` + +3. upravit v index.html + +`{{form}}` na `{{form | crispy}}` + + +### postup při importu +(Work in progress) \ No newline at end of file diff --git a/djangoform/form/__init__.py b/djangoform/form/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoform/form/admin.py b/djangoform/form/admin.py new file mode 100644 index 0000000..a0432fd --- /dev/null +++ b/djangoform/form/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import feedbackModel +# Register your models here. + +admin.site.register(feedbackModel) \ No newline at end of file diff --git a/djangoform/form/apps.py b/djangoform/form/apps.py new file mode 100644 index 0000000..d94fe57 --- /dev/null +++ b/djangoform/form/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class FormConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'form' diff --git a/djangoform/form/forms.py b/djangoform/form/forms.py new file mode 100644 index 0000000..ee4e7d6 --- /dev/null +++ b/djangoform/form/forms.py @@ -0,0 +1,7 @@ +from django.forms import ModelForm +from .models import feedbackModel + +class feedbackForm(ModelForm): + class Meta: + model = feedbackModel + fields = '__all__' \ No newline at end of file diff --git a/djangoform/form/migrations/0001_initial.py b/djangoform/form/migrations/0001_initial.py new file mode 100644 index 0000000..1c94a10 --- /dev/null +++ b/djangoform/form/migrations/0001_initial.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.12 on 2022-02-24 09:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='feedbackModel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nazev', models.CharField(max_length=100)), + ('zprava', models.TextField(max_length=10000)), + ], + ), + ] diff --git a/djangoform/form/migrations/__init__.py b/djangoform/form/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoform/form/models.py b/djangoform/form/models.py new file mode 100644 index 0000000..c852e30 --- /dev/null +++ b/djangoform/form/models.py @@ -0,0 +1,9 @@ +from django.db import models + + +class feedbackModel(models.Model): + nazev = models.CharField(max_length=100) + zprava = models.TextField(max_length=10000) + + def __str__(self): + return self.nazev + " " + self.zprava \ No newline at end of file diff --git a/djangoform/form/templates/index.html b/djangoform/form/templates/index.html new file mode 100644 index 0000000..07b01e4 --- /dev/null +++ b/djangoform/form/templates/index.html @@ -0,0 +1,18 @@ +{% load crispy_forms_tags %} + + + + + FormApp + + +

Feedback formular

+ +
+ {% csrf_token %} + {{form | crispy}} + +
+ + + \ No newline at end of file diff --git a/djangoform/form/tests.py b/djangoform/form/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/djangoform/form/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/djangoform/form/views.py b/djangoform/form/views.py new file mode 100644 index 0000000..80200a7 --- /dev/null +++ b/djangoform/form/views.py @@ -0,0 +1,12 @@ +from django.shortcuts import render +from .forms import feedbackForm + +def indexView(request): + form = feedbackForm + if request.method == "POST": + #print(request.POST) #potrebuju zkontrolovani + form = feedbackForm(request.POST) + if form.is_valid(): + form.save() + context = {'form':form} + return render(request,"index.html", context) \ No newline at end of file diff --git a/djangoform/formfaktor/__init__.py b/djangoform/formfaktor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/djangoform/formfaktor/asgi.py b/djangoform/formfaktor/asgi.py new file mode 100644 index 0000000..56eb521 --- /dev/null +++ b/djangoform/formfaktor/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for formfaktor 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.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'formfaktor.settings') + +application = get_asgi_application() diff --git a/djangoform/formfaktor/settings.py b/djangoform/formfaktor/settings.py new file mode 100644 index 0000000..ebbfc0e --- /dev/null +++ b/djangoform/formfaktor/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for formfaktor project. + +Generated by 'django-admin startproject' using Django 3.2.12. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-vzeltdpib@4scr8e8u24^dv$+se-gs(-=)+v%p!iaa%ajg_*0y' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'form', + 'crispy_forms', +] + +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 = 'formfaktor.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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', + ], + }, + }, +] + +WSGI_APPLICATION = 'formfaktor.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/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.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/djangoform/formfaktor/urls.py b/djangoform/formfaktor/urls.py new file mode 100644 index 0000000..abdd018 --- /dev/null +++ b/djangoform/formfaktor/urls.py @@ -0,0 +1,23 @@ +"""formfaktor URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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 form.views import indexView + +urlpatterns = [ + path('admin/', admin.site.urls), + path('',indexView), +] diff --git a/djangoform/formfaktor/wsgi.py b/djangoform/formfaktor/wsgi.py new file mode 100644 index 0000000..4da08a5 --- /dev/null +++ b/djangoform/formfaktor/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for formfaktor 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.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'formfaktor.settings') + +application = get_wsgi_application() diff --git a/djangoform/manage.py b/djangoform/manage.py new file mode 100644 index 0000000..e0299f7 --- /dev/null +++ b/djangoform/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'formfaktor.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()