From aaafe1d0b45fc96ae39eda82093ea59dd14104ee Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 24 Dec 2019 14:41:49 +0100 Subject: [PATCH] Some things --- .gitmodules | 3 + auction/__init__.py | 0 auction/admin.py | 10 +++ auction/apps.py | 5 ++ auction/migrations/0001_initial.py | 25 ++++++ .../0002_clientprofile_partnerprofile.py | 30 +++++++ auction/migrations/0003_auto_20191222_2310.py | 87 +++++++++++++++++++ auction/migrations/0004_auto_20191222_2318.py | 19 ++++ auction/migrations/__init__.py | 0 auction/models.py | 49 +++++++++++ auction/tests.py | 3 + auction/views.py | 3 + dbsettings | 1 + packages.txt | 3 + payment/__init__.py | 0 payment/admin.py | 7 ++ payment/apps.py | 5 ++ payment/migrations/0001_initial.py | 20 +++++ payment/migrations/0002_auto_20191222_2018.py | 71 +++++++++++++++ payment/migrations/0003_auto_20191222_2048.py | 20 +++++ payment/migrations/0004_auto_20191222_2120.py | 29 +++++++ payment/migrations/__init__.py | 0 payment/models.py | 46 ++++++++++ payment/tests.py | 3 + payment/views.py | 3 + requirements.txt | 8 ++ urlaubsauktion/settings.py | 8 +- 27 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 100644 auction/__init__.py create mode 100644 auction/admin.py create mode 100644 auction/apps.py create mode 100644 auction/migrations/0001_initial.py create mode 100644 auction/migrations/0002_clientprofile_partnerprofile.py create mode 100644 auction/migrations/0003_auto_20191222_2310.py create mode 100644 auction/migrations/0004_auto_20191222_2318.py create mode 100644 auction/migrations/__init__.py create mode 100644 auction/models.py create mode 100644 auction/tests.py create mode 100644 auction/views.py create mode 160000 dbsettings create mode 100644 packages.txt create mode 100644 payment/__init__.py create mode 100644 payment/admin.py create mode 100644 payment/apps.py create mode 100644 payment/migrations/0001_initial.py create mode 100644 payment/migrations/0002_auto_20191222_2018.py create mode 100644 payment/migrations/0003_auto_20191222_2048.py create mode 100644 payment/migrations/0004_auto_20191222_2120.py create mode 100644 payment/migrations/__init__.py create mode 100644 payment/models.py create mode 100644 payment/tests.py create mode 100644 payment/views.py create mode 100644 requirements.txt diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7a1601e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dbsettings"] + path = dbsettings + url = git@kumig.it:kumisystems/dbsettings.git diff --git a/auction/__init__.py b/auction/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/auction/admin.py b/auction/admin.py new file mode 100644 index 0000000..49959ed --- /dev/null +++ b/auction/admin.py @@ -0,0 +1,10 @@ +from django.contrib import admin + +from auction.models import Inquiry, Profile, PartnerProfile, ClientProfile + +# Register your models here. + +admin.site.register(Inquiry) +admin.site.register(Profile) +admin.site.register(PartnerProfile) +admin.site.register(ClientProfile) diff --git a/auction/apps.py b/auction/apps.py new file mode 100644 index 0000000..5aa79fd --- /dev/null +++ b/auction/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + +class AuctionConfig(AppConfig): + name = 'auction' + diff --git a/auction/migrations/0001_initial.py b/auction/migrations/0001_initial.py new file mode 100644 index 0000000..2d640f4 --- /dev/null +++ b/auction/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.6 on 2019-12-22 21:20 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Inquiry', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('amount', models.DecimalField(decimal_places=2, max_digits=25)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/auction/migrations/0002_clientprofile_partnerprofile.py b/auction/migrations/0002_clientprofile_partnerprofile.py new file mode 100644 index 0000000..b5893ff --- /dev/null +++ b/auction/migrations/0002_clientprofile_partnerprofile.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.6 on 2019-12-22 22:05 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('auction', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='PartnerProfile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='ClientProfile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/auction/migrations/0003_auto_20191222_2310.py b/auction/migrations/0003_auto_20191222_2310.py new file mode 100644 index 0000000..a920c98 --- /dev/null +++ b/auction/migrations/0003_auto_20191222_2310.py @@ -0,0 +1,87 @@ +# Generated by Django 2.2.6 on 2019-12-22 23:10 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django_countries.fields +import phonenumber_field.modelfields +import vies.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('auction', '0002_clientprofile_partnerprofile'), + ] + + operations = [ + migrations.AlterModelOptions( + name='clientprofile', + options={'base_manager_name': 'objects'}, + ), + migrations.AlterModelOptions( + name='partnerprofile', + options={'base_manager_name': 'objects'}, + ), + migrations.RemoveField( + model_name='clientprofile', + name='id', + ), + migrations.RemoveField( + model_name='clientprofile', + name='user', + ), + migrations.RemoveField( + model_name='partnerprofile', + name='id', + ), + migrations.RemoveField( + model_name='partnerprofile', + name='user', + ), + migrations.AddField( + model_name='partnerprofile', + name='company', + field=models.CharField(default=None, max_length=128), + preserve_default=False, + ), + migrations.AddField( + model_name='partnerprofile', + name='vatid', + field=vies.models.VATINField(blank=True, max_length=14, null=True), + ), + migrations.CreateModel( + name='Profile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=128)), + ('last_name', models.CharField(max_length=128)), + ('address', models.CharField(max_length=128)), + ('address2', models.CharField(max_length=128)), + ('zipcode', models.CharField(max_length=15)), + ('city', models.CharField(max_length=128)), + ('country', django_countries.fields.CountryField(max_length=2)), + ('phone', phonenumber_field.modelfields.PhoneNumberField(max_length=128, region=None)), + ('polymorphic_ctype', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_auction.profile_set+', to='contenttypes.ContentType')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + ), + migrations.AddField( + model_name='clientprofile', + name='profile_ptr', + field=models.OneToOneField(auto_created=True, default=None, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auction.Profile'), + preserve_default=False, + ), + migrations.AddField( + model_name='partnerprofile', + name='profile_ptr', + field=models.OneToOneField(auto_created=True, default=None, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auction.Profile'), + preserve_default=False, + ), + ] diff --git a/auction/migrations/0004_auto_20191222_2318.py b/auction/migrations/0004_auto_20191222_2318.py new file mode 100644 index 0000000..145ed6b --- /dev/null +++ b/auction/migrations/0004_auto_20191222_2318.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.6 on 2019-12-22 23:18 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auction', '0003_auto_20191222_2310'), + ] + + operations = [ + migrations.AlterField( + model_name='inquiry', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auction.ClientProfile'), + ), + ] diff --git a/auction/migrations/__init__.py b/auction/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/auction/models.py b/auction/models.py new file mode 100644 index 0000000..32cb46a --- /dev/null +++ b/auction/models.py @@ -0,0 +1,49 @@ +from django.db.models import Model, CharField, ForeignKey, DecimalField, OneToOneField, CASCADE +from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver + +from django_countries.fields import CountryField +from polymorphic.models import PolymorphicModel +from phonenumber_field.modelfields import PhoneNumberField +from vies.models import VATINField + +class Profile(PolymorphicModel): + user = OneToOneField(User, on_delete=CASCADE) + first_name = CharField(max_length=128) + last_name = CharField(max_length=128) + address = CharField(max_length=128) + address2 = CharField(max_length=128) + zipcode = CharField(max_length=15) + city = CharField(max_length=128) + country = CountryField() + phone = PhoneNumberField() + +class ClientProfile(Profile): + pass + +class PartnerProfile(Profile): + company = CharField(max_length=128) + vatid = VATINField(blank=True, null=True) + +def create_client_profile(user): + ClientProfile.objects.create(user=user) + +def create_partner_profile(user): + PartnerProfile.objects.create(user=user) + +@receiver(post_save, sender=User) +def save_user_profile(sender, instance, **kwargs): + try: + instance.partnerprofile.save() + except: + pass + + try: + instance.partnerprofile.save() + except: + pass + +class Inquiry(Model): + user = ForeignKey(ClientProfile, on_delete=CASCADE) + amount = DecimalField(max_digits=25, decimal_places=2) diff --git a/auction/tests.py b/auction/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/auction/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/auction/views.py b/auction/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/auction/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/dbsettings b/dbsettings new file mode 160000 index 0000000..ce4c240 --- /dev/null +++ b/dbsettings @@ -0,0 +1 @@ +Subproject commit ce4c2400431152e04b8ff0f23704c41a7087c14d diff --git a/packages.txt b/packages.txt new file mode 100644 index 0000000..27bbcbc --- /dev/null +++ b/packages.txt @@ -0,0 +1,3 @@ +libssl-dev +libffi-dev +libreoffice diff --git a/payment/__init__.py b/payment/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/payment/admin.py b/payment/admin.py new file mode 100644 index 0000000..91418c8 --- /dev/null +++ b/payment/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin +from payment.models import Payment, KlarnaPayment + +# Register your models here. + +admin.site.register(Payment) +admin.site.register(KlarnaPayment) diff --git a/payment/apps.py b/payment/apps.py new file mode 100644 index 0000000..59dfc4d --- /dev/null +++ b/payment/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PaymentConfig(AppConfig): + name = 'payment' diff --git a/payment/migrations/0001_initial.py b/payment/migrations/0001_initial.py new file mode 100644 index 0000000..3b17b35 --- /dev/null +++ b/payment/migrations/0001_initial.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.6 on 2019-12-22 18:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Payment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + ] diff --git a/payment/migrations/0002_auto_20191222_2018.py b/payment/migrations/0002_auto_20191222_2018.py new file mode 100644 index 0000000..a5359fc --- /dev/null +++ b/payment/migrations/0002_auto_20191222_2018.py @@ -0,0 +1,71 @@ +# Generated by Django 2.2.6 on 2019-12-22 20:18 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('payment', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='PaypalPayment', + fields=[ + ('payment_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='payment.Payment')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('payment.payment',), + ), + migrations.CreateModel( + name='SofortPayment', + fields=[ + ('payment_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='payment.Payment')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('payment.payment',), + ), + migrations.CreateModel( + name='StripePayment', + fields=[ + ('payment_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='payment.Payment')), + ], + options={ + 'abstract': False, + 'base_manager_name': 'objects', + }, + bases=('payment.payment',), + ), + migrations.AlterModelOptions( + name='payment', + options={'base_manager_name': 'objects'}, + ), + migrations.AddField( + model_name='payment', + name='amount', + field=models.DecimalField(decimal_places=2, default=0, max_digits=10), + preserve_default=False, + ), + migrations.AddField( + model_name='payment', + name='polymorphic_ctype', + field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_payment.payment_set+', to='contenttypes.ContentType'), + ), + migrations.AddField( + model_name='payment', + name='user', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + preserve_default=False, + ), + ] diff --git a/payment/migrations/0003_auto_20191222_2048.py b/payment/migrations/0003_auto_20191222_2048.py new file mode 100644 index 0000000..94f3ba5 --- /dev/null +++ b/payment/migrations/0003_auto_20191222_2048.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.6 on 2019-12-22 20:48 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('contenttypes', '0002_remove_content_type_name'), + ('payment', '0002_auto_20191222_2018'), + ] + + operations = [ + migrations.RenameModel( + old_name='SofortPayment', + new_name='KlarnaPayment', + ), + ] diff --git a/payment/migrations/0004_auto_20191222_2120.py b/payment/migrations/0004_auto_20191222_2120.py new file mode 100644 index 0000000..833d82c --- /dev/null +++ b/payment/migrations/0004_auto_20191222_2120.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.6 on 2019-12-22 21:20 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auction', '0001_initial'), + ('payment', '0003_auto_20191222_2048'), + ] + + operations = [ + migrations.RemoveField( + model_name='payment', + name='amount', + ), + migrations.RemoveField( + model_name='payment', + name='user', + ), + migrations.AddField( + model_name='payment', + name='inquiry', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='auction.Inquiry'), + preserve_default=False, + ), + ] diff --git a/payment/migrations/__init__.py b/payment/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/payment/models.py b/payment/models.py new file mode 100644 index 0000000..658009d --- /dev/null +++ b/payment/models.py @@ -0,0 +1,46 @@ +from django.db.models import Model, ForeignKey, DecimalField, CASCADE +from django.conf import settings +from polymorphic.models import PolymorphicModel + +from auction.models import Inquiry + +# Create your models here. + +class Payment(PolymorphicModel): + inquiry = ForeignKey(Inquiry, on_delete=CASCADE) + + def status(self): + raise NotImplementedError("status() not implemented in %s!" % type(self).__name__) + +class PaypalPayment(Payment): + pass + +class StripePayment(Payment): + pass + +class KlarnaPayment(Payment): + def create(self): + lang = settings.LANGUAGE_CODE + + json = (""" +{ + "purchase_country": "AT", + "purchase_currency": "EUR", + "locale": "%s", + "order_amount": 10, + "order_tax_amount": 0, + "order_lines": [{ + "type": "digital", + "reference": "19-402", + "name": "Battery Power Pack", + "quantity": 1, + "unit_price": 10, + "tax_rate": 0, + "total_amount": 10, + "total_discount_amount": 0, + "total_tax_amount": 0, + "image_url": "https://www.exampleobjects.com/logo.png", + "product_url": "https://www.estore.com/products/f2a8d7e34" + }] +}""".strip() % (lang)) + diff --git a/payment/tests.py b/payment/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/payment/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/payment/views.py b/payment/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/payment/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..033cb0e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +paypalrestsdk +django-polymorphic +django-vies +pdfdocument +django-countries +django-phonenumber-field +phonenumbers +odfpy diff --git a/urlaubsauktion/settings.py b/urlaubsauktion/settings.py index 6a1a4ce..1b077b1 100644 --- a/urlaubsauktion/settings.py +++ b/urlaubsauktion/settings.py @@ -37,6 +37,11 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'payment', + 'dbsettings', + 'auction', + 'django_countries', + 'phonenumber_field', ] MIDDLEWARE = [ @@ -103,7 +108,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'de-at' TIME_ZONE = 'UTC' @@ -118,3 +123,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' +