diff --git a/borgia/__init__.py b/borgia/__init__.py index e69de29b..71ac8661 100644 --- a/borgia/__init__.py +++ b/borgia/__init__.py @@ -0,0 +1,7 @@ +"""from __future__ import absolute_import, unicode_literals + +# This will make sure the app is always imported when +# Django starts so that shared_task will use this app. +from .celery import app as celery_app + +__all__ = ['celery_app']""" diff --git a/borgia/celery.py b/borgia/celery.py new file mode 100644 index 00000000..771496fb --- /dev/null +++ b/borgia/celery.py @@ -0,0 +1,38 @@ +from __future__ import absolute_import, unicode_literals + +import os +from celery import Celery, chain +from celery.schedules import crontab +from users.tasks import scan_mailing_balance_alert + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'borgia.settings') +"""import django +from django.conf import settings +settings.configure() +django.setup()""" + +# set the default Django settings module for the 'celery' program. +app = Celery('borgia', backend='rpc://', broker='pyamqp://') + +# Using a string here means the worker doesn't have to serialize +# the configuration object to child processes. +# - namespace='CELERY' means all celery-related configuration keys +# should have a `CELERY_` prefix. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks() + +# Console log +@app.task(bind=True) +def debug_task(self): + print('Request: {0!r}'.format(self.request)) + + +@app.on_after_configure.connect +def setup_periodic_tasks(sender, **kwargs): + sender.add_periodic_task( + 5, + scan_mailing_balance_alert.s(), + name='Alert mailing' + ) diff --git a/borgia/settings.py b/borgia/settings.py index fe01b123..fd8b278a 100644 --- a/borgia/settings.py +++ b/borgia/settings.py @@ -46,7 +46,8 @@ 'modules', 'stocks', 'graphene_django', - 'static_precompiler' + 'static_precompiler', + 'django_celery_results' ] MIDDLEWARE_CLASSES = [ @@ -221,3 +222,6 @@ CENTER_NAME = "Center Name" DEFAULT_TEMPLATE = "light" #Default template, en minuscule + +# Celery +CELERY_RESULT_BACKEND = 'django-db' diff --git a/borgia/urls.py b/borgia/urls.py index 3a50750d..d6dfee31 100644 --- a/borgia/urls.py +++ b/borgia/urls.py @@ -25,6 +25,7 @@ from modules.views import * from notifications.views import * from stocks.views import * +from settings_data.views import GlobalConfig, PriceConfig, LydiaConfig, BalanceConfig from api.Schema.main import schema from graphene_django.views import GraphQLView from api.views import AuthGenerateJWT, AuthVerifyJWT, AuthInvalidateJWT, GraphQLJwtProtectedView @@ -45,6 +46,18 @@ url(r'^jwt/token/(?P.+)/(?P\d+).json$', AuthVerifyJWT.as_view()), url(r'^jwt/invalidate/(?P.+)/(?P\d+).json$', AuthInvalidateJWT.as_view()), + ##################### + # CONFIG # + ##################### + url(r'^(?P[\w-]+)/config/$', + GlobalConfig.as_view(), name='url_global_config'), + url(r'^(?P[\w-]+)/config/price/$', + PriceConfig.as_view(), name='url_price_config'), + url(r'^(?P[\w-]+)/config/lydia/$', + LydiaConfig.as_view(), name='url_lydia_config'), + url(r'^(?P[\w-]+)/config/balance/$', + BalanceConfig.as_view(), name='url_balance_config'), + ##################### # WORKBOARDS # ##################### diff --git a/borgia/utils.py b/borgia/utils.py index 181e1591..080023e3 100644 --- a/borgia/utils.py +++ b/borgia/utils.py @@ -237,6 +237,21 @@ def lateral_menu(user, group, active=None): except ValueError: pass + # Global config + try: + if (Permission.objects.get(codename='change_setting') + in group.permissions.all()): + nav_tree.append(simple_lateral_link( + label='Configuration', + faIcon='cogs', + id='lm_global_config', + url=reverse( + 'url_global_config', + kwargs={'group_name': group.name}) + )) + except ObjectDoesNotExist: + pass + if active is not None: for link in nav_tree: try: diff --git a/celerybeat-schedule.db b/celerybeat-schedule.db new file mode 100644 index 00000000..4b71fc74 Binary files /dev/null and b/celerybeat-schedule.db differ diff --git a/finances/forms.py b/finances/forms.py index a4e03525..b808abd2 100644 --- a/finances/forms.py +++ b/finances/forms.py @@ -220,8 +220,9 @@ def __init__(self, **kwargs): min_value = kwargs.pop('min_value') max_value = kwargs.pop('max_value') super(SelfLydiaCreateForm, self).__init__(**kwargs) - self.fields['amount'] = forms.IntegerField( + self.fields['amount'] = forms.DecimalField( label='Montant (€)', + decimal_places=2, max_digits=9, min_value=min_value, max_value=max_value) self.fields['tel_number'] = forms.CharField( diff --git a/finances/templates/finances/self_lydia_button.html b/finances/templates/finances/self_lydia_button.html index 080474c2..ebb5061d 100644 --- a/finances/templates/finances/self_lydia_button.html +++ b/finances/templates/finances/self_lydia_button.html @@ -1,5 +1,6 @@ {% extends 'base_sober.html' %} {% load static %} +{% load l10n %} {% load bootstrap %} {% block content %} @@ -13,7 +14,7 @@
- +
@@ -28,7 +29,7 @@