forked from City-of-Helsinki/linkedevents
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Preliminary changes to payment methods Preliminary changes to payment methods, includes model changes, multilanguage translation changes, admin view changes and a new api endpoint. * Handle payment_method linking * Fixed validation for Image publication rights. This bug caused us problems with all new models requiring editable rights. This has now been resolved. * Validate that the models have is_user_editable attribute We also need to validate that the models have the is_user_editable function. * Importer for 'Payment Methods' default values Importer for Payment Methods that adds the default values into the database. * Checks for the existence of both attributes. Checks for the existence of both attributes. * PMD update PMD update * Updated PMD index start value Updated PMD index start value * Update api.py New offer update, changes to OfferSerializer * Create 0083_auto_20211102_1005.py New migration file for payment methods * Update models.py Removed unused import Co-authored-by: ezkat <[email protected]> Co-authored-by: Anthon98 <[email protected]>
- Loading branch information
1 parent
d5d2f43
commit 7c29f24
Showing
6 changed files
with
190 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Dependencies. | ||
|
||
# Logging: | ||
import time | ||
import logging | ||
from os import mkdir | ||
from os.path import abspath, join, dirname, exists, basename, splitext | ||
|
||
# Django: | ||
from django_orghierarchy.models import Organization | ||
from django_orghierarchy.models import OrganizationClass | ||
from events.models import BaseModel, PaymentMethod | ||
|
||
# Importer specific: | ||
from .base import Importer, register_importer | ||
|
||
# Type checking: | ||
from typing import Any | ||
|
||
# Setup Logging: | ||
if not exists(join(dirname(__file__), 'logs')): | ||
mkdir(join(dirname(__file__), 'logs')) | ||
|
||
logger = logging.getLogger(__name__) # Per module logger | ||
curFileExt = basename(__file__) | ||
curFile = splitext(curFileExt)[0] | ||
logFile = \ | ||
logging.FileHandler( | ||
'%s' % (join(dirname(__file__), 'logs', curFile+'.logs')) | ||
) | ||
logFile.setFormatter( | ||
logging.Formatter( | ||
'[%(asctime)s] <%(name)s> (%(lineno)d): %(message)s' | ||
) | ||
) | ||
logFile.setLevel(logging.DEBUG) | ||
logger.addHandler( | ||
logFile | ||
) | ||
|
||
|
||
@register_importer | ||
class PMDImporter(Importer): | ||
# Required super 'base' class dependencies... | ||
name = "payment_method_defaults" # Command calling name. | ||
supported_languages = ['fi', 'sv', 'en'] # Language requirement. | ||
data_source = None # Base data_source requirement. | ||
organization = None # Base organization requirement. | ||
|
||
def setup(self: 'events.importer.payment_method_defaults.PMDImporter') -> None: | ||
data = [ | ||
'Käteinen', | ||
'Maksukortti', | ||
'Virikeseteli', | ||
'Tyky-ranneke', | ||
'Verkkomaksu', | ||
'Mobile Pay', | ||
'Museokortti', | ||
'Lasku', | ||
] | ||
|
||
for idx, word in enumerate(data, start=1): | ||
try: | ||
pm = PaymentMethod() | ||
pm.id = str(idx) | ||
pm.name = word | ||
pm.save() | ||
except Exception as e: | ||
logger.error(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 2.2.24 on 2021-11-02 08:05 | ||
|
||
from django.db import migrations, models | ||
import events.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('events', '0082_event_enrolment_url'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PaymentMethod', | ||
fields=[ | ||
('id', models.CharField(max_length=100, primary_key=True, serialize=False)), | ||
('name', models.CharField(blank=True, max_length=25, verbose_name='Name')), | ||
('name_fi', models.CharField(blank=True, max_length=25, null=True, verbose_name='Name')), | ||
('name_sv', models.CharField(blank=True, max_length=25, null=True, verbose_name='Name')), | ||
('name_en', models.CharField(blank=True, max_length=25, null=True, verbose_name='Name')), | ||
('name_zh_hans', models.CharField(blank=True, max_length=25, null=True, verbose_name='Name')), | ||
('name_ru', models.CharField(blank=True, max_length=25, null=True, verbose_name='Name')), | ||
('name_ar', models.CharField(blank=True, max_length=25, null=True, verbose_name='Name')), | ||
], | ||
bases=(models.Model, events.models.SimpleValueMixin), | ||
), | ||
migrations.AddField( | ||
model_name='offer', | ||
name='payment_methods', | ||
field=models.ManyToManyField(blank=True, related_name='paymentmethods', to='events.PaymentMethod'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters