From 585998dcc10dfe439e2bc4f2752290a2735f6e56 Mon Sep 17 00:00:00 2001 From: koksnuss Date: Mon, 20 Apr 2020 13:06:34 +0200 Subject: [PATCH] django installed and basic configured, add admin-view, add models U m@laptop> ser Coin and Country --- Pipfile | 12 +++ Pipfile.lock | 50 ++++++++++++ coinmanager/coinc/__init__.py | 0 coinmanager/coinc/admin.py | 28 +++++++ coinmanager/coinc/apps.py | 6 ++ coinmanager/coinc/models.py | 83 +++++++++++++++++++ coinmanager/coinc/tests.py | 3 + coinmanager/coinc/urls.py | 28 +++++++ coinmanager/coinc/views.py | 28 +++++++ coinmanager/coinmanager/__init__.py | 0 coinmanager/coinmanager/asgi.py | 16 ++++ coinmanager/coinmanager/settings.py | 121 ++++++++++++++++++++++++++++ coinmanager/coinmanager/urls.py | 22 +++++ coinmanager/coinmanager/wsgi.py | 16 ++++ coinmanager/manage.py | 21 +++++ 15 files changed, 434 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 coinmanager/coinc/__init__.py create mode 100644 coinmanager/coinc/admin.py create mode 100644 coinmanager/coinc/apps.py create mode 100644 coinmanager/coinc/models.py create mode 100644 coinmanager/coinc/tests.py create mode 100644 coinmanager/coinc/urls.py create mode 100644 coinmanager/coinc/views.py create mode 100644 coinmanager/coinmanager/__init__.py create mode 100644 coinmanager/coinmanager/asgi.py create mode 100644 coinmanager/coinmanager/settings.py create mode 100644 coinmanager/coinmanager/urls.py create mode 100644 coinmanager/coinmanager/wsgi.py create mode 100755 coinmanager/manage.py diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..21bc4e8 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +django = "*" + +[requires] +python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..1ef1f63 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,50 @@ +{ + "_meta": { + "hash": { + "sha256": "68309cd71a258c30a39567fce09a09ad5c4ff0bdc85b6fba22b47598c985c883" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "asgiref": { + "hashes": [ + "sha256:8036f90603c54e93521e5777b2b9a39ba1bad05773fcf2d208f0299d1df58ce5", + "sha256:9ca8b952a0a9afa61d30aa6d3d9b570bb3fd6bafcf7ec9e6bed43b936133db1c" + ], + "version": "==3.2.7" + }, + "django": { + "hashes": [ + "sha256:642d8eceab321ca743ae71e0f985ff8fdca59f07aab3a9fb362c617d23e33a76", + "sha256:d4666c2edefa38c5ede0ec1655424c56dc47ceb04b6d8d62a7eac09db89545c1" + ], + "index": "pypi", + "version": "==3.0.5" + }, + "pytz": { + "hashes": [ + "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d", + "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be" + ], + "version": "==2019.3" + }, + "sqlparse": { + "hashes": [ + "sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e", + "sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548" + ], + "version": "==0.3.1" + } + }, + "develop": {} +} diff --git a/coinmanager/coinc/__init__.py b/coinmanager/coinc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/coinmanager/coinc/admin.py b/coinmanager/coinc/admin.py new file mode 100644 index 0000000..6dd7040 --- /dev/null +++ b/coinmanager/coinc/admin.py @@ -0,0 +1,28 @@ +# encoding: utf-8 +# +# Copyright (C) 2020 willipink.eu +# Author Moritz Münch moritzmuench@mailbox.org +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + + +from django.contrib import admin + +from .models import User, Coin, Country + + +admin.site.register(User) +admin.site.register(Coin) +admin.site.register(Country) diff --git a/coinmanager/coinc/apps.py b/coinmanager/coinc/apps.py new file mode 100644 index 0000000..b0bda1d --- /dev/null +++ b/coinmanager/coinc/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CoincConfig(AppConfig): + name = 'coinc' + verbose_name = 'CoinC, das Fenster zum Münzenmanager' diff --git a/coinmanager/coinc/models.py b/coinmanager/coinc/models.py new file mode 100644 index 0000000..19119a7 --- /dev/null +++ b/coinmanager/coinc/models.py @@ -0,0 +1,83 @@ +# encoding: utf-8 +# +# Copyright (C) 2020 willipink.eu +# Author Moritz Münch moritzmuench@mailbox.org +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + + +from datetime import datetime + +from django.db.models import BooleanField, CASCADE, CharField, DateField, ForeignKey, Model, PositiveIntegerField, PositiveSmallIntegerField, TextField + + + +class User(Model): + name = CharField('Name', max_length=50, default='Anonym') + + color = CharField('Farbe', max_length=20, default='white') + + + def __str__(self): + return self.name + + + +class Country(Model): + name_iso = CharField('Kürzel', max_length=2, primary_key=True) + + name = CharField('Land', max_length=50) + + member_since = PositiveSmallIntegerField('Mitglied seit') + + + def __str__(self): + return f"{self.name} - {self.name_iso}, Mitglied seit {self.member_since}" + + + +class Coin(Model): + value = PositiveSmallIntegerField('Wert', default=100) + + year_now = int(datetime.now().year) + year = PositiveSmallIntegerField('Jahr', default=year_now) + + country = ForeignKey('Country', on_delete=CASCADE) + + stamp = CharField('Prägerei', max_length=1, default='') + + name = TextField('Name', default='', blank=True) + + found_by = ForeignKey('User', on_delete=CASCADE) + + found_on = DateField('Gefunden am', auto_now_add=True) + + buy_only = BooleanField('Kursmünze', default=False) + + circulation = PositiveIntegerField('Auflage', default=0) + + comment = TextField('Kommentar', default='', blank=True) + + in_collector = BooleanField('Im Eurocollector 2002', default=False) + + checked = BooleanField('Von Gigo geprüft und einsortiert', default=False) + + exists = BooleanField('Existiert', default=True) + + fault_stamp = BooleanField('Fehlprägung', default=False) + + + def __str__(self): + return f"Wert: {self.value}, Jahr: {self.year}, Land: {self.country}, Prägerei {self.stamp}, Name {self.name}" diff --git a/coinmanager/coinc/tests.py b/coinmanager/coinc/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/coinmanager/coinc/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/coinmanager/coinc/urls.py b/coinmanager/coinc/urls.py new file mode 100644 index 0000000..8048921 --- /dev/null +++ b/coinmanager/coinc/urls.py @@ -0,0 +1,28 @@ +# encoding: utf-8 +# +# Copyright (C) 2020 willipink.eu +# Author Moritz Münch moritzmuench@mailbox.org +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + + +from django.urls import path + +from . import views + + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py new file mode 100644 index 0000000..1f6ddc3 --- /dev/null +++ b/coinmanager/coinc/views.py @@ -0,0 +1,28 @@ +# encoding: utf-8 +# +# Copyright (C) 2020 willipink.eu +# Author Moritz Münch moritzmuench@mailbox.org +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + + +from django.shortcuts import render + +from django.http import HttpResponse + + + +def index(request): + return HttpResponse("loift") diff --git a/coinmanager/coinmanager/__init__.py b/coinmanager/coinmanager/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/coinmanager/coinmanager/asgi.py b/coinmanager/coinmanager/asgi.py new file mode 100644 index 0000000..2c7f8b6 --- /dev/null +++ b/coinmanager/coinmanager/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for coinmanager 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', 'coinmanager.settings') + +application = get_asgi_application() diff --git a/coinmanager/coinmanager/settings.py b/coinmanager/coinmanager/settings.py new file mode 100644 index 0000000..510d002 --- /dev/null +++ b/coinmanager/coinmanager/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for coinmanager 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 = 'w-^#jkm1ub6=)(xiy%6od%+j6pwr51o0sk9o(-mb$8b77#h$53' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'coinc.apps.CoincConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'coinmanager.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 = 'coinmanager.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 = 'en-us' + +TIME_ZONE = 'Europe/Berlin' + +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/' diff --git a/coinmanager/coinmanager/urls.py b/coinmanager/coinmanager/urls.py new file mode 100644 index 0000000..0bbcc5e --- /dev/null +++ b/coinmanager/coinmanager/urls.py @@ -0,0 +1,22 @@ +"""coinmanager 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 include, path + +urlpatterns = [ + path('coinc/', include('coinc.urls')), + path('admin/', admin.site.urls), +] diff --git a/coinmanager/coinmanager/wsgi.py b/coinmanager/coinmanager/wsgi.py new file mode 100644 index 0000000..0082360 --- /dev/null +++ b/coinmanager/coinmanager/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for coinmanager 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', 'coinmanager.settings') + +application = get_wsgi_application() diff --git a/coinmanager/manage.py b/coinmanager/manage.py new file mode 100755 index 0000000..60a094a --- /dev/null +++ b/coinmanager/manage.py @@ -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', 'coinmanager.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()