0001-general-add-connector-class-method-to-get-new-edit-f.patch
passerelle/apps/pastell/__init__.py | ||
---|---|---|
27 | 27 |
from . import models |
28 | 28 |
return models.Pastell |
29 | 29 | |
30 |
def get_form_class(self): |
|
31 |
from . import forms |
|
32 |
return forms.PastellForm |
|
33 | 30 | |
34 | 31 |
default_app_config = 'passerelle.apps.pastell.AppConfig' |
passerelle/apps/pastell/models.py | ||
---|---|---|
44 | 44 |
def get_verbose_name(cls): |
45 | 45 |
return cls._meta.verbose_name |
46 | 46 | |
47 |
@classmethod |
|
48 |
def get_manager_form_class(cls): |
|
49 |
from .forms import PastellForm |
|
50 |
return PastellForm |
|
51 | ||
47 | 52 |
def pastell_request(self, endpoint, **kwargs): |
48 | 53 |
if self.keystore: |
49 | 54 |
kwargs['cert'] = (self.keystore.path, self.keystore.path) |
passerelle/base/models.py | ||
---|---|---|
18 | 18 |
from django.core.urlresolvers import reverse |
19 | 19 |
from django.db import connection, models, transaction |
20 | 20 |
from django.db.models import Q |
21 |
from django.forms.models import modelform_factory |
|
22 |
from django.forms.widgets import ClearableFileInput |
|
21 | 23 |
from django.test import override_settings |
22 | 24 |
from django.utils.text import slugify |
23 | 25 |
from django.utils import timezone, six |
... | ... | |
36 | 38 |
import passerelle |
37 | 39 |
import requests |
38 | 40 |
from passerelle.compat import json_loads |
41 |
from passerelle.forms import GenericConnectorForm |
|
39 | 42 |
from passerelle.utils.api import endpoint |
40 | 43 |
from passerelle.utils.jsonresponse import APIError |
41 | 44 | |
... | ... | |
128 | 131 | |
129 | 132 |
parameters = None |
130 | 133 |
manager_view_template_name = None |
134 |
manager_form_base_class = GenericConnectorForm |
|
131 | 135 | |
132 | 136 |
# permission descriptions |
133 | 137 |
_can_access_description = _('Access is limited to the following API users:') |
... | ... | |
159 | 163 |
def is_enabled(cls): |
160 | 164 |
return getattr(settings, 'PASSERELLE_APP_%s_ENABLED' % cls._meta.app_label.upper(), True) |
161 | 165 | |
166 |
@classmethod |
|
167 |
def get_manager_form_class(cls, **kwargs): |
|
168 |
''' |
|
169 |
Return the class to use for new/edit connector forms. |
|
170 |
''' |
|
171 |
form_class = modelform_factory( |
|
172 |
cls, |
|
173 |
form=cls.manager_form_base_class, |
|
174 |
**kwargs) |
|
175 |
for field in form_class.base_fields.values(): |
|
176 |
if isinstance(field.widget, ClearableFileInput): |
|
177 |
field.widget.template_with_initial = ''\ |
|
178 |
'%(initial_text)s: %(initial)s '\ |
|
179 |
'%(clear_template)s<br />%(input_text)s: %(input)s' |
|
180 |
return form_class |
|
181 | ||
162 | 182 |
@property |
163 | 183 |
def requests(self): |
164 | 184 |
if getattr(self, '_requests', None) is None: |
passerelle/views.py | ||
---|---|---|
41 | 41 |
from django.utils.timezone import make_aware |
42 | 42 |
from django.utils.translation import ugettext_lazy as _ |
43 | 43 |
from django.utils.encoding import force_bytes, force_text |
44 |
from django.forms.models import modelform_factory |
|
45 |
from django.forms.widgets import ClearableFileInput |
|
46 | 44 |
from django.utils.six.moves.urllib.parse import quote |
47 | 45 | |
48 | 46 |
from dateutil import parser as date_parser |
... | ... | |
54 | 52 |
from passerelle.utils.json import unflatten |
55 | 53 | |
56 | 54 |
from .utils import to_json, is_authorized |
57 |
from .forms import GenericConnectorForm |
|
58 | 55 |
from .forms import ResourceLogSearchForm |
59 | 56 | |
60 | 57 |
if 'mellon' in settings.INSTALLED_APPS: |
... | ... | |
156 | 153 |
raise Http404() |
157 | 154 | |
158 | 155 |
self.model = app.get_connector_model() |
159 |
if hasattr(app, 'get_form_class'): |
|
160 |
self.form_class = app.get_form_class() |
|
161 |
else: |
|
162 |
self.form_class = modelform_factory( |
|
163 |
self.model, |
|
164 |
form=GenericConnectorForm, |
|
165 |
exclude=self.exclude_fields) |
|
166 |
for field in self.form_class.base_fields.values(): |
|
167 |
if isinstance(field.widget, ClearableFileInput): |
|
168 |
field.widget.template_with_initial = ''\ |
|
169 |
'%(initial_text)s: %(initial)s '\ |
|
170 |
'%(clear_template)s<br />%(input_text)s: %(input)s' |
|
156 |
self.form_class = self.model.get_manager_form_class(exclude=self.exclude_fields) |
|
171 | 157 | |
172 | 158 |
def dispatch(self, request, *args, **kwargs): |
173 | 159 |
self.init_stuff(request, *args, **kwargs) |
174 |
- |