| @ -0,0 +1,116 @@ | |||||
| # Django # | |||||
| *.log | |||||
| *.pot | |||||
| *.pyc | |||||
| __pycache__ | |||||
| db.sqlite3 | |||||
| media | |||||
| # Backup files # | |||||
| *.bak | |||||
| # If you are using PyCharm # | |||||
| .idea/**/workspace.xml | |||||
| .idea/**/tasks.xml | |||||
| .idea/dictionaries | |||||
| .idea/**/dataSources/ | |||||
| .idea/**/dataSources.ids | |||||
| .idea/**/dataSources.xml | |||||
| .idea/**/dataSources.local.xml | |||||
| .idea/**/sqlDataSources.xml | |||||
| .idea/**/dynamic.xml | |||||
| .idea/**/uiDesigner.xml | |||||
| .idea/**/gradle.xml | |||||
| .idea/**/libraries | |||||
| *.iws /out/ | |||||
| # Python # | |||||
| *.py[cod] | |||||
| *$py.class | |||||
| # Distribution / packaging | |||||
| .Python build/ | |||||
| develop-eggs/ | |||||
| dist/ | |||||
| downloads/ | |||||
| eggs/ | |||||
| .eggs/ | |||||
| lib/ | |||||
| lib64/ | |||||
| parts/ | |||||
| sdist/ | |||||
| var/ | |||||
| wheels/ | |||||
| *.egg-info/ | |||||
| .installed.cfg | |||||
| *.egg | |||||
| *.manifest | |||||
| *.spec | |||||
| # Installer logs | |||||
| pip-log.txt | |||||
| pip-delete-this-directory.txt | |||||
| # Unit test / coverage reports | |||||
| htmlcov/ | |||||
| .tox/ | |||||
| .coverage | |||||
| .coverage.* | |||||
| .cache | |||||
| .pytest_cache/ | |||||
| nosetests.xml | |||||
| coverage.xml | |||||
| *.cover | |||||
| .hypothesis/ | |||||
| # Jupyter Notebook | |||||
| .ipynb_checkpoints | |||||
| # pyenv | |||||
| .python-version | |||||
| # celery | |||||
| celerybeat-schedule.* | |||||
| # SageMath parsed files | |||||
| *.sage.py | |||||
| # Environments | |||||
| .env | |||||
| .venv | |||||
| env/ | |||||
| venv/ | |||||
| ENV/ | |||||
| env.bak/ | |||||
| venv.bak/ | |||||
| # mkdocs documentation | |||||
| /site | |||||
| # mypy | |||||
| .mypy_cache/ | |||||
| # Sublime Text # | |||||
| *.tmlanguage.cache | |||||
| *.tmPreferences.cache | |||||
| *.stTheme.cache | |||||
| *.sublime-workspace | |||||
| *.sublime-project | |||||
| # sftp configuration file | |||||
| sftp-config.json | |||||
| # Package control specific files Package | |||||
| Control.last-run | |||||
| Control.ca-list | |||||
| Control.ca-bundle | |||||
| Control.system-ca-bundle | |||||
| GitHub.sublime-settings | |||||
| # Visual Studio Code # | |||||
| .vscode/* | |||||
| !.vscode/settings.json | |||||
| !.vscode/tasks.json | |||||
| !.vscode/launch.json | |||||
| !.vscode/extensions.json | |||||
| .history | |||||
| @ -0,0 +1,8 @@ | |||||
| # Default ignored files | |||||
| /shelf/ | |||||
| /workspace.xml | |||||
| # Datasource local storage ignored files | |||||
| /dataSources/ | |||||
| /dataSources.local.xml | |||||
| # Editor-based HTTP Client requests | |||||
| /httpRequests/ | |||||
| @ -0,0 +1,6 @@ | |||||
| <component name="InspectionProjectProfileManager"> | |||||
| <settings> | |||||
| <option name="USE_PROJECT_PROFILE" value="false" /> | |||||
| <version value="1.0" /> | |||||
| </settings> | |||||
| </component> | |||||
| @ -0,0 +1,30 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <module type="PYTHON_MODULE" version="4"> | |||||
| <component name="FacetManager"> | |||||
| <facet type="django" name="Django"> | |||||
| <configuration> | |||||
| <option name="rootFolder" value="$MODULE_DIR$" /> | |||||
| <option name="settingsModule" value="lu_django_1/settings.py" /> | |||||
| <option name="manageScript" value="$MODULE_DIR$/manage.py" /> | |||||
| <option name="environment" value="<map/>" /> | |||||
| <option name="doNotUseTestRunner" value="false" /> | |||||
| <option name="trackFilePattern" value="migrations" /> | |||||
| </configuration> | |||||
| </facet> | |||||
| </component> | |||||
| <component name="NewModuleRootManager"> | |||||
| <content url="file://$MODULE_DIR$"> | |||||
| <excludeFolder url="file://$MODULE_DIR$/venv" /> | |||||
| </content> | |||||
| <orderEntry type="inheritedJdk" /> | |||||
| <orderEntry type="sourceFolder" forTests="false" /> | |||||
| </component> | |||||
| <component name="TemplatesService"> | |||||
| <option name="TEMPLATE_CONFIGURATION" value="Django" /> | |||||
| <option name="TEMPLATE_FOLDERS"> | |||||
| <list> | |||||
| <option value="$MODULE_DIR$/../lu_django_1\templates" /> | |||||
| </list> | |||||
| </option> | |||||
| </component> | |||||
| </module> | |||||
| @ -0,0 +1,4 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project version="4"> | |||||
| <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (lu_django_1)" project-jdk-type="Python SDK" /> | |||||
| </project> | |||||
| @ -0,0 +1,8 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project version="4"> | |||||
| <component name="ProjectModuleManager"> | |||||
| <modules> | |||||
| <module fileurl="file://$PROJECT_DIR$/.idea/lu_django_1.iml" filepath="$PROJECT_DIR$/.idea/lu_django_1.iml" /> | |||||
| </modules> | |||||
| </component> | |||||
| </project> | |||||
| @ -0,0 +1,6 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project version="4"> | |||||
| <component name="VcsDirectoryMappings"> | |||||
| <mapping directory="$PROJECT_DIR$" vcs="Git" /> | |||||
| </component> | |||||
| </project> | |||||
| @ -0,0 +1,16 @@ | |||||
| """ | |||||
| ASGI config for lu_django_1 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', 'lu_django_1.settings') | |||||
| application = get_asgi_application() | |||||
| @ -0,0 +1,130 @@ | |||||
| """ | |||||
| Django settings for lu_django_1 project. | |||||
| Generated by 'django-admin startproject' using Django 3.2.8. | |||||
| 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-hubq#k5jq^veb5@1l=gu!)j7dbv3oi7d6l+!0sei7+q&td4qe2' | |||||
| # SECURITY WARNING: don't run with debug turned on in production! | |||||
| DEBUG = True | |||||
| ALLOWED_HOSTS = [ | |||||
| '91.105.66.240', | |||||
| '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', | |||||
| 'uzdevumi.apps.UzdevumiConfig', | |||||
| ] | |||||
| 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 = 'lu_django_1.urls' | |||||
| TEMPLATES = [ | |||||
| { | |||||
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |||||
| 'DIRS': [BASE_DIR / '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', | |||||
| ], | |||||
| }, | |||||
| }, | |||||
| ] | |||||
| WSGI_APPLICATION = 'lu_django_1.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' | |||||
| @ -0,0 +1,26 @@ | |||||
| """lu_django_1 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 | |||||
| import uzdevumi.views | |||||
| urlpatterns = [ | |||||
| path('admin/', admin.site.urls), | |||||
| path('add-visit', uzdevumi.views.add_visit), | |||||
| path('visit/<int:visit_id>', uzdevumi.views.get_visit, name='get-visit'), | |||||
| path('', uzdevumi.views.get_all_visits), | |||||
| ] | |||||
| @ -0,0 +1,16 @@ | |||||
| """ | |||||
| WSGI config for lu_django_1 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', 'lu_django_1.settings') | |||||
| application = get_wsgi_application() | |||||
| @ -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', 'lu_django_1.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,0 +1,14 @@ | |||||
| <!DOCTYPE html> | |||||
| <html lang="en"> | |||||
| <head> | |||||
| <meta charset="UTF-8"> | |||||
| <title>{{ visitor }}'s visit</title> | |||||
| </head> | |||||
| <body> | |||||
| <p> | |||||
| <strong>{{ visit.visitor }} will arrive at {{ visit.date_time }}</strong><br> | |||||
| Reason: {{ visit.reason }} | |||||
| </p> | |||||
| </body> | |||||
| </html> | |||||
| @ -0,0 +1,14 @@ | |||||
| <!DOCTYPE html> | |||||
| <html lang="en"> | |||||
| <head> | |||||
| <meta charset="UTF-8"> | |||||
| <title>New visit</title> | |||||
| </head> | |||||
| <body> | |||||
| <form action="" method="post"> | |||||
| {% csrf_token %} | |||||
| {{ form.as_p }} | |||||
| <input type="submit"> | |||||
| </form> | |||||
| </body> | |||||
| </html> | |||||
| @ -0,0 +1,20 @@ | |||||
| <!DOCTYPE html> | |||||
| <html lang="en"> | |||||
| <head> | |||||
| <meta charset="UTF-8"> | |||||
| <title>Users</title> | |||||
| </head> | |||||
| <body> | |||||
| <ul> | |||||
| {% for visit in visits %} | |||||
| <li> | |||||
| <a href="{% url 'get-visit' visit_id=visit.id %}"> | |||||
| ID: {{ visit.id }} <br> | |||||
| <strong>{{ visit.visitor }} at {{ visit.date_time }}</strong> <br> | |||||
| Reason: {{ visit.reason }} | |||||
| </a> | |||||
| </li> | |||||
| {% endfor %} | |||||
| </ul> | |||||
| </body> | |||||
| </html> | |||||
| @ -0,0 +1,10 @@ | |||||
| from django.contrib import admin | |||||
| from .models import Visit | |||||
| class VisitAdmin(admin.ModelAdmin): | |||||
| pass | |||||
| admin.site.register(Visit, VisitAdmin) | |||||
| @ -0,0 +1,6 @@ | |||||
| from django.apps import AppConfig | |||||
| class UzdevumiConfig(AppConfig): | |||||
| default_auto_field = 'django.db.models.BigAutoField' | |||||
| name = 'uzdevumi' | |||||
| @ -0,0 +1,12 @@ | |||||
| from django.forms import ( | |||||
| Form, | |||||
| CharField, | |||||
| DateTimeField, | |||||
| ) | |||||
| class VisitForm(Form): | |||||
| visitor = CharField() | |||||
| date_time = DateTimeField() | |||||
| reason = CharField() | |||||
| @ -0,0 +1,23 @@ | |||||
| # Generated by Django 3.2.8 on 2021-11-10 17:14 | |||||
| from django.db import migrations, models | |||||
| class Migration(migrations.Migration): | |||||
| initial = True | |||||
| dependencies = [ | |||||
| ] | |||||
| operations = [ | |||||
| migrations.CreateModel( | |||||
| name='Visit', | |||||
| fields=[ | |||||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |||||
| ('visitor', models.CharField(max_length=100)), | |||||
| ('date_time', models.DateTimeField()), | |||||
| ('reason', models.CharField(max_length=140)), | |||||
| ], | |||||
| ), | |||||
| ] | |||||
| @ -0,0 +1,8 @@ | |||||
| from django.db import models | |||||
| class Visit(models.Model): | |||||
| visitor = models.CharField(max_length=100) | |||||
| reason = models.CharField(max_length=140) | |||||
| date_time = models.DateTimeField() | |||||
| @ -0,0 +1,3 @@ | |||||
| from django.test import TestCase | |||||
| # Create your tests here. | |||||
| @ -0,0 +1,60 @@ | |||||
| from django.shortcuts import render | |||||
| from django.http import HttpResponse | |||||
| from .forms import VisitForm | |||||
| from .models import Visit | |||||
| def get_all_visits(request): | |||||
| visits = Visit.objects.all() | |||||
| context = { | |||||
| 'visits': visits, | |||||
| } | |||||
| return render( | |||||
| request, | |||||
| template_name='visits.html', | |||||
| context=context, | |||||
| ) | |||||
| def get_visit(request, visit_id): | |||||
| visit = Visit.objects.get(id=visit_id) | |||||
| return HttpResponse(visit_id) | |||||
| def add_visit(request): | |||||
| form = VisitForm(request.POST or None) | |||||
| if request.method == 'POST': | |||||
| if form.is_valid(): | |||||
| visit = Visit( | |||||
| visitor=form.cleaned_data['visitor'], | |||||
| reason=form.cleaned_data['reason'], | |||||
| date_time=form.cleaned_data['date_time'], | |||||
| ) | |||||
| visit.save() | |||||
| context = { | |||||
| 'visit': visit, | |||||
| } | |||||
| return render( | |||||
| request, | |||||
| template_name='visit.html', | |||||
| context=context, | |||||
| ) | |||||
| return render( | |||||
| request, | |||||
| template_name='visit_form.html', | |||||
| context={'form': form} | |||||
| ) | |||||