From e8ffe635f99cbadc3c7e27522934969466bd9402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Thu, 11 Jan 2018 19:24:52 +0100 Subject: [PATCH 01/45] typos in template --- .../currencies/templates/currencies/index.html | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index d29a52d..2ab0e02 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -5,10 +5,9 @@

Currencies in CHF

-

{{ message }}

-

Frühere Daten:

-
-

US Dollars:

+

{{ message }}

+

Frühere Daten:

+

US Dollars:

{% if currency_USD_list %} @@ -28,7 +27,7 @@

{% endif %}
-

EURO:

+

EURO:

{% if currency_EUR_list %}
@@ -48,7 +47,7 @@

{% endif %}
-

Japanese Yenn:

+

Japanese Yenn:

{% if currency_JPY_list %}
@@ -69,7 +68,7 @@

{% endif %}
-

Great Britain Pounds:

+

Great Britain Pounds:

{% if currency_GBP_list %}
From 10c9d8602dd2a7e2ebb8131d3534e09a864e07fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sat, 13 Jan 2018 08:39:24 +0100 Subject: [PATCH 02/45] add order by dates --- django/didgeridoo/currencies/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index d19f3e8..5afaac3 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -110,10 +110,14 @@ def currencies(request): geschlossen ist? """ currency_list = ExchangeRate.objects.all() - currency_USD_list = ExchangeRate.objects.filter(name__name='USD') - currency_EUR_list = ExchangeRate.objects.filter(name__name='EUR') - currency_JPY_list = ExchangeRate.objects.filter(name__name='JPY') - currency_GBP_list = ExchangeRate.objects.filter(name__name='GBP') + currency_USD_list = ExchangeRate.objects.filter( + name__name='USD').order_by('date__date') + currency_EUR_list = ExchangeRate.objects.filter( + name__name='EUR').order_by('date__date') + currency_JPY_list = ExchangeRate.objects.filter( + name__name='JPY').order_by('date__date') + currency_GBP_list = ExchangeRate.objects.filter( + name__name='GBP').order_by('date__date') # ------------------------------------------------------------------- # ------------------------------------------------------------------- # I leave this part in the document as history. From 681773ae101e352d65a218300584685b0acfce11 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 14 Jan 2018 13:07:16 +0100 Subject: [PATCH 03/45] update the apache configuration in the ansible role --- ansible/roles/web_AI-5/files/000-default.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/roles/web_AI-5/files/000-default.conf b/ansible/roles/web_AI-5/files/000-default.conf index bf85cc0..b9d347e 100644 --- a/ansible/roles/web_AI-5/files/000-default.conf +++ b/ansible/roles/web_AI-5/files/000-default.conf @@ -13,7 +13,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/ ServerAdmin webmaster@localhost - Alias /media/ /vagrant/django/didgeridoo/media/ + Alias /media/ /srv/media/ Alias /static/ /vagrant/django/didgeridoo/static/ @@ -23,7 +23,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/ - + Require all granted From 368c7342ef0c8226cfddaf6af4f43cb8d8343316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 13:43:13 +0100 Subject: [PATCH 04/45] add of a dropdown and footerinformation nicely --- .../webshop/templates/webshop/base.html | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index bb41953..a560c90 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -43,13 +43,23 @@ {% else %}
  • LOGIN
  • {% endif %} -
  • CURRENCY
  • +
    -
    +
    {% block sidebar %} {% if category_list %}
      @@ -67,13 +77,15 @@ {% endif %} {% endblock %}
    -
    +
    +

    {% block section_title %}{% endblock %}

    -
    -
    - {% block content %}{% endblock %} +
    +
    + {% block content %}{% endblock %} +
    @@ -82,8 +94,30 @@
    {% block footer %} - This is a case study project of Ivan Hörler and Andreas Zweili.
    - It is a school project/excercise and has no commercial intent. + {% endblock %}
    From c4d018be9537a9c77a80931c3272f80831bd6015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 13:44:11 +0100 Subject: [PATCH 05/45] first try of a form for currency dropdown --- django/didgeridoo/currencies/forms.py | 7 + django/didgeridoo/currencies/models.py | 1 + .../templates/currencies/index.html | 13 +- django/didgeridoo/currencies/urls.py | 4 +- django/didgeridoo/currencies/views.py | 70 +++------ django/didgeridoo/didgeridoo/settings.py | 142 ------------------ 6 files changed, 35 insertions(+), 202 deletions(-) create mode 100644 django/didgeridoo/currencies/forms.py delete mode 100644 django/didgeridoo/didgeridoo/settings.py diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py new file mode 100644 index 0000000..5acf450 --- /dev/null +++ b/django/didgeridoo/currencies/forms.py @@ -0,0 +1,7 @@ +from django import forms +from currencies.models import ExchangeRate_name + + +class CurrencyForm(forms.Form): + currencies = forms.ModelChoiceField( + queryset=ExchangeRate_name.objects.all()) diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index 73a09ba..5ee16ef 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.core.urlresolvers import reverse from decimal import Decimal import datetime diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index 2ab0e02..2f28ccb 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -1,10 +1,6 @@ - - - - - -
    -

    Currencies in CHF

    +{% extends "webshop/base.html" %} +{% block section_title %}Currencies in CHF{% endblock %} + {% block content %}

    {{ message }}

    Frühere Daten:

    US Dollars:

    @@ -89,5 +85,4 @@

    {% endif %}
    - - +{% endblock %} diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 2804c74..8b2dd1a 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,7 +1,9 @@ from django.conf.urls import url -from currencies.views import currencies +from currencies.views import currencies, CurrencyUpdate urlpatterns = [ url(r'^currencies/$', currencies), + url(r'^/$', CurrencyUpdate.as_view(), + name='CurrencyUpdate'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 5afaac3..cc392ec 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -1,11 +1,20 @@ from django.shortcuts import render import datetime +from django.views.generic.edit import UpdateView +from django.core.urlresolvers import reverse_lazy from currencies.models import (ExchangeRate, ExchangeRate_date, ExchangeRate_name) from currencies import exchange_rates +from currencies.forms import CurrencyForm +class CurrencyUpdate(UpdateView): + model = ExchangeRate_name + currency_form = CurrencyForm + template_name = 'webshop/base.html' + success_url = 'webshop/base.html' + def currencies(request): # this function fetches the data from exchange_rates.py # evaluates if the values are already stored and @@ -19,17 +28,21 @@ def currencies(request): print('views raw_data: ', raw_data, 'error:', e) # assert False message_no = "Already querried today: " message_yes = " Updated successfully: " + # raw_data can be empty. In this case skip: if raw_data: - print(raw_data) + # if raw_data is not empty iterate over items in it: for currency, rate in raw_data.items(): + # check for already existing exrates per day and add + # to message that its already been saved. if ExchangeRate.objects.filter( date__date=today, name__name=currency): message_no += currency + ", " - # A: https://stackoverflow.com/a/27802801/4061870 else: if ExchangeRate_date.objects.filter(date=today)[:1]: + # if data and currency is not yet present, save it. try: + # A: https://stackoverflow.com/a/27802801/4061870 # lustigerweise gibt .values() den value und die id # zurück. Ohne .values() gibts nur den "value" date_dict = ExchangeRate_date.objects.filter( @@ -47,6 +60,7 @@ def currencies(request): % (e, type(e), today)) if ExchangeRate_name.objects.filter( name=currency)[:1]: + # if data and currency is not yet present, save it. try: name_dict = ExchangeRate_name.objects.filter( name=currency).values() @@ -62,6 +76,7 @@ def currencies(request): print('exname_not_exists %s (%s) on %s' % (e, type(e), currency)) try: + # save item to where id's match. exrate = ExchangeRate.objects.create( # name_id=name_id, name_id=ExchangeRate_name.objects.get( @@ -87,7 +102,7 @@ def currencies(request): message_yes = message_yes[::-1] # invert the string message_yes = message_yes.replace(",", "!", 1) # replace f. , with ! message_yes = message_yes[::-1] # invert the string back - + # here we evaluate what kind of message is valid: if len(message_no) > 24 and len(message_yes) > 23: message = message_no + message_yes elif len(message_no) > 24: @@ -109,6 +124,7 @@ def currencies(request): Kann es sein dass die SNB aufgrund eines Feiertages geschlossen ist? """ + # know we can query our data for presentaton: currency_list = ExchangeRate.objects.all() currency_USD_list = ExchangeRate.objects.filter( name__name='USD').order_by('date__date') @@ -118,53 +134,7 @@ def currencies(request): name__name='JPY').order_by('date__date') currency_GBP_list = ExchangeRate.objects.filter( name__name='GBP').order_by('date__date') - # ------------------------------------------------------------------- - # ------------------------------------------------------------------- - # I leave this part in the document as history. - # Problem is that i get the expected List with dictionaries like: - # view_currencies_list[ - # {'date': '2017-12-29, 'USD':'1.00', 'EUR':'1.00', 'GBP':'1.00', 'JPY':'1.00'}, - # {'date': '2017-12-30, 'USD':'1.00', 'EUR':'1.00', 'GBP':'1.00', 'JPY':'1.00'}, - # ] - # but the dict of 'date:' does not seam to deliver the same values as - # the dict's of key name:'USD' im not able to fix this in moment. - # nor am i able to generate a HTML table with date | USD | EUR | ... - # ------------------------------------------------------------------- - # ------------------------------------------------------------------- - # prepare data to be displayed in a html table: - # https://stackoverflow.com/questions/8749158/removing-duplicates-from-dictionary#8749473 - # A: https://stackoverflow.com/questions/37205793/django-values-list-vs-values#37205928 - # B: https://stackoverflow.com/questions/6521892/how-to-access-a-dictionary-key-value-present-inside-a-list - # # search for currencies in a date and apend them to the list - # view_currency_list = [] - # view_currencies_list = ExchangeRate_name.objects.all() - # view_dates_list = ExchangeRate_date.objects.all() - # count_date = 0 - # count_currencies = 0 - # for view_date in view_dates_list: - # count_date += 1 - # view_currency_dict = {view_date} - # # view_currency_dict.update({}) - # for view_currency in view_currencies_list: - # count_currencies += 1 - # try: - # x = ExchangeRate.objects.filter(date__date=str( - # view_date), - # name__name=str( - # view_currency - # )).values() # A - # view_exchange_rate_to_chf = x[0]['exchange_rate_to_chf'] - # except Exception as e: - # print('prepare_view %s (%s) for %s on %s is %s' - # % (e, type(e), view_currency, view_date, - # view_exchange_rate_to_chf)) - # view_exchange_rate_to_chf = " " - # - # view_currency_dict.update({view_currency: - # view_exchange_rate_to_chf}) # B - # - # view_currency_list.append(view_currency_dict) - # assert False + # and publish it on template: return render(request, 'currencies/index.html', {'currency_list': currency_list, diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py deleted file mode 100644 index 3e84361..0000000 --- a/django/didgeridoo/didgeridoo/settings.py +++ /dev/null @@ -1,142 +0,0 @@ -""" -Django settings for didgeridoo project. - -Generated by 'django-admin startproject' using Django 1.10.7. - -For more information on this file, see -https://docs.djangoproject.com/en/1.10/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.10/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/1.10/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '(#4#-$$&mx7(%q+6&&@-c&g%i0dc4)zfks1%sy8b%lsxspou&%' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [ - 'localhost', - '127.0.0.1', - 'didgeridoo.ml' -] - - -# Application definition - -INSTALLED_APPS = [ - 'webshop.apps.WebshopConfig', - 'django_extensions', - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'currencies', - 'bootstrap3', - ] - -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 = 'didgeridoo.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', - 'django.template.context_processors.media' - ], - }, - }, -] - -WSGI_APPLICATION = 'didgeridoo.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.10/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'webshopdb', - 'USER': 'webshop', - 'PASSWORD': '2YKtY53F3HDDzPyExAaSh3jdVNh6VN', - 'HOST': '127.0.0.1', - 'PORT': '3306', - 'OPTIONS': { - 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" - } - } -} - - -# Password validation -# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'Europe/Zurich' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.10/howto/static-files/ - -STATIC_URL = '/static/' -STATIC_ROOT = '/vagrant/django/didgeridoo/static/' - -MEDIA_URL = '/media/' -MEDIA_ROOT = '/srv/media/' - -LOGIN_REDIRECT_URL = '/' From 013d3d2d2848b17893fea15d00bd35fae07993bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 14:07:53 +0100 Subject: [PATCH 06/45] =?UTF-8?q?falsche=20vorgehensweise=20um=20settings.?= =?UTF-8?q?py=20zur=C3=BCck=20zu=20bekommen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/roles/web_AI-5/tasks/main.yml | 8 ++++ django/didgeridoo/webshop/admin.py | 48 +++++++++++++++++-- .../didgeridoo/webshop/fixtures/webshop.yaml | 7 +++ django/didgeridoo/webshop/forms.py | 31 +++++++++++- django/didgeridoo/webshop/models.py | 14 ++---- .../webshop/templates/webshop/category.html | 2 +- .../webshop/templates/webshop/index.html | 2 +- django/didgeridoo/webshop/views.py | 5 +- docs/andreas.bib | 2 +- docs/doku.org | 2 +- 10 files changed, 99 insertions(+), 22 deletions(-) diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index 5daf02b..40cb890 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -43,5 +43,13 @@ group: www-data mode: 0755 + +- name: Add currency refresh cronjob + cron: + name: "refresh currencies" + minute: "0" + job: "wget -O /dev/null https://didgeridoo.ml/currencies" + + - name: Restart apache service service: name=apache2 state=restarted diff --git a/django/didgeridoo/webshop/admin.py b/django/didgeridoo/webshop/admin.py index 06b4dd4..e3d5f74 100644 --- a/django/didgeridoo/webshop/admin.py +++ b/django/didgeridoo/webshop/admin.py @@ -5,7 +5,9 @@ from django.contrib.auth.models import User # Register your models here. from webshop.models import (Article, Order, OrderPosition, Person, City, Picture, OrderOfGoods, - Category, Option, Setting) + Category, Option) + +from webshop.forms import PictureForm class PersonInline(admin.StackedInline): @@ -14,10 +16,47 @@ class PersonInline(admin.StackedInline): verbose_name_plural = 'person' +class PictureAdmin(admin.ModelAdmin): + form = PictureForm + ordering = ('name',) + list_display = ('name', 'article',) + + +class PictureInline(admin.StackedInline): + model = Picture + form = PictureForm + can_delete = False + verbose_name_plural = 'pictures' + + +class OptionAdmin(admin.ModelAdmin): + model = Option + list_display = ('name', 'description',) + readonly_fields = ('name','description',) + + + def get_actions(self, request): + #Disable delete + actions = super(OptionAdmin, self).get_actions(request) + del actions['delete_selected'] + return actions + + def has_delete_permission(self, request, obj=None): + #Disable delete + return False + + def has_add_permission(self, request): + return False + + class UserAdmin(BaseUserAdmin): inlines = (PersonInline,) +class ArticleAdmin(admin.ModelAdmin): + inlines = (PictureInline,) + + class OrderPositionInline(admin.StackedInline): model = OrderPosition can_delete = False @@ -42,11 +81,10 @@ class OrderOfGoodsAdmin(admin.ModelAdmin): admin.site.unregister(User) admin.site.register(User, UserAdmin) -admin.site.register(Article) +admin.site.register(Article, ArticleAdmin) admin.site.register(Order, OrderAdmin) +admin.site.register(Picture, PictureAdmin) admin.site.register(City) -admin.site.register(Picture) admin.site.register(OrderOfGoods, OrderOfGoodsAdmin) admin.site.register(Category) -admin.site.register(Option) -admin.site.register(Setting) +admin.site.register(Option, OptionAdmin) diff --git a/django/didgeridoo/webshop/fixtures/webshop.yaml b/django/didgeridoo/webshop/fixtures/webshop.yaml index a3c429d..fd09a94 100644 --- a/django/didgeridoo/webshop/fixtures/webshop.yaml +++ b/django/didgeridoo/webshop/fixtures/webshop.yaml @@ -95,3 +95,10 @@ stock: 44 status: 3 price_in_chf: 41.4 + +- model: webshop.Option + fields: + name: max_pictures + description: "Maximum number of Pictures a user is allowed to upload." + value: 5 + enabled: True diff --git a/django/didgeridoo/webshop/forms.py b/django/didgeridoo/webshop/forms.py index c87ec6c..5e431a9 100644 --- a/django/didgeridoo/webshop/forms.py +++ b/django/didgeridoo/webshop/forms.py @@ -1,5 +1,5 @@ from django import forms -from webshop.models import Salutation, City +from webshop.models import Salutation, City, Picture, Article, Option class RegistrationForm(forms.Form): @@ -22,3 +22,32 @@ class RegistrationForm(forms.Form): raise forms.ValidationError( "The zip code and the city don't match.") return city + + +class PictureForm(forms.ModelForm): + def max_pictures(self): + try: + option = Option.objects.get(name='max_pictures') + if option.enabled: + return option.value + else: + return False + except: + return False + + def count_pictures(self, _article): + count = Picture.objects.filter(article=_article.id).count() + return count + + def clean(self): + article = self.cleaned_data.get('article') + print(self.max_pictures()) + if self.max_pictures(): + if (self.count_pictures(article) >= self.max_pictures()): + raise forms.ValidationError("Only " + str(self.max_pictures()) + + " pictures per article allowed.") + return self.cleaned_data + + class Meta: + model = Picture + fields = ['name', 'article', 'image'] diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index 3bb3442..a17e7dc 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -7,18 +7,12 @@ from django.utils import timezone class Option(models.Model): name = models.CharField(max_length=200, unique=True) + description = models.CharField(max_length=200, unique=True) value = models.IntegerField(default=5) - - def __str__(self): - return self.name - - -class Setting(models.Model): - option = models.ForeignKey(Option, on_delete=models.CASCADE) enabled = models.BooleanField(default=False) def __str__(self): - return str(self.option) + return self.name class ArticleStatus(models.Model): @@ -74,8 +68,8 @@ class OrderOfGoods(models.Model): class Picture(models.Model): - name = models.CharField(max_length=200, unique=True) - article = models.ForeignKey(Article, on_delete=models.CASCADE) + name = models.CharField(max_length=200) + article = models.ForeignKey(Article) image = models.ImageField(upload_to="images") def __str__(self): diff --git a/django/didgeridoo/webshop/templates/webshop/category.html b/django/didgeridoo/webshop/templates/webshop/category.html index bb6a535..5ea3a14 100644 --- a/django/didgeridoo/webshop/templates/webshop/category.html +++ b/django/didgeridoo/webshop/templates/webshop/category.html @@ -25,7 +25,7 @@
    {% else %}

    - Something whent wrong, no articles are stored. + We are sorry but there are currently no articles in this category.

    {% endif %} {% endblock %} diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 7f661bd..7eff913 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -26,7 +26,7 @@ {% else %}

    - Something whent wrong, no articles are stored. + We are sorry but there are currently no articles being sold.

    {% endif %} {% endblock %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index cce4b63..1a4a4db 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -59,10 +59,11 @@ def article_details(request, article_id): {i: Category.objects.filter(parent_category=i.id)}) article = get_object_or_404(Article, pk=article_id) - + picture_list = Picture.objects.filter(article=article_id) return render(request, 'webshop/article_details.html', {'article': article, - 'category_list': category_list}) + 'category_list': category_list, + 'picture_list': picture_list}) @login_required def profile(request): diff --git a/docs/andreas.bib b/docs/andreas.bib index 96bd885..b0a3cdc 100644 --- a/docs/andreas.bib +++ b/docs/andreas.bib @@ -8,8 +8,8 @@ } @book{djangobook, + Note = {{\url{https://djangobook.com/}}}, publisher = {{leanpub.com}}, - Url = {{https://djangobook.com/}}, Urldate = {{2018-01-08}}, author = {Nigel George}, title = {{Mastering Django: Core}}, diff --git a/docs/doku.org b/docs/doku.org index d1dbd58..e4ced80 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -485,7 +485,7 @@ ein Ergebnis eines Anwendungsfalls sein (e.g. falsches Pass- wort beim Login). Dabei wird die technische Lösung nicht konkret beschrieben. Die Detailstufe kann dabei sehr unterschiedlich sein.\footcite{usecase} -**** TODO Anwendungsfalliagramm +**** Anwendungsfalliagramm "Ein Anwendungsfalldiagramm ... ist eine der 14 Diagrammarten der Unified Modeling Language (UML), einer Sprache für die Modellierung From ec92099fc9c59395345be0f32d0433edb9c424d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 14:11:27 +0100 Subject: [PATCH 07/45] duno how to restore. created new. --- django/didgeridoo/didgeridoo/settings.py | 141 +++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 django/didgeridoo/didgeridoo/settings.py diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py new file mode 100644 index 0000000..405c1de --- /dev/null +++ b/django/didgeridoo/didgeridoo/settings.py @@ -0,0 +1,141 @@ +""" +Django settings for didgeridoo project. + +Generated by 'django-admin startproject' using Django 1.10.7. + +For more information on this file, see +https://docs.djangoproject.com/en/1.10/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.10/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/1.10/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '(#4#-$$&mx7(%q+6&&@-c&g%i0dc4)zfks1%sy8b%lsxspou&%' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [ + 'localhost', + '127.0.0.1', + 'didgeridoo.ml' +] + + +# Application definition + +INSTALLED_APPS = [ + 'webshop.apps.WebshopConfig', + 'django_extensions', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'currencies', + ] + +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 = 'didgeridoo.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', + 'django.template.context_processors.media' + ], + }, + }, +] + +WSGI_APPLICATION = 'didgeridoo.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'webshopdb', + 'USER': 'webshop', + 'PASSWORD': '2YKtY53F3HDDzPyExAaSh3jdVNh6VN', + 'HOST': '127.0.0.1', + 'PORT': '3306', + 'OPTIONS': { + 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" + } + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'Europe/Zurich' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ + +STATIC_URL = '/static/' +STATIC_ROOT = '/vagrant/django/didgeridoo/static/' + +MEDIA_URL = '/media/' +MEDIA_ROOT = '/srv/media/' + +LOGIN_REDIRECT_URL = '/' From 05b77b8845f4eddaa605e4b32729e5f72ba4320e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 17:13:41 +0100 Subject: [PATCH 08/45] unfinished part of currency dropdown --- django/didgeridoo/currencies/forms.py | 4 +- django/didgeridoo/currencies/urls.py | 2 - django/didgeridoo/currencies/views.py | 14 +++--- .../webshop/templates/webshop/base.html | 44 ++++++++++--------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 5acf450..f1df52d 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -3,5 +3,5 @@ from currencies.models import ExchangeRate_name class CurrencyForm(forms.Form): - currencies = forms.ModelChoiceField( - queryset=ExchangeRate_name.objects.all()) + currencies = forms.ModelChoiceField( + queryset=ExchangeRate_name.objects.all()) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 8b2dd1a..28801cf 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -4,6 +4,4 @@ from currencies.views import currencies, CurrencyUpdate urlpatterns = [ url(r'^currencies/$', currencies), - url(r'^/$', CurrencyUpdate.as_view(), - name='CurrencyUpdate'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index cc392ec..5af1837 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -9,11 +9,15 @@ from currencies import exchange_rates from currencies.forms import CurrencyForm -class CurrencyUpdate(UpdateView): - model = ExchangeRate_name - currency_form = CurrencyForm - template_name = 'webshop/base.html' - success_url = 'webshop/base.html' +def CurrencyUpdate(request): + if request.method == 'POST': + currency_form = CurrencyForm + assert False + else: + currency_form = CurrencyForm + assert False + return render(request, + {'currency_form': currency_form}) def currencies(request): # this function fetches the data from exchange_rates.py diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index a560c90..661fbae 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -34,27 +34,31 @@ HOME + +
    + {% csrf_token %} + +
    -
    From 7fb1c36e986ea0b8a709099c8ab7095bdb83fa84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 19:56:33 +0100 Subject: [PATCH 09/45] changed static url's to correctly detected ones. by runserver. needs to be checked for apache! --- django/didgeridoo/didgeridoo/settings.py | 30 +++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 405c1de..d17455f 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -131,9 +131,37 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.10/howto/static-files/ +# seams like it changed with 1.13+ (14.1.18|IH) +# https://stackoverflow.com/a/14800489/4061870 STATIC_URL = '/static/' -STATIC_ROOT = '/vagrant/django/didgeridoo/static/' +STATIC_ROOT = '' + +# Absolute path to the directory static files should be collected to. +# Don't put anything in this directory yourself; store your static files +# in apps' "static/" subdirectories and in STATICFILES_DIRS. +# Example: "/home/media/media.lawrence.com/static/" +STATIC_ROOT = '' + +# URL prefix for static files. +# Example: "http://media.lawrence.com/static/" +STATIC_URL = '/static/' + +# Additional locations of static files +STATICFILES_DIRS = ( + # Put strings here, like "/home/html/static" or "C:/www/django/static". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. + '/vagrant/django/didgeridoo/static', +) + +# List of finder classes that know how to find static files in +# various locations. +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + # 'django.contrib.staticfiles.finders.DefaultStorageFinder', +) MEDIA_URL = '/media/' MEDIA_ROOT = '/srv/media/' From e765a999c69829b9b156175c66f01e703aa431fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Sun, 14 Jan 2018 19:57:22 +0100 Subject: [PATCH 10/45] divided the navigation to separate file. --- .../webshop/templates/webshop/base.html | 39 +++---------------- .../webshop/templates/webshop/index.html | 2 + .../webshop/templates/webshop/nav.html | 35 +++++++++++++++++ 3 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 django/didgeridoo/webshop/templates/webshop/nav.html diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index 661fbae..34177de 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -7,7 +7,7 @@ - {% load static %} + {% load staticfiles %} {% block title %} @@ -28,39 +28,7 @@ </div> </div> </div> - <nav class="navbar navbar-default"> - <div class="container-fluid"> - <div class="navbar-header"> - <a class="navbar-brand" href="{% url 'index' %}"> - HOME - </a> - <ul class="nav navbar-nav"> - <li><a href="#">CART</a></li> - {% if user.is_authenticated %} - <li> - <a href="{% url 'profile' %}">PROFILE</a> - </li> - <li> - <a href="{% url 'logout' %}">LOGOUT</a> - </li> - {% else %} - <li> - <a href="{% url 'login' %}">LOGIN</a> - </li> - {% endif %} - </ul> - <form action="" method="POST" novalidate> - {% csrf_token %} - <select name="CurrencyUpdate" id="CurrencyUpdate" onchange="this.form.submit()"> - <option value="CHF">CHF</option> - <option value="USD">USD</option> - <option value="GBP">GBP</option> - <option value="JPY">JPY</option> - </select> - </form> - </div> - </div> - </nav> + {% block nav %}{% include "webshop/nav.html" %}{% endblock %} <div class="container-fluid"> <div class="row"> <div class="col-md-2"> @@ -127,5 +95,8 @@ </div> </div> </footer> + <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> + <script src="{% static 'js/app.js' %}"></script> + <script>{% block javascript %}{% endblock %}</script> </body> </html> diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 7eff913..71484e3 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,5 +1,7 @@ {% extends "webshop/base.html" %} + {% block section_title %}Articles{% endblock %} + {% block content %} {% if articles_list %} <table class="table"> diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html new file mode 100644 index 0000000..aa45224 --- /dev/null +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -0,0 +1,35 @@ +{% block nav %} +<nav class="navbar navbar-default"> + <div class="container-fluid"> + <div class="navbar-header"> + <a class="navbar-brand" href="{% url 'index' %}"> + HOME + </a> + <ul class="nav navbar-nav"> + <li><a href="#">CART</a></li> + {% if user.is_authenticated %} + <li> + <a href="{% url 'profile' %}">PROFILE</a> + </li> + <li> + <a href="{% url 'logout' %}">LOGOUT</a> + </li> + {% else %} + <li> + <a href="{% url 'login' %}">LOGIN</a> + </li> + {% endif %} + </ul> + <form action="" method="POST" novalidate> + {% csrf_token %} + <select name="CurrencyUpdate" id="CurrencyUpdate" onchange="this.form.submit()"> + <option value="CHF">CHF</option> + <option value="USD">USD</option> + <option value="GBP">GBP</option> + <option value="JPY">JPY</option> + </select> + </form> + </div> + </div> +</nav> +{% endblock %} From 19af243c4f9f714dbfefbe691ce78e061971b544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 19:57:48 +0100 Subject: [PATCH 11/45] not finished AJAX request for currencies --- django/didgeridoo/currencies/urls.py | 3 +++ django/didgeridoo/currencies/views.py | 17 +++++++++-------- django/didgeridoo/static/js/app.js | 15 +++++++++++++++ django/didgeridoo/webshop/urls.py | 8 ++++++-- django/didgeridoo/webshop/views.py | 1 + 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 django/didgeridoo/static/js/app.js diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 28801cf..ef9dd3f 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -4,4 +4,7 @@ from currencies.views import currencies, CurrencyUpdate urlpatterns = [ url(r'^currencies/$', currencies), + url(r'^ajax/CurrencyUpdate/$', + CurrencyUpdate, + name='CurrencyUpdate'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 5af1837..a69fb90 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -7,17 +7,18 @@ from currencies.models import (ExchangeRate, ExchangeRate_name) from currencies import exchange_rates from currencies.forms import CurrencyForm +from django.http import JsonResponse def CurrencyUpdate(request): - if request.method == 'POST': - currency_form = CurrencyForm - assert False - else: - currency_form = CurrencyForm - assert False - return render(request, - {'currency_form': currency_form}) + assert False + currency = request.GET.get('CurrencyUpdate', None) + data = { + 'currency': ExchangeRate_name.objects.filter( + name=currency) + } + return JsonResponse(data) + def currencies(request): # this function fetches the data from exchange_rates.py diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js new file mode 100644 index 0000000..09c128c --- /dev/null +++ b/django/didgeridoo/static/js/app.js @@ -0,0 +1,15 @@ + $("#id_currency").change(function () { + var currency = $(this).val(); + $.ajax({ + url: '/ajax/CurrencyUpdate/', + data: { + 'currency': currency + }, + dataType: 'json', + success: function (data) { + if (data.is_taken) { + alert("es pop auf! --dies kommt von: static/js/app.js--."); + } + } + }); + }); diff --git a/django/didgeridoo/webshop/urls.py b/django/didgeridoo/webshop/urls.py index dc79c1d..5a4685e 100644 --- a/django/didgeridoo/webshop/urls.py +++ b/django/didgeridoo/webshop/urls.py @@ -11,6 +11,10 @@ urlpatterns = [ views.articles_in_category, name='category'), url('^', include('django.contrib.auth.urls')), - url(r'^profile/$', views.profile, name='profile'), - url(r'^registration/$', views.registration, name='registration'), + url(r'^profile/$', + views.profile, + name='profile'), + url(r'^registration/$', + views.registration, + name='registration'), ] diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 1a4a4db..040f522 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -11,6 +11,7 @@ from webshop.models import (Article, Picture) from webshop.forms import RegistrationForm + # Create your views here. From 4ea27b0bbc6168e2c42bf4b6eaa22b08be9d9afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 21:21:01 +0100 Subject: [PATCH 12/45] delete redundacy --- django/didgeridoo/didgeridoo/settings.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index d17455f..6ecbe46 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -134,9 +134,6 @@ USE_TZ = True # seams like it changed with 1.13+ (14.1.18|IH) # https://stackoverflow.com/a/14800489/4061870 -STATIC_URL = '/static/' -STATIC_ROOT = '' - # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. From 2117c978748afeb9670d5a337c1a69217ad0d029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 21:30:57 +0100 Subject: [PATCH 13/45] for andreas --- django/didgeridoo/currencies/views.py | 6 +++--- django/didgeridoo/static/js/app.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index a69fb90..0dcd960 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -11,12 +11,12 @@ from django.http import JsonResponse def CurrencyUpdate(request): - assert False currency = request.GET.get('CurrencyUpdate', None) data = { - 'currency': ExchangeRate_name.objects.filter( - name=currency) + 'currency': ExchangeRate_name.objects.get( + currency).id } + print('currency: ', currency, 'data: ', data) return JsonResponse(data) diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index 09c128c..90b51bc 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,4 +1,4 @@ - $("#id_currency").change(function () { + $("#CurrencyUpdate").change(function () { var currency = $(this).val(); $.ajax({ url: '/ajax/CurrencyUpdate/', From 213d231c818523b0bb2dbd2c6534c59400bdc4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 22:02:43 +0100 Subject: [PATCH 14/45] change function name from camelcase to python syntactical underlines --- django/didgeridoo/currencies/urls.py | 8 ++++---- django/didgeridoo/currencies/views.py | 8 ++++---- django/didgeridoo/static/js/app.js | 4 ++-- django/didgeridoo/webshop/templates/webshop/base.html | 2 +- django/didgeridoo/webshop/templates/webshop/nav.html | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index ef9dd3f..0ef97bf 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,10 +1,10 @@ from django.conf.urls import url -from currencies.views import currencies, CurrencyUpdate +from currencies.views import currencies, currency_update urlpatterns = [ url(r'^currencies/$', currencies), - url(r'^ajax/CurrencyUpdate/$', - CurrencyUpdate, - name='CurrencyUpdate'), + url(r'^ajax/currency_update/$', + currency_update, + name='currency_update'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 0dcd960..86419ff 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -10,11 +10,11 @@ from currencies.forms import CurrencyForm from django.http import JsonResponse -def CurrencyUpdate(request): - currency = request.GET.get('CurrencyUpdate', None) +def currency_update(request): + currency = request.GET.get('currency_update', None) data = { - 'currency': ExchangeRate_name.objects.get( - currency).id + 'currency': ExchangeRate.objects.filter( + name__name=currency).latest('date') } print('currency: ', currency, 'data: ', data) return JsonResponse(data) diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index 90b51bc..e9dea69 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,7 +1,7 @@ - $("#CurrencyUpdate").change(function () { + $("#currency_update").change(function () { var currency = $(this).val(); $.ajax({ - url: '/ajax/CurrencyUpdate/', + url: '/ajax/currency_update/', data: { 'currency': currency }, diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index 34177de..58f7905 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -7,7 +7,7 @@ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- Add additional CSS in static file --> - {% load staticfiles %} + {% load static %} <link rel="stylesheet" href="{{ STATIC_URL }}/static/webshop/css/base.css" /> {% block title %} <title> diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index aa45224..f009520 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -22,7 +22,7 @@ </ul> <form action="" method="POST" novalidate> {% csrf_token %} - <select name="CurrencyUpdate" id="CurrencyUpdate" onchange="this.form.submit()"> + <select name="currency_update" id="currency_update" onchange="this.form.submit()"> <option value="CHF">CHF</option> <option value="USD">USD</option> <option value="GBP">GBP</option> From 5e91470470506d233c3ada5c474fe30cf5dcc64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 22:09:18 +0100 Subject: [PATCH 15/45] Revert "change function name from camelcase to python syntactical underlines" This reverts commit 213d231c818523b0bb2dbd2c6534c59400bdc4ce. --- django/didgeridoo/currencies/urls.py | 8 ++++---- django/didgeridoo/currencies/views.py | 8 ++++---- django/didgeridoo/static/js/app.js | 4 ++-- django/didgeridoo/webshop/templates/webshop/base.html | 2 +- django/didgeridoo/webshop/templates/webshop/nav.html | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 0ef97bf..ef9dd3f 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,10 +1,10 @@ from django.conf.urls import url -from currencies.views import currencies, currency_update +from currencies.views import currencies, CurrencyUpdate urlpatterns = [ url(r'^currencies/$', currencies), - url(r'^ajax/currency_update/$', - currency_update, - name='currency_update'), + url(r'^ajax/CurrencyUpdate/$', + CurrencyUpdate, + name='CurrencyUpdate'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 86419ff..0dcd960 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -10,11 +10,11 @@ from currencies.forms import CurrencyForm from django.http import JsonResponse -def currency_update(request): - currency = request.GET.get('currency_update', None) +def CurrencyUpdate(request): + currency = request.GET.get('CurrencyUpdate', None) data = { - 'currency': ExchangeRate.objects.filter( - name__name=currency).latest('date') + 'currency': ExchangeRate_name.objects.get( + currency).id } print('currency: ', currency, 'data: ', data) return JsonResponse(data) diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index e9dea69..90b51bc 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,7 +1,7 @@ - $("#currency_update").change(function () { + $("#CurrencyUpdate").change(function () { var currency = $(this).val(); $.ajax({ - url: '/ajax/currency_update/', + url: '/ajax/CurrencyUpdate/', data: { 'currency': currency }, diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index 58f7905..34177de 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -7,7 +7,7 @@ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- Add additional CSS in static file --> - {% load static %} + {% load staticfiles %} <link rel="stylesheet" href="{{ STATIC_URL }}/static/webshop/css/base.css" /> {% block title %} <title> diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index f009520..aa45224 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -22,7 +22,7 @@ </ul> <form action="" method="POST" novalidate> {% csrf_token %} - <select name="currency_update" id="currency_update" onchange="this.form.submit()"> + <select name="CurrencyUpdate" id="CurrencyUpdate" onchange="this.form.submit()"> <option value="CHF">CHF</option> <option value="USD">USD</option> <option value="GBP">GBP</option> From c7d9e62f0529d47ef1ecf107c4a146215e887c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 22:11:34 +0100 Subject: [PATCH 16/45] again. --- django/didgeridoo/currencies/urls.py | 8 ++++---- django/didgeridoo/currencies/views.py | 8 ++++---- django/didgeridoo/static/js/app.js | 4 ++-- django/didgeridoo/webshop/templates/webshop/nav.html | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index ef9dd3f..0ef97bf 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,10 +1,10 @@ from django.conf.urls import url -from currencies.views import currencies, CurrencyUpdate +from currencies.views import currencies, currency_update urlpatterns = [ url(r'^currencies/$', currencies), - url(r'^ajax/CurrencyUpdate/$', - CurrencyUpdate, - name='CurrencyUpdate'), + url(r'^ajax/currency_update/$', + currency_update, + name='currency_update'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 0dcd960..86419ff 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -10,11 +10,11 @@ from currencies.forms import CurrencyForm from django.http import JsonResponse -def CurrencyUpdate(request): - currency = request.GET.get('CurrencyUpdate', None) +def currency_update(request): + currency = request.GET.get('currency_update', None) data = { - 'currency': ExchangeRate_name.objects.get( - currency).id + 'currency': ExchangeRate.objects.filter( + name__name=currency).latest('date') } print('currency: ', currency, 'data: ', data) return JsonResponse(data) diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index 90b51bc..e9dea69 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,7 +1,7 @@ - $("#CurrencyUpdate").change(function () { + $("#currency_update").change(function () { var currency = $(this).val(); $.ajax({ - url: '/ajax/CurrencyUpdate/', + url: '/ajax/currency_update/', data: { 'currency': currency }, diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index aa45224..f009520 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -22,7 +22,7 @@ </ul> <form action="" method="POST" novalidate> {% csrf_token %} - <select name="CurrencyUpdate" id="CurrencyUpdate" onchange="this.form.submit()"> + <select name="currency_update" id="currency_update" onchange="this.form.submit()"> <option value="CHF">CHF</option> <option value="USD">USD</option> <option value="GBP">GBP</option> From 1f0940a2a6253f96b18700303309b8174e3dc9d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 22:11:57 +0100 Subject: [PATCH 17/45] updated to newer syntax --- django/didgeridoo/webshop/templates/webshop/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index 34177de..58f7905 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -7,7 +7,7 @@ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- Add additional CSS in static file --> - {% load staticfiles %} + {% load static %} <link rel="stylesheet" href="{{ STATIC_URL }}/static/webshop/css/base.css" /> {% block title %} <title> From f44a13cf98fdab18601c51564cbeb66d17357fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 22:50:54 +0100 Subject: [PATCH 18/45] minimal refactoring --- django/didgeridoo/currencies/models.py | 4 ++-- django/didgeridoo/currencies/urls.py | 2 +- django/didgeridoo/currencies/views.py | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index 5ee16ef..a5014f3 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -1,5 +1,4 @@ from django.db import models -from django.core.urlresolvers import reverse from decimal import Decimal import datetime @@ -21,7 +20,8 @@ class ExchangeRate_date(models.Model): class ExchangeRate(models.Model): name = models.ForeignKey(ExchangeRate_name) date = models.ForeignKey(ExchangeRate_date) - exchange_rate_to_chf = models.DecimalField(max_digits=12, decimal_places=5) + exchange_rate_to_chf = models.DecimalField(max_digits=12, + decimal_places=5) def __str__(self): return str(self.name) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 0ef97bf..e34aba9 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url from currencies.views import currencies, currency_update - +from core import views urlpatterns = [ url(r'^currencies/$', currencies), diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 86419ff..06094a2 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -11,11 +11,12 @@ from django.http import JsonResponse def currency_update(request): + # https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html currency = request.GET.get('currency_update', None) - data = { - 'currency': ExchangeRate.objects.filter( - name__name=currency).latest('date') - } + data = ExchangeRate.objects.filter( + name__name=currency + ).values('exchange_rate_to_chf' + ).latest('date__date') print('currency: ', currency, 'data: ', data) return JsonResponse(data) From d74adc65f46e5745159362006c501693ac62a77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 22:54:46 +0100 Subject: [PATCH 19/45] bad --- django/didgeridoo/currencies/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index e34aba9..0ef97bf 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url from currencies.views import currencies, currency_update -from core import views + urlpatterns = [ url(r'^currencies/$', currencies), From 595d02433cb4af39cf8e46fd25054e001b1638d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 23:23:41 +0100 Subject: [PATCH 20/45] handling all post prevents errors. --- django/didgeridoo/currencies/models.py | 4 ++++ django/didgeridoo/currencies/views.py | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index a5014f3..76fb711 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -25,3 +25,7 @@ class ExchangeRate(models.Model): def __str__(self): return str(self.name) + + class Meta: + # https://simpleisbetterthancomplex.com/tips/2016/10/06/django-tip-17-earliest-and-latest.html + get_latest_by = 'name__name' diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 06094a2..f7fbe23 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -12,11 +12,8 @@ from django.http import JsonResponse def currency_update(request): # https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html - currency = request.GET.get('currency_update', None) - data = ExchangeRate.objects.filter( - name__name=currency - ).values('exchange_rate_to_chf' - ).latest('date__date') + currency = request.POST.get('currency_update', None) + data = ExchangeRate.objects.values('exchange_rate_to_chf').latest() print('currency: ', currency, 'data: ', data) return JsonResponse(data) From 7ff173d9c714b904a8ee8bd94f304d5dccc9c213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 23:38:10 +0100 Subject: [PATCH 21/45] yess! --- django/didgeridoo/currencies/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index f7fbe23..5e9b496 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -12,8 +12,15 @@ from django.http import JsonResponse def currency_update(request): # https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html - currency = request.POST.get('currency_update', None) - data = ExchangeRate.objects.values('exchange_rate_to_chf').latest() + if request.method == 'GET': + print('its get method') + else: + print('its not get method') + currency = request.GET.get('currency', None) + data = ExchangeRate.objects.filter( + name__name=currency).values( + 'exchange_rate_to_chf').latest( + 'date__date') print('currency: ', currency, 'data: ', data) return JsonResponse(data) From 2a1a565f9007e8f131d17b6e3476dd8875f132e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 14 Jan 2018 23:39:20 +0100 Subject: [PATCH 22/45] typos --- django/didgeridoo/currencies/models.py | 2 +- django/didgeridoo/currencies/urls.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index 76fb711..9f420fb 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -28,4 +28,4 @@ class ExchangeRate(models.Model): class Meta: # https://simpleisbetterthancomplex.com/tips/2016/10/06/django-tip-17-earliest-and-latest.html - get_latest_by = 'name__name' + get_latest_by = 'name__name' diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index 0ef97bf..aa24648 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,7 +1,6 @@ from django.conf.urls import url from currencies.views import currencies, currency_update - urlpatterns = [ url(r'^currencies/$', currencies), url(r'^ajax/currency_update/$', From fce2f77cb23aa09f4ccd391a0293ab41e0427695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Mon, 15 Jan 2018 00:07:14 +0100 Subject: [PATCH 23/45] add same id as value and name now it pops up because of app.js but does override somehow --- django/didgeridoo/currencies/views.py | 2 +- django/didgeridoo/static/js/app.js | 8 +++----- django/didgeridoo/webshop/templates/webshop/nav.html | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 5e9b496..43c9d29 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -16,7 +16,7 @@ def currency_update(request): print('its get method') else: print('its not get method') - currency = request.GET.get('currency', None) + currency = request.GET.get('currency_update', None) data = ExchangeRate.objects.filter( name__name=currency).values( 'exchange_rate_to_chf').latest( diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index e9dea69..8bf833f 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,15 +1,13 @@ $("#currency_update").change(function () { - var currency = $(this).val(); + var currency_update = $(this).val(); $.ajax({ url: '/ajax/currency_update/', data: { - 'currency': currency + 'currency_update': currency_update }, dataType: 'json', success: function (data) { - if (data.is_taken) { - alert("es pop auf! --dies kommt von: static/js/app.js--."); - } + alert("es pop auf! --dies kommt von: static/js/app.js--.", data); } }); }); diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index f009520..bb3e269 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -28,6 +28,9 @@ <option value="GBP">GBP</option> <option value="JPY">JPY</option> </select> + <ul class="nav navbar-nav"> + {{ form.as_li }} + </ul> </form> </div> </div> From 1a3ff0118fdaae69f2687f7bfddc2b2a84e3a353 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Mon, 15 Jan 2018 19:16:28 +0100 Subject: [PATCH 24/45] update bibliography --- docs/andreas.bib | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/docs/andreas.bib b/docs/andreas.bib index b0a3cdc..c19a1c4 100644 --- a/docs/andreas.bib +++ b/docs/andreas.bib @@ -16,3 +16,93 @@ year = {2016}, } +@misc{removeadd, + month = {{01}}, + note = {{\url{https://stackoverflow.com/a/21454467/7723859}}}, + Urldate = {{2018-01-15}}, + author = {Avinash Garg}, + title = {{How to remove Add button in Django admin, for specific Model?}}, + year = {2014}, +} + +@misc{removedelete, + month = {{08}}, + note = {{\url{https://stackoverflow.com/a/7031093/7723859}}}, + Urldate = {{2018-01-15}}, + author = {Jonathan R.}, + title = {{In Django Admin how do I disable the Delete link}}, + year = {2011}, +} + +@misc{readonly, + month = {{09}}, + note = {{\url{https://stackoverflow.com/a/46124159/7723859}}}, + Urldate = {{2018-01-15}}, + author = {gdlmx}, + title = {{Display a model field as readonly in Django admin}}, + year = {2017}, +} + +@misc{timezone, + month = {{07}}, + note = {{\url{https://stackoverflow.com/a/38239673}}}, + Urldate = {{2018-01-15}}, + author = {Antoine Pinsard}, + title = {{Django: timezone.now vs timezone.now()}}, + year = {2016}, +} + +@misc{usemodel, + month = {{07}}, + note = {{\url{https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html}}}, + Urldate = {{2018-01-15}}, + author = {Vitor Freitas}, + title = {{How to Extend Django User Model}}, + year = {2016}, +} + +@misc{djangogirls, + month = {{10}}, + note = {{\url{https://tutorial.djangogirls.org/en/}}}, + Urldate = {{2018-01-15}}, + author = {DjangoGirls}, + title = {{Django Girls Tutorial}}, + year = {2017}, +} + +@misc{images, + month = {{08}}, + note = {{\url{https://stackoverflow.com/a/1235542}}}, + Urldate = {{2018-01-15}}, + author = {steve}, + title = {{How do I include image files in Django templates?}}, + year = {2009}, +} + +@misc{djangodoc, + month = {{01}}, + note = {{\url{https://docs.djangoproject.com/en/1.11/}}}, + Urldate = {{2018-01-15}}, + author = {Django Foundation}, + title = {{Django documentation}}, + year = {2018}, +} + +@misc{upload, + month = {{12}}, + note = {{\url{https://stackoverflow.com/a/8542030}}}, + Urldate = {{2018-01-15}}, + author = {Akseli Pal{\'{e}}n}, + title = {{Need a minimal Django file upload example [closed]}}, + year = {2011}, +} + +@misc{tree, + month = {{09}}, + note = {{\url{https://stackoverflow.com/a/39729832}}}, + Urldate = {{2018-01-15}}, + author = {ht_}, + title = {{Tree view in django template}}, + year = {2016}, +} + From 9d6c4b308c4ec1fbcc051b856bb62827f18d26e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Tue, 16 Jan 2018 00:54:35 +0100 Subject: [PATCH 25/45] fixed AJAX request and response --- django/didgeridoo/currencies/forms.py | 12 ++++- django/didgeridoo/currencies/views.py | 17 ++++--- django/didgeridoo/static/js/app.js | 20 +++++++- .../webshop/templates/webshop/nav.html | 46 ++++++++++--------- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index f1df52d..38111bd 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -3,5 +3,13 @@ from currencies.models import ExchangeRate_name class CurrencyForm(forms.Form): - currencies = forms.ModelChoiceField( - queryset=ExchangeRate_name.objects.all()) + # https://bradmontgomery.net/blog/2008/11/24/a-simple-django-example-with-ajax/ + currencies = forms.ModelChoiceField( + queryset=ExchangeRate_name.objects.all()) + + CURRENCY_CHOICES = [(t.name, t.name) for t in + ExchangeRate_name.objects.all()] + + type = forms.ChoiceField(choices=CURRENCY_CHOICES, + widget=forms.Select(attrs={ + 'onchange': 'get_vehicle_color();'})) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 43c9d29..a4faae6 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -12,16 +12,15 @@ from django.http import JsonResponse def currency_update(request): # https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html - if request.method == 'GET': - print('its get method') + if request.GET.get('currency_update', None) == 'CHF': + data = {} else: - print('its not get method') - currency = request.GET.get('currency_update', None) - data = ExchangeRate.objects.filter( - name__name=currency).values( - 'exchange_rate_to_chf').latest( - 'date__date') - print('currency: ', currency, 'data: ', data) + currency = request.GET.get('currency_update', None) + data = ExchangeRate.objects.filter( + name__name=currency).values( + 'exchange_rate_to_chf').latest( + 'date__date') + print('currency:', currency, 'data: ', data) return JsonResponse(data) diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index 8bf833f..a9eeae3 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -1,5 +1,6 @@ - $("#currency_update").change(function () { + $("#id_currency_update").change(function () { var currency_update = $(this).val(); + $("#id_currency_update").val(currency_update); $.ajax({ url: '/ajax/currency_update/', data: { @@ -7,7 +8,22 @@ }, dataType: 'json', success: function (data) { - alert("es pop auf! --dies kommt von: static/js/app.js--.", data); + alert("es pop auf! --dies kommt von: static/js/app.js--."); + } }); }); + + //document.getElementById('id_currency_update').getElementsByTagName('currency_update') + //$("#id_currency_update").val('USD').selected = 'selected'; + + //https://stackoverflow.com/a/30489067/4061870 + // var obj = document.getElementById("id_currency_update"); + // for(i=0; i<obj.options.length; i++){ + // if(obj.options[i].value == "USD"){ + // obj.selectedIndex = i; + // } + // } + + // var e document.getElementById("id_currency_update"); + //e.value = currency_update; diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index bb3e269..169d043 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -8,31 +8,35 @@ <ul class="nav navbar-nav"> <li><a href="#">CART</a></li> {% if user.is_authenticated %} - <li> - <a href="{% url 'profile' %}">PROFILE</a> - </li> - <li> - <a href="{% url 'logout' %}">LOGOUT</a> - </li> + <li> + <a href="{% url 'profile' %}">PROFILE</a> + </li> + <li> + <a href="{% url 'logout' %}">LOGOUT</a> + </li> {% else %} - <li> - <a href="{% url 'login' %}">LOGIN</a> - </li> + <li> + <a href="{% url 'login' %}">LOGIN</a> + </li> {% endif %} + <!-- https://pypi.python.org/pypi/django-select-multiple-field --> + <form method="POST" novalidate> + <select name="currency_update" id="id_currency_update"> + <option value="CHF">CHF</option> + <option value="USD">USD</option> + <option value="GBP">GBP</option> + <option value="JPY">JPY</option> + </select> + {% csrf_token %} + </form> </ul> - <form action="" method="POST" novalidate> - {% csrf_token %} - <select name="currency_update" id="currency_update" onchange="this.form.submit()"> - <option value="CHF">CHF</option> - <option value="USD">USD</option> - <option value="GBP">GBP</option> - <option value="JPY">JPY</option> - </select> - <ul class="nav navbar-nav"> - {{ form.as_li }} - </ul> - </form> </div> + <!-- + Es wird auf id im app.js file gemached. + die URL wird im app.js gesetzt + und mit urls.py weitergereicht. + dann auf name im views.py gemached und ausgeführt. + --> </div> </nav> {% endblock %} From 98172c0a8fc028cefa82ecd8ce467d0ca530428c Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 08:37:03 +0100 Subject: [PATCH 26/45] escape an underscore --- docs/andreas.bib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/andreas.bib b/docs/andreas.bib index c19a1c4..0f54c5a 100644 --- a/docs/andreas.bib +++ b/docs/andreas.bib @@ -101,7 +101,7 @@ month = {{09}}, note = {{\url{https://stackoverflow.com/a/39729832}}}, Urldate = {{2018-01-15}}, - author = {ht_}, + author = {ht\_}, title = {{Tree view in django template}}, year = {2016}, } From ed8ca907223b3ddaa0f1bb69b59d9e7df0d73085 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:25:04 +0100 Subject: [PATCH 27/45] correct some typos --- docs/andreas.bib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/andreas.bib b/docs/andreas.bib index 0f54c5a..34315f1 100644 --- a/docs/andreas.bib +++ b/docs/andreas.bib @@ -1,4 +1,4 @@ -@misc{django_extensions, +@misc{djangoextensions, month = {{01}}, note = {{\url{https://github.com/django-extensions/django-extensions}}}, Urldate = {{2018-01-05}}, @@ -52,7 +52,7 @@ year = {2016}, } -@misc{usemodel, +@misc{usermodel, month = {{07}}, note = {{\url{https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html}}}, Urldate = {{2018-01-15}}, From 354c2838e837b13f6fa60aaef40a327a914b0e0a Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:28:03 +0100 Subject: [PATCH 28/45] correct the picture paths I had to correct the paths to the images otherwise the latex compilation would fail because with the old format the images got created as links. --- docs/doku.org | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index e4ced80..05eaf2f 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -546,7 +546,7 @@ Webshops beschränkt. #+CAPTION: Ein frühes Mockup des Shop #+ATTR_LATEX: :width \textwidth #+NAME: mockup -[[file:pictures/mockup-full-snipet.png][file:pictures/mockup-full-snipet.png]] +[[./pictures/mockup-full-snipet.png]] *** TODO Klassendiagramme der Models **** NEXT Category @@ -554,98 +554,97 @@ Webshops beschränkt. #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Kategorien #+NAME: fig:category -[[file:pictures/class_category.png]] +[[./pictures/class_category.png]] **** NEXT Option #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Optionen #+NAME: fig:option -[[file:pictures/class_option.png][file:pictures/class_option.png]] **** NEXT Setting #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Einstellungen #+NAME: fig:umweltgrafik -[[file:pictures/class_setting.png][file:pictures/class_setting.png]] +[[./pictures/class_option.png]] **** NEXT ArticleStatus #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Artikelstatus #+NAME: fig:articlestatus -[[file:pictures/class_articlestatus.png][file:pictures/class_articlestatus.png]] +[[./pictures/class_articlestatus.png]] **** TODO ExchangeRate #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Wechselkurse #+NAME: fig:exchangerate -[[file:pictures/class_exchangerate.png][file:pictures/class_exchangerate.png]] +[[./pictures/class_exchangerate.png]] **** NEXT Article #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Artikel #+NAME: fig:article -[[file:pictures/class_article.png][file:pictures/class_article.png]] +[[./pictures/class_article.png]] **** NEXT OrderStatus #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Bestellstatus #+NAME: fig:orderstatus -[[file:pictures/class_orderstatus.png][file:pictures/class_orderstatus.png]] +[[./pictures/class_orderstatus.png]] **** NEXT OrderOfGoods #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Warenbestellungen #+NAME: fig:orderofgoods -[[file:pictures/class_orderofgoods.png][file:pictures/class_orderofgoods.png]] +[[./pictures/class_orderofgoods.png]] **** NEXT Picture #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Bilder #+NAME: fig:picture -[[file:pictures/class_picture.png][file:pictures/class_picture.png]] +[[./pictures/class_picture.png]] **** NEXT Order #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Bestellungen #+NAME: fig:order -[[file:pictures/class_order.png][file:pictures/class_order.png]] +[[./pictures/class_order.png]] **** NEXT ShoppingCart #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Warenkörbe #+NAME: fig:shoppingcart -[[file:pictures/class_shoppingcart.png][file:pictures/class_shoppingcart.png]] +[[./pictures/class_shoppingcart.png]] **** NEXT City #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Städte #+NAME: fig:city -[[file:pictures/class_city.png][file:pictures/class_city.png]] +[[./pictures/class_city.png]] **** NEXT Salutation #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Anreden #+NAME: fig:salutation -[[file:pictures/class_salutation.png][file:pictures/class_salutation.png]] +[[./pictures/class_salutation.png]] **** NEXT Person #+ATTR_LATEX: :width 9cm #+CAPTION: Klassenmodel für Personen #+NAME: fig:person -[[file:pictures/class_person.png][file:pictures/class_person.png]] +[[./pictures/class_person.png]] ** Benutzerinterface *** Mockup skizzieren From 39afb3ecb8ee63f7a514b78db7c93dccf8a074a9 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:30:51 +0100 Subject: [PATCH 29/45] correct some positions of figures --- docs/doku.org | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index 05eaf2f..407ecba 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -390,7 +390,7 @@ Abbildung: ([[fig:umweltgrafik]]) grafisch dargestellt. *** NEXT Risikobewertung #+CAPTION: Risikobewertung Wahrscheinlichkeit -#+ATTR_LATEX: :align l|l +#+ATTR_LATEX: :align l|l :placement [H] #+NAME: tab:wahrscheinlichkeit | *Bewertung* | *Beschreibung: Warscheinlichkeit (W)* | |-------------+---------------------------------------| @@ -399,7 +399,7 @@ Abbildung: ([[fig:umweltgrafik]]) grafisch dargestellt. | 3 = hoch | Hohe warscheinlichkeit > 50% | #+CAPTION: Risikobewertung Auswirkung -#+ATTR_LATEX: :align l|l +#+ATTR_LATEX: :align l|l :placement [H] #+NAME: tab:auswirkung | *Bewertung* | *Beschreibung: Auswirkung (A)* | |-------------+-------------------------------------------------| @@ -408,7 +408,7 @@ Abbildung: ([[fig:umweltgrafik]]) grafisch dargestellt. | 3 = hoch | Projekt erfüllt nicht alle Anforderungen | #+CAPTION: Grafische Darstellung der Risikoanalyse -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+NAME: fig:risk [[file:diagrammes/risk_analysis.eps]] @@ -551,14 +551,14 @@ Webshops beschränkt. *** TODO Klassendiagramme der Models **** NEXT Category -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Kategorien #+NAME: fig:category [[./pictures/class_category.png]] **** NEXT Option -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Optionen #+NAME: fig:option @@ -571,77 +571,77 @@ Webshops beschränkt. **** NEXT ArticleStatus -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Artikelstatus #+NAME: fig:articlestatus [[./pictures/class_articlestatus.png]] **** TODO ExchangeRate -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Wechselkurse #+NAME: fig:exchangerate [[./pictures/class_exchangerate.png]] **** NEXT Article -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Artikel #+NAME: fig:article [[./pictures/class_article.png]] **** NEXT OrderStatus -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Bestellstatus #+NAME: fig:orderstatus [[./pictures/class_orderstatus.png]] **** NEXT OrderOfGoods -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Warenbestellungen #+NAME: fig:orderofgoods [[./pictures/class_orderofgoods.png]] **** NEXT Picture -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Bilder #+NAME: fig:picture [[./pictures/class_picture.png]] **** NEXT Order -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Bestellungen #+NAME: fig:order [[./pictures/class_order.png]] **** NEXT ShoppingCart -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Warenkörbe #+NAME: fig:shoppingcart [[./pictures/class_shoppingcart.png]] **** NEXT City -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Städte #+NAME: fig:city [[./pictures/class_city.png]] **** NEXT Salutation -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Anreden #+NAME: fig:salutation [[./pictures/class_salutation.png]] **** NEXT Person -#+ATTR_LATEX: :width 9cm +#+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Personen #+NAME: fig:person [[./pictures/class_person.png]] From 4560f130562b294a8e1e57487909237ab0d36328 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:31:17 +0100 Subject: [PATCH 30/45] remove the settings model from the documentation --- docs/doku.org | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index 407ecba..1bb8c97 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -561,12 +561,6 @@ Webshops beschränkt. #+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Optionen #+NAME: fig:option - -**** NEXT Setting - -#+ATTR_LATEX: :width 9cm -#+CAPTION: Klassenmodel für Einstellungen -#+NAME: fig:umweltgrafik [[./pictures/class_option.png]] **** NEXT ArticleStatus From 56e18a9dc43a710fde79788b912f2c24f36158aa Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:31:40 +0100 Subject: [PATCH 31/45] rephrase section title --- docs/doku.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/doku.org b/docs/doku.org index 1bb8c97..2368b71 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -548,7 +548,7 @@ Webshops beschränkt. #+NAME: mockup [[./pictures/mockup-full-snipet.png]] -*** TODO Klassendiagramme der Models +*** TODO Models **** NEXT Category #+ATTR_LATEX: :width 9cm :placement [H] From 11d02f0a3e970b2c9db150d5acf93f60f7fb702c Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:32:02 +0100 Subject: [PATCH 32/45] add citations which where used to create the models --- docs/doku.org | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/doku.org b/docs/doku.org index 2368b71..b85cd19 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -549,15 +549,25 @@ Webshops beschränkt. [[./pictures/mockup-full-snipet.png]] *** TODO Models + +\footcite{djangoextensions} + **** NEXT Category +\footcite{tree} + #+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Kategorien #+NAME: fig:category [[./pictures/class_category.png]] + **** NEXT Option +\footcite{readonly} +\footcite{removeadd} +\footcite{removedelete} + #+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Optionen #+NAME: fig:option @@ -572,6 +582,8 @@ Webshops beschränkt. **** TODO ExchangeRate +\footcite{timezone} + #+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Wechselkurse #+NAME: fig:exchangerate @@ -600,6 +612,9 @@ Webshops beschränkt. **** NEXT Picture +\footcite{upload} +\footcite{images} + #+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Bilder #+NAME: fig:picture @@ -635,6 +650,8 @@ Webshops beschränkt. **** NEXT Person +\footcite{usermodel} + #+ATTR_LATEX: :width 9cm :placement [H] #+CAPTION: Klassenmodel für Personen #+NAME: fig:person From 068ea6f4998555f9b2511d6d274f669b964b7df6 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:32:26 +0100 Subject: [PATCH 33/45] correct section titles --- docs/doku.org | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/doku.org b/docs/doku.org index b85cd19..5aa124c 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -662,10 +662,14 @@ Webshops beschränkt. *** Frontend Umsetzung *** Backend Umsetzung -** Testfälle +** Testing + +*** Fixtures #+LATEX:\newpage #+LATEX:\begin{landscape} +*** Testfälle + #+CAPTION: Testfälle #+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{1.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}| #+NAME: tab:testcases From 05c3becb7a739f8a913b28a823b1df9d232ff064 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Tue, 16 Jan 2018 22:32:39 +0100 Subject: [PATCH 34/45] change the placement of the test cases table --- docs/doku.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/doku.org b/docs/doku.org index 5aa124c..9834b8d 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -671,7 +671,7 @@ Webshops beschränkt. *** Testfälle #+CAPTION: Testfälle -#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{1.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}| +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{1.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}| :placement [H] #+NAME: tab:testcases |----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------| | <20> | <20> | <20> | <20> | <20> | <20> | <20> | <20> | From a6c03b81b9d803d57f5bf0e3a3f2f286d7dec381 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Wed, 17 Jan 2018 22:07:17 +0100 Subject: [PATCH 35/45] add some use cases --- docs/doku.org | 368 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 337 insertions(+), 31 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index 9834b8d..e7352f6 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -508,38 +508,344 @@ Webshops beschränkt. **** NEXT Use Case Detailbeschreibung -#+CAPTION: Use Case -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| +***** Artikel durchstöbern + +#+CAPTION: Use 1.0 Artikel durchstöbern +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:browse_article +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 1.0 Artikel durchstöbern | +|---------------------+--------------------------------| +| *Description* | Durchklicken der verschiedenen Kategorieren und ansehen der Artikel Details und Bilder. | +|---------------------+--------------------------------| +| *Actors* | Kunden, Interessenten | +|---------------------+--------------------------------| +| *Status* | Freigegeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | User möchte Artikel einsehen | +|---------------------+--------------------------------| +| *Preconditions* | Website aufgerufen | +|---------------------+--------------------------------| +| *Postconditions* | - | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Website aufrufen | +| | 2. Kategorienen durchsehen | +| | 3. Artikel anklicken | +|---------------------+--------------------------------| +| *Alternative Flow* | - | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** Registration + +#+CAPTION: Use Case 2.0 Registration +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:registration +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 2.0 Registration | +|---------------------+--------------------------------| +| *Description* | Ein User registriert sich einen Account. | +|---------------------+--------------------------------| +| *Actors* | Interessent | +|---------------------+--------------------------------| +| *Status* | Freigebgen | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | User möchte einen Account erstellen. | +|---------------------+--------------------------------| +| *Preconditions* | Email Adresse vorhanden | +|---------------------+--------------------------------| +| *Postconditions* | Account wurde erfolgreich erstellt. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. User klickt auf den Link "Go to registration.". | +| | 2. User füllt das Registrations Formular aus. | +| | 3. User schliesst die Registrierung mit Klick auf "Register" ab. | +| | 4. Die Website leitet ihn in den Login Bereich um. | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. User klickt auf den Link "Go to registration.". | +| | 2. User füllt das Registrations Formular mir falschen Daten aus. | +| | 3. Die Website gibt die entsprechenden Fehler aus. | +| | 4. Der User korrigiert die Angaben. | +| | 5. User schliesst die Registrierung mit Klick auf "Register" ab. | +| | 6. Die Website leitet ihn in den Login Bereich um. | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** User Login + +#+CAPTION: Use Case 2.1 User Login +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:login -|---------------------+-----------------------------| -| *Identifier + Name* | | -|---------------------+-----------------------------| -| *Description* | | -|---------------------+-----------------------------| -| *Actors* | | -|---------------------+-----------------------------| -| *Status* | Freigegeben | -|---------------------+-----------------------------| -| *Includes* | - | -|---------------------+-----------------------------| -| *Trigger* | | -|---------------------+-----------------------------| -| *Preconditions* | | -|---------------------+-----------------------------| -| *Postconditions* | | -|---------------------+-----------------------------| -| *Normal Flow* | | -|---------------------+-----------------------------| -| *Alternative Flow* | - | -|---------------------+-----------------------------| -| *Notes* | - | -|---------------------+-----------------------------| -| *UC History* | 1.0 Darft erstellt durch AZ | -|---------------------+-----------------------------| -| *Author* | A. Zweili & I. | -|---------------------+-----------------------------| -| *Date* | | -|---------------------+-----------------------------| +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 2.1 User Login | +|---------------------+--------------------------------| +| *Description* | Ein Kunde logt sich auf der Website ein. | +|---------------------+--------------------------------| +| *Actors* | Kunde | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Ein Kunde möchte sich einloggen. | +|---------------------+--------------------------------| +| *Preconditions* | UC 2.0 erfolgreich abgeschlossen. | +|---------------------+--------------------------------| +| *Postconditions* | User hat sich erfolgreich eingeloggt. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. User klickt in der Navigation auf "Login". | +| | 2. User gibt Zugangsdaten ein. | +| | 3. User beendet Login mit Klick auf "Login". | +| | 4. Die Website leitet ihn auf die Index Seite um und zeigt neu eine "Profil" und "Logout" Schaltfläche. | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. User klickt in der Navigation auf "Login". | +| | 2. User gibt falsche Zugangsdaten ein. | +| | 3. User beendet Login mit Klick auf "Login". | +| | 4. Die Website gibt entsprechende Fehlermeldungen aus. | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** Artikel in Warenkorb legen + +#+CAPTION: Use Case 3.0 Artikel in Warenkorb legen +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:cart +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 3.0 Artikel in Warenkorb legen | +|---------------------+--------------------------------| +| *Description* | Ein Kunde legt einen Artikel in den Warenkorb. | +|---------------------+--------------------------------| +| *Actors* | Kunde | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Ein Kunde möchte einen Artikel kaufen. | +|---------------------+--------------------------------| +| *Preconditions* | UC2.1 erfolgreich abgeschlossen. | +|---------------------+--------------------------------| +| *Postconditions* | Artikel wurde im Warenkorb gespeichert. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. User klickt einen Artikel an. | +| | 2. User klickt auf "Add to cart". | +| | 3. Die Website speichert den Artikel im Warenkorb. | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. User klickt einen Artikel mit Stock "0.0" an. | +| | 2. User klickt auf "Add to cart". | +| | 3. Die Website meldet "We are sorry but this item is out of stock.". | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** Währung ändern + +#+CAPTION: Use Case 3.1 Währung ändern +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:currency +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 3.1 Währung ändern | +|---------------------+--------------------------------| +| *Description* | Ein User ändert die Währung für die Preise. | +|---------------------+--------------------------------| +| *Actors* | Kunde, Interessent | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Ein User möchte sich die Preise in einer anderen Währung anzeigen lassen. | +|---------------------+--------------------------------| +| *Preconditions* | - | +|---------------------+--------------------------------| +| *Postconditions* | Die Preise werden in der gewünschten Währung angezeigt. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Der User wählt im Drop-Down die gewünschte Währung aus. | +| | 2. Die Website aktualisiert und zeigt die neu berechneten Preise an. | +|---------------------+--------------------------------| +| *Alternative Flow* | - | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** Checkout + +#+CAPTION: Use Case 3.2 Checkout +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:checkout +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 3.2 Checkout | +|---------------------+--------------------------------| +| *Description* | User gibt seinen Warenkorb als Bestellung auf. | +|---------------------+--------------------------------| +| *Actors* | Kunde | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Ein Kunde möchte seine Artikel im Warenkorb bestellen. | +|---------------------+--------------------------------| +| *Preconditions* | UC2.1 und UC3.0 erfolgreich abgeschlossen. | +|---------------------+--------------------------------| +| *Postconditions* | Die Bestellung wurde von der Website gespeichert. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Der User klickt in der Navigation auf "Cart". | +| | 2. Die Website leitet ihn zum Warenkorb um. | +| | 3. Der User klickt dort auf "Checkout". | +| | 4. Die Website gibt ihm eine komplette Übersicht der Bestellung sowie der Empfängeradresse. | +| | 5. User klickt auf "Send order". | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. Der User klickt in der Navigation auf "Cart". | +| | 2. Die Website leitet ihn zum Warenkorb um. | +| | 3. Der User klickt dort auf "Checkout". | +| | 4. Die Website gibt ihm eine komplette Übersicht der Bestellung sowie der Empfängeradresse. | +| | 5. Der User bricht die Bestellung mit Klick auf "Cancel" ab. | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** User Passwort ändern + +#+CAPTION: 4.0 User Passwort ändern +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:password +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 4.0 User Passwort ändern | +|---------------------+--------------------------------| +| *Description* | Ein Administrator ändert ein User Kennwort. | +|---------------------+--------------------------------| +| *Actors* | Verwaltung | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Ein Administrator möchte ein Passwort zurücksetzen weil es vergessen wurde. | +|---------------------+--------------------------------| +| *Preconditions* | Account mit Administrationsrechten vorhanden. | +|---------------------+--------------------------------| +| *Postconditions* | Auf dem User Account wurde ein neues Passwort gesetzt. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klickt auf "Users". | +| | 3. Admin wählt den passenden Account aus. | +| | 4. Klickt unterhalb des Passwort Hashes auf "this form". | +| | 5. Gibt zweimal das neue Passwort ein und klickt "Change password". | +| | 6. Die Website leitet den Admin zurück zu den User Details. | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klicht auf "Users". | +| | 3. Admin wählt den passenden Account aus. | +| | 4. Klickt unterhalb des Passwort Hashes auf "this form". | +| | 5. Gibt zweimal ein invalides Passwort ein und klickt "Change password". | +| | 6. Die Website gibt eine entsprechende Fehlermeldung aus. | +| | 7. Der Admin korrigiert die Passwörter und klickt auf "Change password". | +| | 8. Die Website leitet den Admin zurück zu den User Details. | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| + +***** Artikel erfassen + +#+CAPTION: 5.0 Artikel erfassen +#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:create_article +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 5.0 Artikel erfassen | +|---------------------+--------------------------------| +| *Description* | Ein Administrator erfasst einen neuen Artikel mit Bildern. | +|---------------------+--------------------------------| +| *Actors* | Verwaltung | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Um das Sortiment zu erweitern möchte der Administrator einen neuen Artikel erfassen. | +|---------------------+--------------------------------| +| *Preconditions* | Account mit Administrationsrechten vorhanden. | +|---------------------+--------------------------------| +| *Postconditions* | Der Artikel wir im Webshop angezeigt. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klickt neben "Articles" auf "+ Add". | +| | 3. Admin füllt das Formular aus und lädt ein Bild hoch. | +| | 4. Klickt unten rechts auf "Save". | +| | 5. Die Website speichert den Artikel in der Datenbank. | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klickt neben "Articles" auf "+ Add". | +| | 3. Admin füllt das Formular aus, vergisst jedoch ein Feld und lädt ein Bild hoch. | +| | 4. Klickt unten rechts auf "Save". | +| | 5. Die Website gibt eine entsprechende Fehlermeldung aus. | +| | 6. Der Admin füllt die Felder aus und klickt auf "Save". | +| | 7. Die Website speichert den Artikel in der Datenbank. | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| *** NEXT Mockup From 56cb4a9a1f9523e5c63559abf8592f69e9a30183 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 19:57:30 +0100 Subject: [PATCH 36/45] add description about the detailed use cases --- docs/doku.org | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/doku.org b/docs/doku.org index e7352f6..bedadd8 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -508,10 +508,44 @@ Webshops beschränkt. **** NEXT Use Case Detailbeschreibung +Use Cases werden in der Regel mit Hilfe einer sogenannten Use Case +Schablone im Detail beschrieben damit klar ist wie der Ablauf jeweils +genau aussieht. Die von uns verwendete Schablone wurde von Alistair +Cockburn definiert. + +Da ein Web-Shop eine sehr umfangreiche Applikation ist gibt es sehr +viele Use Cases welche beschrieben und umgesetzt werden müssen. Aus +zeitlichen Gründen haben wir nur einen kleinen Teil der Use Cases im +Detail ausgearbeitet. Insbesondere diese welche wir selber +ausprogrammiert haben. Die gesamte Liste an Use Cases sieht wie folgt +aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: + +#+LATEX: {\footnotesize +| - 1.0 Artikel durchstöbern | - Kategorie erfassen (Admin Funktion) | +| - 2.0 Registration | - Kategorie ändern (Admin Funktion) | +| - 2.1 User Login | - Kategorie löschen (Admin Funktion) | +| - User Profil ansehen | - Bild hochladen (Admin Funktion) | +| - 3.0 Artikel in Warenkorb legen | - Bild ändern (Admin Funktion) | +| - 3.1 Währung ändern | - Bild löschen (Admin Funktion) | +| - Währung aktualisieren (Admin Funktion) | - Bestellung erfassen (Admin Funktion) | +| - 3.2 Checkout | - 7.0 Bestellung ändern/korrigieren (Admin Funktion) | +| - 4.0 User Passwort ändern (Admin Funktion) | - Bestellung löschen (Admin Funktion) | +| - 5.0 Artikel erfassen (Admin Funktion) | - 6.0 max_pictures Option anpassen (Admin Funktion) | +| - Artikel ändern (Admin Funktion) | - max_pictures Option deaktivieren (Admin Funktion) | +| - Artikel löschen (Admin Funktion) | - User erfassen (Admin Funktion) | +| - Materialbestellung erfassen (Admin Funktion) | - User/Personen Daten ändern (Admin Funktion) | +| - Materialbestellung ändern/korrigieren (Admin Funktion) | - User löschen (Admin Funktion) | +| - Materialbestellung löschen (Admin Funktion) | - User Berechtigungen anpassen (Admin Funktion) | +| - Stadt hinzufügen (Admin Funktion) | | +| - Stadt ändern (Admin Funktion) | | +| - Stadt löschen (Admin Funktion) | | +#+LATEX:} + ***** Artikel durchstöbern +#+LATEX:{\footnotesize #+CAPTION: Use 1.0 Artikel durchstöbern -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX::environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:browse_article |---------------------+--------------------------------| | | <30> | From 18d8a7bce06aed103377eaa21d61877b51ca957e Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 19:58:20 +0100 Subject: [PATCH 37/45] add two additional use cases --- docs/doku.org | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/docs/doku.org b/docs/doku.org index bedadd8..813a314 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -880,6 +880,97 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} + +***** max_pictures Option anpassen + +#+LATEX:{\footnotesize +#+CAPTION: Use Case 6.0 max_pictures Option anpassen +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:max_pictures +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 6.0 max_pictures Option anpassen | +|---------------------+--------------------------------| +| *Description* | Ein Administrator ändert die max_pictures Option. | +|---------------------+--------------------------------| +| *Actors* | Verwaltung | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Ein Administrator möchte die maximale Anzahl Bilder pro Artikel anpassen. | +|---------------------+--------------------------------| +| *Preconditions* | Account mit Administrationsrechten vorhanden. | +|---------------------+--------------------------------| +| *Postconditions* | Der neue Wert wurde von der Website gespeichert. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klickt auf "Options" und anschliessend auf "max_pictures". | +| | 3. Admin ändert den Wert "Value" zu einer Ganzzahl seiner Wahl. | +| | 4. Klickt unten rechts auf "Save". | +| | 5. Die Website speichert den Wert in der Datenbank. | +|---------------------+--------------------------------| +| *Alternative Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klickt auf "Options" und anschliessend auf "max_pictures". | +| | 3. Admin ändert den Wert "Value" zu einer Gleitzahl seiner Wahl. | +| | 4. Klickt unten rechts auf "Save". | +| | 5. Die Website gibt eine entsprechende Fehlermeldung aus. | +| | 6. Der Admin korrigiert den Wert und klickt "Save". | +| | 7. Die Website speichert den Wert in der Datenbank. | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| +#+LATEX:} + +***** Bestellung ändern/korrigieren + +#+LATEX:{\footnotesize +#+CAPTION: Use Case 7.0 Bestellung ändern/korrigieren +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+NAME: tab:change_order +|---------------------+--------------------------------| +| | <30> | +| *Identifier + Name* | 7.0 Bestellung ändern/korrigieren | +|---------------------+--------------------------------| +| *Description* | Ein Administrator korrigiert eine Bestellung. | +|---------------------+--------------------------------| +| *Actors* | Verwaltung | +|---------------------+--------------------------------| +| *Status* | Freigeben | +|---------------------+--------------------------------| +| *Includes* | - | +|---------------------+--------------------------------| +| *Trigger* | Administrator ändert auf Wunsch eines Kunden eine Bestellung. | +|---------------------+--------------------------------| +| *Preconditions* | Account mit Administrationsrechten vorhanden. | +|---------------------+--------------------------------| +| *Postconditions* | Die Bestellung hat eine angepasste Artikel Menge. | +|---------------------+--------------------------------| +| *Normal Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | +| | 2. Admin klickt auf "Orders" und anschliessend auf die passende Order ID. | +| | 3. Admin ändert den Wert "Amount" des ersten Artikels zu 0. | +| | 4. Klickt unten rechts auf "Save". | +| | 5. Die Website speichert die Bestellung in der Datenbank. | +|---------------------+--------------------------------| +| *Alternative Flow* | - | +|---------------------+--------------------------------| +| *Notes* | - | +|---------------------+--------------------------------| +| *UC History* | 1.0 Darft erstellt durch AZ | +|---------------------+--------------------------------| +| *Author* | A. Zweili & I. Hörler | +|---------------------+--------------------------------| +| *Date* | 16.01.2018 | +|---------------------+--------------------------------| +#+LATEX:} *** NEXT Mockup From a185cfd416c2f8bb9fa8a8bbd3b09db50685c7e3 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 19:58:47 +0100 Subject: [PATCH 38/45] change the use case tables to footnotesize and longtable environment --- docs/doku.org | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index 813a314..0f26214 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -579,11 +579,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** Registration +#+LATEX:{\footnotesize #+CAPTION: Use Case 2.0 Registration -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:registration |---------------------+--------------------------------| | | <30> | @@ -623,11 +625,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** User Login +#+LATEX:{\footnotesize #+CAPTION: Use Case 2.1 User Login -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:login |---------------------+--------------------------------| | | <30> | @@ -665,11 +669,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** Artikel in Warenkorb legen +#+LATEX:{\footnotesize #+CAPTION: Use Case 3.0 Artikel in Warenkorb legen -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:cart |---------------------+--------------------------------| | | <30> | @@ -705,11 +711,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** Währung ändern +#+LATEX:{\footnotesize #+CAPTION: Use Case 3.1 Währung ändern -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:currency |---------------------+--------------------------------| | | <30> | @@ -742,11 +750,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** Checkout +#+LATEX:{\footnotesize #+CAPTION: Use Case 3.2 Checkout -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:checkout |---------------------+--------------------------------| | | <30> | @@ -786,11 +796,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** User Passwort ändern +#+LATEX:{\footnotesize #+CAPTION: 4.0 User Passwort ändern -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:password |---------------------+--------------------------------| | | <30> | @@ -834,11 +846,13 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Date* | 16.01.2018 | |---------------------+--------------------------------| +#+LATEX:} ***** Artikel erfassen +#+LATEX:{\footnotesize #+CAPTION: 5.0 Artikel erfassen -#+ATTR_LATEX: :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] +#+ATTR_LATEX: :environment longtable :align |>{\columncolor[HTML]{EFEFEF}}p{.25\textwidth}|p{.7\textwidth}| :placement [H] #+NAME: tab:create_article |---------------------+--------------------------------| | | <30> | From c41c52817b6a90cbbe4177e5118b6d91252bca61 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 19:59:07 +0100 Subject: [PATCH 39/45] change the "Artikel erfassen" erfassen --- docs/doku.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index 0f26214..6400ef8 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -880,10 +880,10 @@ aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: |---------------------+--------------------------------| | *Alternative Flow* | 1. Der Administrator loggt sich unter https://didgeridoo.ml/admin ein. | | | 2. Admin klickt neben "Articles" auf "+ Add". | -| | 3. Admin füllt das Formular aus, vergisst jedoch ein Feld und lädt ein Bild hoch. | +| | 3. Admin füllt das Formular aus und lädt zuviele Bilder hoch. | | | 4. Klickt unten rechts auf "Save". | | | 5. Die Website gibt eine entsprechende Fehlermeldung aus. | -| | 6. Der Admin füllt die Felder aus und klickt auf "Save". | +| | 6. Der Admin entfernt die überzähligen Bilder. | | | 7. Die Website speichert den Artikel in der Datenbank. | |---------------------+--------------------------------| | *Notes* | - | From ec70a30b3cfd4546dcfc1b72bfaa84fbfdf32a76 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 20:05:28 +0100 Subject: [PATCH 40/45] add german language to the document --- docs/doku.org | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/doku.org b/docs/doku.org index 6400ef8..e3574ab 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -5,6 +5,7 @@ #+LATEX_CLASS_OPTIONS: [a4paper,11pt] #+LaTeX_HEADER: \input{style} #+OPTIONS: H:5 todo:t +#+LANGUAGE: de #+STARTUP: align From d4105e1a1d7969df85fba70740be1a9717846422 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 20:11:56 +0100 Subject: [PATCH 41/45] remove todo states --- docs/doku.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index e3574ab..c913ae3 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -476,7 +476,7 @@ Als Interessent möchte ich... - die Preise in einer anderen Währung anzeigen können um die Preise in einer mir bekannten Währung vergleichen zu können. -*** TODO Use Cases +*** Use Cases Ein Use Case sammelt alle möglichen Szenarien, die eintreten können, wenn ein Akteur versucht, mit Hilfe des betrachteten Systems ein @@ -507,7 +507,7 @@ Webshops beschränkt. #+LATEX:\end{landscape} #+LATEX:\newpage -**** NEXT Use Case Detailbeschreibung +**** Use Case Detailbeschreibung Use Cases werden in der Regel mit Hilfe einer sogenannten Use Case Schablone im Detail beschrieben damit klar ist wie der Ablauf jeweils From d7d6e709401859f78526ced843f605008ef80fc6 Mon Sep 17 00:00:00 2001 From: Andreas Zweili <andreas@2li.ch> Date: Thu, 18 Jan 2018 20:12:16 +0100 Subject: [PATCH 42/45] add links from the use cases list to the actuall use case --- docs/doku.org | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/doku.org b/docs/doku.org index c913ae3..7150df6 100644 --- a/docs/doku.org +++ b/docs/doku.org @@ -522,16 +522,16 @@ ausprogrammiert haben. Die gesamte Liste an Use Cases sieht wie folgt aus, die Use Cases mit den Nummern wurden dabei im Detail ausgearbeitet: #+LATEX: {\footnotesize -| - 1.0 Artikel durchstöbern | - Kategorie erfassen (Admin Funktion) | -| - 2.0 Registration | - Kategorie ändern (Admin Funktion) | -| - 2.1 User Login | - Kategorie löschen (Admin Funktion) | +| - [[*Artikel durchst%C3%B6bern][1.0 Artikel durchstöbern]] | - Kategorie erfassen (Admin Funktion) | +| - [[Registration][2.0 Registration]] | - Kategorie ändern (Admin Funktion) | +| - [[User Login][2.1 User Login]] | - Kategorie löschen (Admin Funktion) | | - User Profil ansehen | - Bild hochladen (Admin Funktion) | -| - 3.0 Artikel in Warenkorb legen | - Bild ändern (Admin Funktion) | -| - 3.1 Währung ändern | - Bild löschen (Admin Funktion) | +| - [[Artikel in Warenkorb legen][3.0 Artikel in Warenkorb legen]] | - Bild ändern (Admin Funktion) | +| - [[W%C3%A4hrung %C3%A4ndern][3.1 Währung ändern]] | - Bild löschen (Admin Funktion) | | - Währung aktualisieren (Admin Funktion) | - Bestellung erfassen (Admin Funktion) | -| - 3.2 Checkout | - 7.0 Bestellung ändern/korrigieren (Admin Funktion) | -| - 4.0 User Passwort ändern (Admin Funktion) | - Bestellung löschen (Admin Funktion) | -| - 5.0 Artikel erfassen (Admin Funktion) | - 6.0 max_pictures Option anpassen (Admin Funktion) | +| - [[Checkout][3.2 Checkout]] | - [[Bestellung %C3%A4ndern/korrigieren][7.0 Bestellung ändern/korrigieren (Admin Funktion)]] | +| - [[User Passwort %C3%A4ndern][4.0 User Passwort ändern (Admin Funktion)]] | - Bestellung löschen (Admin Funktion) | +| - [[Artikel erfassen][5.0 Artikel erfassen (Admin Funktion)]] | - [[max_pictures Option anpassen][6.0 max_pictures Option anpassen (Admin Funktion)]] | | - Artikel ändern (Admin Funktion) | - max_pictures Option deaktivieren (Admin Funktion) | | - Artikel löschen (Admin Funktion) | - User erfassen (Admin Funktion) | | - Materialbestellung erfassen (Admin Funktion) | - User/Personen Daten ändern (Admin Funktion) | From b53f52cac1d7103d3b53b1a8acc8eda4d2a0b102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Fri, 19 Jan 2018 15:40:55 +0100 Subject: [PATCH 43/45] a work in progress test of custom filters --- django/didgeridoo/currencies/forms.py | 4 ---- .../currencies/templatetags/customfilters.py | 11 +++++++++++ django/didgeridoo/static/js/app.js | 3 ++- .../didgeridoo/webshop/templates/webshop/index.html | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 django/didgeridoo/currencies/templatetags/customfilters.py diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 38111bd..2dcee6a 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -9,7 +9,3 @@ class CurrencyForm(forms.Form): CURRENCY_CHOICES = [(t.name, t.name) for t in ExchangeRate_name.objects.all()] - - type = forms.ChoiceField(choices=CURRENCY_CHOICES, - widget=forms.Select(attrs={ - 'onchange': 'get_vehicle_color();'})) diff --git a/django/didgeridoo/currencies/templatetags/customfilters.py b/django/didgeridoo/currencies/templatetags/customfilters.py new file mode 100644 index 0000000..5831f92 --- /dev/null +++ b/django/didgeridoo/currencies/templatetags/customfilters.py @@ -0,0 +1,11 @@ +from django import template + + +register = template.Library() + + +@register.filter() +def boldcoffee(value): + return '%s !!gefiltert!!' % value + + # excample filter: {{ article.price_in_chf|boldcoffee }} diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index a9eeae3..fefddab 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -8,7 +8,8 @@ }, dataType: 'json', success: function (data) { - alert("es pop auf! --dies kommt von: static/js/app.js--."); + var foo = jQuery.parseJSON(data); + alert("es pop auf! --dies kommt von: static/js/app.js--." + foo.currency_update); } }); diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 71484e3..ec938cb 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,5 +1,5 @@ {% extends "webshop/base.html" %} - +{% load customfilters %} {% block section_title %}Articles{% endblock %} {% block content %} @@ -22,7 +22,7 @@ </td> <td scope="col">{{ article.category }}</td> <td scope="col">{{ article.stock }}</td> - <td scope="col">{{ article.price_in_chf }}</td> + <td scope="col">{{ article.price_in_chf|boldcoffee }}</td> </tr> {% endfor %} </table> From dba76057b3227db77394ca869de83ee87340b01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 21 Jan 2018 21:31:26 +0100 Subject: [PATCH 44/45] added new generic rss fetch and parse functions and setup to store not only today value but all values in file and update if new are available. --- .../didgeridoo/currencies/exchange_rates.py | 197 +++++++----------- .../currencies/migrations/__init__.py | 0 .../currencies/templatetags/customfilters.py | 1 + django/didgeridoo/currencies/views.py | 174 +++++++++------- .../didgeridoo/webshop/migrations/__init__.py | 0 .../webshop/templates/webshop/index.html | 2 +- 6 files changed, 184 insertions(+), 190 deletions(-) delete mode 100644 django/didgeridoo/currencies/migrations/__init__.py delete mode 100644 django/didgeridoo/webshop/migrations/__init__.py diff --git a/django/didgeridoo/currencies/exchange_rates.py b/django/didgeridoo/currencies/exchange_rates.py index 05c279f..7e7cfd9 100644 --- a/django/didgeridoo/currencies/exchange_rates.py +++ b/django/didgeridoo/currencies/exchange_rates.py @@ -11,134 +11,99 @@ Key:Value pairs of new currencys. """ -def get_exchange_rate(): - # zweitweise kann die resource nicht geladen werden. - # https://stackoverflow.com/a/43523497/4061870 - # During weekends there are no updates. - # To develop i need a testresource. - # In that case i comment the Online Resource block and uncomment the - # development Block... - - # ~~~~~~~~~~~~~~~~~~~~~ - # Online Resource block: - # ~~~~~~~~~~~~~~~~~~~~~ - today = datetime.now().strftime("%Y-%m-%d") - SNB_URL = 'https://www.snb.ch/selector/de/mmr/exfeed/rss' +def get_rss(url): urlsocket = '' try: - urlsocket = urllib.request.urlopen(SNB_URL) + urlsocket = urllib.request.urlopen(url) + return(urlsocket) except urllib.error.URLError as e: print('err: urllib.request.urlopen: ', e.reason) + + +def parse_rss(urlsocket): if urlsocket: root = ET.parse(urlsocket) - root = ET.ElementTree(root) - # ~~~~~~~~~~~~~~~~~~~~~ - # development block: - # ~~~~~~~~~~~~~~~~~~~~~ - # today = "2018-01-08" - # try: - # root = ET.ElementTree(file='rss') - # except Exception as e: - # print('exchange_rates.py_urlsocket failed %s ( - # %s) on date: %s for %s' - # % (e, type(e), root)) - # ~~~~~~~~~~~~~~~~~~~~~ + rss_tree = ET.ElementTree(root) + return(rss_tree) - # Namespaces - ns = {'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', - 'none': 'http://purl.org/rss/1.0/', - 'dc': 'http://purl.org/dc/elements/1.1/', - 'dcterms': 'http://purl.org/dc/terms/', - 'cb': 'http://www.cbwiki.net/wiki/index.php/Specification_1.2/' - } - # Pathvariables to XML Namespaces - rate_path = 'cb:statistics/cb:exchangeRate/' - observation_path = 'cb:statistics/cb:exchangeRate/cb:observation/' - exchange_rates = {} - for item in root.findall('none:item', ns): - # for eatch item n the list we grab the release date - # to evaluate if its fresh data or old: - # THE CURRENCY DATE: - datetime_str = item.find('dc:date', ns).text - # convert string to date object: - # https://stackoverflow.com/a/12282040/4061870 - # seams like snb striked the microsecond somewhere - # between Nov. and Dez. 2017 so maybe first check - # time type is with milliseconds: +def get_exchange_rate(rss_tree, ns): + # Pathvariables to XML Namespaces with + rate_path = 'cb:statistics/cb:exchangeRate/' + observation_path = 'cb:statistics/cb:exchangeRate/cb:observation/' + exchange_rates = [] + + for item in rss_tree.findall('none:item', ns): + datetime_str = item.find('dc:date', ns).text + try: + date = datetime.strptime(''.join( + datetime_str.rsplit(':', 1)), + "%Y-%m-%dT%H:%M:%S%z").strftime( + "%Y-%m-%d") + except Exception as e: + print('%s (%s)' % (e, type(e))) try: date = datetime.strptime(''.join( datetime_str.rsplit(':', 1)), - "%Y-%m-%dT%H:%M:%S%z").strftime( + "%Y-%m-%dT%H:%M:%S.%f%z").strftime( "%Y-%m-%d") + continue except Exception as e: print('%s (%s)' % (e, type(e))) - try: - date = datetime.strptime(''.join( - datetime_str.rsplit(':', 1)), - "%Y-%m-%dT%H:%M:%S.%f%z").strftime( - "%Y-%m-%d") - continue - except Exception as e: - print('%s (%s)' % (e, type(e))) - continue - # Print dates for development: - # print("date:", date, "today:", today) - # only the values of today are used so check for date in XML: - if date == today: - # now search for the currency exchange rate: - target_currency = item.find(rate_path + - 'cb:targetCurrency', ns).text - value = float(item.find(observation_path + - 'cb:value', ns).text) - value = float(value) # convert to float - foreign_value = value # copy to new value to have both. - - if item.find(observation_path + 'cb:unit_mult', ns) is None: - # because it's dangerous to check for present, - # i check for none here and have to set the target - # to 1. as im multiplying it later. - unit_mult = float("1.0") - else: - # shift left by 2 digits with "/" - # https://stackoverflow.com/questions/8362792/ - # because some currencys differ widly from CHF - unit_mult = item.find(observation_path + - 'cb:unit_mult', ns).text - # unit_mult defaults to '0' so we check for 8 decimal - # values (2..-6) they represent the fracton value to - # calculate the correct decimalpoint. - if unit_mult == '2': # thinking of Bitcoins - unit_mult = '0.01' - if unit_mult == '1': - unit_mult = '0.10' - if unit_mult == '-1': - unit_mult = '10' - if unit_mult == '-2': # Japan Yen - unit_mult = '100' - if unit_mult == '-3': - unit_mult = '1000' - if unit_mult == '-4': - unit_mult = '10000' - if unit_mult == '-5': - unit_mult = '100000' - if unit_mult == '-6': # indian rupies - unit_mult = '1000000' - unit_mult = float(unit_mult) # convert to float - # calculate the Currency to CHF: - foreign_value = 1 / value - foreign_value *= unit_mult - value = value / unit_mult - # truncate it to decimal values provided by the xml: - foreign_value_round = round(foreign_value, 5) - # Print nice setup of all calculated currencys for development: - # print("date:", date, " 1 ", target_currency, " costs: ", - # CHFvalue, "CHF and 1 ", base_currency, " costs: ", - # FOREIGNvalue_round, target_currency) - exchange_rates.update( - {target_currency: foreign_value_round}) - # Print the Dictionary: - # print(exchange_rates) - else: continue - return(exchange_rates, today) + # now search for the currency exchange rate: + target_currency = item.find(rate_path + + 'cb:targetCurrency', ns).text + value = float(item.find(observation_path + + 'cb:value', ns).text) + value = float(value) # convert to float + foreign_value = value # copy to new value to have both. + + if item.find(observation_path + 'cb:unit_mult', ns) is None: + # because it's dangerous to check for present, + # i check for none here and have to set the target + # to 1. as im multiplying it later. + unit_mult = float("1.0") + else: + # shift left by 2 digits with "/" + # https://stackoverflow.com/questions/8362792/ + # because some currencys differ widly from CHF + unit_mult = item.find(observation_path + + 'cb:unit_mult', ns).text + # unit_mult defaults to '0' so we check for 8 decimal + # values (2..-6) they represent the fracton value to + # calculate the correct decimalpoint. + if unit_mult == '2': # thinking of Bitcoins + unit_mult = '0.01' + if unit_mult == '1': + unit_mult = '0.10' + if unit_mult == '-1': + unit_mult = '10' + if unit_mult == '-2': # Japan Yen + unit_mult = '100' + if unit_mult == '-3': + unit_mult = '1000' + if unit_mult == '-4': + unit_mult = '10000' + if unit_mult == '-5': + unit_mult = '100000' + if unit_mult == '-6': # indian rupies + unit_mult = '1000000' + unit_mult = float(unit_mult) # convert to float + # calculate the Currency to CHF: + foreign_value = 1 / value + foreign_value *= unit_mult + value = value / unit_mult + # truncate it to decimal values provided by the xml: + foreign_value_round = round(foreign_value, 5) + # Print nice setup of all calculated currencys for development: + # print("date:", date, " 1 ", target_currency, " costs: ", + # CHFvalue, "CHF and 1 ", base_currency, " costs: ", + # FOREIGNvalue_round, target_currency) + data = [{'date': date, + 'currency': target_currency, + 'exchangerate': foreign_value_round}] + exchange_rates.append(data) + # Print the Dictionary: + print(exchange_rates) + return(exchange_rates) diff --git a/django/didgeridoo/currencies/migrations/__init__.py b/django/didgeridoo/currencies/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django/didgeridoo/currencies/templatetags/customfilters.py b/django/didgeridoo/currencies/templatetags/customfilters.py index 5831f92..a30e2ab 100644 --- a/django/didgeridoo/currencies/templatetags/customfilters.py +++ b/django/didgeridoo/currencies/templatetags/customfilters.py @@ -6,6 +6,7 @@ register = template.Library() @register.filter() def boldcoffee(value): + # currency_of_customer = request.session['currency'] return '%s !!gefiltert!!' % value # excample filter: {{ article.price_in_chf|boldcoffee }} diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index a4faae6..6da8f88 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -import datetime +from datetime import datetime from django.views.generic.edit import UpdateView from django.core.urlresolvers import reverse_lazy from currencies.models import (ExchangeRate, @@ -25,82 +25,111 @@ def currency_update(request): def currencies(request): - # this function fetches the data from exchange_rates.py - # evaluates if the values are already stored and - # prepares the view all dynamicaly. - # It can grow in terms of more Currencies over time automaticaly. - today = '' - raw_data = [] + + """this function fetches the data from swiss national bank + evaluates if the values are already stored and + prepares a view all dynamicaly. + It can grow in terms of more Currencies over time automaticaly.""" + + # Namespaces + ns = {'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + 'none': 'http://purl.org/rss/1.0/', + 'dc': 'http://purl.org/dc/elements/1.1/', + 'dcterms': 'http://purl.org/dc/terms/', + 'cb': 'http://www.cbwiki.net/wiki/index.php/Specification_1.2/' + } + SNB_URL = 'https://www.snb.ch/selector/de/mmr/exfeed/rss' try: - raw_data, today = exchange_rates.get_exchange_rate() + urlsocket = exchange_rates.get_rss(SNB_URL) except Exception as e: - print('views raw_data: ', raw_data, 'error:', e) # assert False - message_no = "Already querried today: " + print('currencies/views get_rss(): ', urlsocket, 'error:', e) + try: + rss_tree = exchange_rates.parse_rss(urlsocket) + except Exception as e: + print('currencies/views parse_rss(): ', rss_tree, 'error:', e) + try: + raw_data = exchange_rates.get_exchange_rate(rss_tree, ns) + except Exception as e: + print('currencies/views get_exchange_rate(): ', raw_data, 'error:', e) + + today = datetime.now().strftime("%Y-%m-%d") + + message_no = "Already querried: " + length_of_message_no = len(message_no) message_yes = " Updated successfully: " + length_of_message_yes = len(message_yes) # raw_data can be empty. In this case skip: if raw_data: - # if raw_data is not empty iterate over items in it: - for currency, rate in raw_data.items(): - # check for already existing exrates per day and add - # to message that its already been saved. - if ExchangeRate.objects.filter( - date__date=today, - name__name=currency): - message_no += currency + ", " - else: - if ExchangeRate_date.objects.filter(date=today)[:1]: - # if data and currency is not yet present, save it. - try: - # A: https://stackoverflow.com/a/27802801/4061870 - # lustigerweise gibt .values() den value und die id - # zurück. Ohne .values() gibts nur den "value" - date_dict = ExchangeRate_date.objects.filter( - date=today).values() - except Exception as e: - print('exdate_exists %s (%s) on %s' - % (e, type(e), today)) + for one_obj_of_list in raw_data: + for exchange_rate_of_one_day in one_obj_of_list: + date = exchange_rate_of_one_day['date'] + currency = exchange_rate_of_one_day['currency'] + exchangerate = exchange_rate_of_one_day['exchangerate'] + # check for already existing exrates per day and add + # to message that its already been saved. + if ExchangeRate.objects.filter( + date__date=date, + name__name=currency): + message_no += currency + ' on ' + date + ", " else: + if ExchangeRate_date.objects.filter(date=date)[:1]: + # if data and currency is not yet present, save it. + try: + # A: https://stackoverflow.com/a/27802801/4061870 + # lustigerweise gibt .values() den value und die id + # zurück. Ohne .values() gibts nur den "value" + date_dict = ExchangeRate_date.objects.filter( + date=date).values() + except Exception as e: + print('currencies/views/exdate_exists \ + %s (%s) on %s' + % (e, type(e), today)) + else: + try: + exdate = ExchangeRate_date.objects.create( + date=date) + exdate.save() + except Exception as e: + print('currencies/views/exdate_not_exists \ + %s (%s) for %s' + % (e, type(e), date)) + if ExchangeRate_name.objects.filter( + name=currency)[:1]: + # if data and currency is not yet present, save it. + try: + name_dict = ExchangeRate_name.objects.filter( + name=currency).values() + except Exception as e: + print('currencies/views/exname_exists \ + %s (%s) on %s' + % (e, type(e), currency)) + else: + try: + exname = ExchangeRate_name.objects.create( + name=currency) + exname.save() + except Exception as e: + print('currencies/views/exname_not_exists \ + %s (%s) on %s' + % (e, type(e), currency)) try: - exdate = ExchangeRate_date.objects.create( - date=today) - exdate.save() - except Exception as e: - print('exdate_not_exists %s (%s) for %s' - % (e, type(e), today)) - if ExchangeRate_name.objects.filter( - name=currency)[:1]: - # if data and currency is not yet present, save it. - try: - name_dict = ExchangeRate_name.objects.filter( - name=currency).values() - except Exception as e: - print('exname_exists %s (%s) on %s' - % (e, type(e), currency)) - else: - try: - exname = ExchangeRate_name.objects.create( - name=currency) - exname.save() - except Exception as e: - print('exname_not_exists %s (%s) on %s' - % (e, type(e), currency)) - try: - # save item to where id's match. - exrate = ExchangeRate.objects.create( - # name_id=name_id, - name_id=ExchangeRate_name.objects.get( - name=currency).id, - # date_id=date_id, - date_id=ExchangeRate_date.objects.get( - date=today).id, - exchange_rate_to_chf=rate, - ) - exrate.save() - message_yes += currency + ", " + # save item to where id's match. + exrate = ExchangeRate.objects.create( + # name_id=name_id, + name_id=ExchangeRate_name.objects.get( + name=currency).id, + # date_id=date_id, + date_id=ExchangeRate_date.objects.get( + date=date).id, + exchange_rate_to_chf=exchangerate, + ) + exrate.save() + message_yes += currency + ' on ' + date + ", " - except Exception as e: - print('exrate_create %s (%s) on %s for %s' - % (e, type(e), currency, today)) + except Exception as e: + print('currencies/views/exrate_create \ + %s (%s) on %s for %s' + % (e, type(e), currency, date)) # prepare messages: # python can not swap a char insinde a sting so i have @@ -112,11 +141,12 @@ def currencies(request): message_yes = message_yes.replace(",", "!", 1) # replace f. , with ! message_yes = message_yes[::-1] # invert the string back # here we evaluate what kind of message is valid: - if len(message_no) > 24 and len(message_yes) > 23: + if len(message_no) > length_of_message_no\ + and len(message_yes) > length_of_message_yes: message = message_no + message_yes elif len(message_no) > 24: message = message_no - elif len(message_yes) > 23: + elif len(message_yes) > 18: message = message_yes elif datetime.datetime.today().isoweekday() == 6: message = """Die Abfrage wurde ohne ergebniss beendet. @@ -130,8 +160,6 @@ def currencies(request): """ else: message = """Die Abfrage wurde ohne ergebniss beendet. - Kann es sein dass die SNB aufgrund eines Feiertages - geschlossen ist? """ # know we can query our data for presentaton: currency_list = ExchangeRate.objects.all() diff --git a/django/didgeridoo/webshop/migrations/__init__.py b/django/didgeridoo/webshop/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index ec938cb..4d13d5b 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -22,7 +22,7 @@ </td> <td scope="col">{{ article.category }}</td> <td scope="col">{{ article.stock }}</td> - <td scope="col">{{ article.price_in_chf|boldcoffee }}</td> + <td scope="col">{{ article.price_in_chf }}</td> </tr> {% endfor %} </table> From 2f940e57c7b573101bf8ff089028e1adbf122f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= <i.hoerler@me.com> Date: Sun, 21 Jan 2018 22:47:14 +0100 Subject: [PATCH 45/45] getting rid of clutter. --- django/didgeridoo/currencies/forms.py | 11 ----------- django/didgeridoo/currencies/models.py | 4 ---- django/didgeridoo/currencies/views.py | 2 -- 3 files changed, 17 deletions(-) delete mode 100644 django/didgeridoo/currencies/forms.py diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py deleted file mode 100644 index 2dcee6a..0000000 --- a/django/didgeridoo/currencies/forms.py +++ /dev/null @@ -1,11 +0,0 @@ -from django import forms -from currencies.models import ExchangeRate_name - - -class CurrencyForm(forms.Form): - # https://bradmontgomery.net/blog/2008/11/24/a-simple-django-example-with-ajax/ - currencies = forms.ModelChoiceField( - queryset=ExchangeRate_name.objects.all()) - - CURRENCY_CHOICES = [(t.name, t.name) for t in - ExchangeRate_name.objects.all()] diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index 9f420fb..a5014f3 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -25,7 +25,3 @@ class ExchangeRate(models.Model): def __str__(self): return str(self.name) - - class Meta: - # https://simpleisbetterthancomplex.com/tips/2016/10/06/django-tip-17-earliest-and-latest.html - get_latest_by = 'name__name' diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 6da8f88..33cabe1 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -1,12 +1,10 @@ from django.shortcuts import render from datetime import datetime from django.views.generic.edit import UpdateView -from django.core.urlresolvers import reverse_lazy from currencies.models import (ExchangeRate, ExchangeRate_date, ExchangeRate_name) from currencies import exchange_rates -from currencies.forms import CurrencyForm from django.http import JsonResponse