Browse Source

first commit

master
Jakub Škrabánek 3 years ago
parent
commit
8e954b5c06
  1. 208
      .gitignore
  2. 6
      djangoform/.idea/inspectionProfiles/profiles_settings.xml
  3. 7
      djangoform/.idea/misc.xml
  4. 48
      djangoform/.idea/workspace.xml
  5. 124
      djangoform/README.md
  6. 0
      djangoform/form/__init__.py
  7. 5
      djangoform/form/admin.py
  8. 6
      djangoform/form/apps.py
  9. 7
      djangoform/form/forms.py
  10. 22
      djangoform/form/migrations/0001_initial.py
  11. 0
      djangoform/form/migrations/__init__.py
  12. 9
      djangoform/form/models.py
  13. 18
      djangoform/form/templates/index.html
  14. 3
      djangoform/form/tests.py
  15. 12
      djangoform/form/views.py
  16. 0
      djangoform/formfaktor/__init__.py
  17. 16
      djangoform/formfaktor/asgi.py
  18. 127
      djangoform/formfaktor/settings.py
  19. 23
      djangoform/formfaktor/urls.py
  20. 16
      djangoform/formfaktor/wsgi.py
  21. 22
      djangoform/manage.py

208
.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

6
djangoform/.idea/inspectionProfiles/profiles_settings.xml

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
djangoform/.idea/misc.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (djangoform)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

48
djangoform/.idea/workspace.xml

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="6e19fe3c-b9b4-41d7-b98b-ed92f721a48d" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
<option value="HTML File" />
</list>
</option>
</component>
<component name="ProjectId" id="25Y2DzcLozOHMogtM9JUyR5oFMf" />
<component name="PropertiesComponent">
<property name="DefaultHtmlFileTemplate" value="HTML File" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="6e19fe3c-b9b4-41d7-b98b-ed92f721a48d" name="Default Changelist" comment="" />
<created>1645689583524</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1645689583524</updated>
</task>
<servers />
</component>
</project>

124
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
<h1>Feedback formular</h1>
<form action="" method="post">
{% csrf_token %}
{{form}}
<input type="submit">
</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)

0
djangoform/form/__init__.py

5
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)

6
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'

7
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__'

22
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)),
],
),
]

0
djangoform/form/migrations/__init__.py

9
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

18
djangoform/form/templates/index.html

@ -0,0 +1,18 @@
{% load crispy_forms_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FormApp</title>
</head>
<body>
<h1>Feedback formular</h1>
<form action="" method="post">
{% csrf_token %}
{{form | crispy}}
<input type="submit">
</form>
</body>
</html>

3
djangoform/form/tests.py

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

12
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)

0
djangoform/formfaktor/__init__.py

16
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()

127
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'

23
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),
]

16
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()

22
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()
Loading…
Cancel
Save