populating service url from settings on cell initilisation

This commit is contained in:
Serghei Mihai 2015-04-17 14:50:50 +02:00
parent 44f3490c8c
commit b63758cd21
3 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('combo_plugin_subscriptions', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='subscriptionsmanagecell',
name='passerelle_url',
field=models.URLField(max_length=128, verbose_name='Subscriptions service url'),
preserve_default=True,
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('combo_plugin_subscriptions', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='subscriptionsmanagecell',
name='passerelle_url',
field=models.URLField(max_length=128, verbose_name='Subscriptions service url'),
preserve_default=True,
),
]

View File

@ -9,6 +9,7 @@ from django.utils.translation import ugettext as _
from django.template.defaultfilters import slugify
from django.core.cache import cache
from django import template
from django.forms import models as model_forms, Select
logger = logging.getLogger(__name__)
@ -22,7 +23,6 @@ from .forms import SubscriptionsManageForm
@register_cell_class
class SubscriptionsManageCell(CellBase):
passerelle_url = models.URLField(verbose_name=_('Subscriptions service url'),
choices=settings.COMBO_SUBSCRIPTIONS,
max_length=128)
resources_restrictions = models.TextField(verbose_name=_('resources restrictions'), blank=True)
transports_restrictions = models.TextField(verbose_name=_('transports restrictions'), blank=True)
@ -35,6 +35,16 @@ class SubscriptionsManageCell(CellBase):
class Meta:
verbose_name = _('Manage your subscriptions')
def get_default_form_class(self):
model_fields = ('passerelle_url', 'resources_restrictions',
'transports_restrictions')
try:
return model_forms.modelform_factory(self.__class__, fields=model_fields,
widgets={'passerelle_url': Select(choices=settings.COMBO_SUBSCRIPTIONS)})
except AttributeError:
return model_forms.modelform_factory(self.__class__, fields=model_fields)
def simplify(self, name):
return slugify(name.strip())