general: move connector form_class from view to model (#.....)
This commit is contained in:
parent
c7b387f4eb
commit
5e8b06043e
|
@ -18,6 +18,8 @@ from django.core.exceptions import ValidationError, ObjectDoesNotExist, Permissi
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.db import connection, models, transaction
|
||||
from django.db.models import Q
|
||||
from django.forms.models import modelform_factory
|
||||
from django.forms.widgets import ClearableFileInput
|
||||
from django.test import override_settings
|
||||
from django.utils.text import slugify
|
||||
from django.utils import timezone, six
|
||||
|
@ -159,6 +161,20 @@ class BaseResource(models.Model):
|
|||
def is_enabled(cls):
|
||||
return getattr(settings, 'PASSERELLE_APP_%s_ENABLED' % cls._meta.app_label.upper(), True)
|
||||
|
||||
@classmethod
|
||||
def get_form_class(cls, **kwargs):
|
||||
from passerelle.forms import GenericConnectorForm
|
||||
form_class = modelform_factory(
|
||||
cls,
|
||||
form=GenericConnectorForm,
|
||||
**kwargs)
|
||||
for field in form_class.base_fields.values():
|
||||
if isinstance(field.widget, ClearableFileInput):
|
||||
field.widget.template_with_initial = ''\
|
||||
'%(initial_text)s: %(initial)s '\
|
||||
'%(clear_template)s<br />%(input_text)s: %(input)s'
|
||||
return form_class
|
||||
|
||||
@property
|
||||
def requests(self):
|
||||
if getattr(self, '_requests', None) is None:
|
||||
|
|
|
@ -159,15 +159,7 @@ class GenericConnectorMixin(object):
|
|||
if hasattr(app, 'get_form_class'):
|
||||
self.form_class = app.get_form_class()
|
||||
else:
|
||||
self.form_class = modelform_factory(
|
||||
self.model,
|
||||
form=GenericConnectorForm,
|
||||
exclude=self.exclude_fields)
|
||||
for field in self.form_class.base_fields.values():
|
||||
if isinstance(field.widget, ClearableFileInput):
|
||||
field.widget.template_with_initial = ''\
|
||||
'%(initial_text)s: %(initial)s '\
|
||||
'%(clear_template)s<br />%(input_text)s: %(input)s'
|
||||
self.form_class = self.model.get_form_class(exclude=self.exclude_fields)
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.init_stuff(request, *args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue