0001-misc-move-carddef-data-source-support-to-carddef-mod.patch
wcs/carddef.py | ||
---|---|---|
18 | 18 |
import types |
19 | 19 | |
20 | 20 |
from quixote import get_publisher |
21 |
from .qommon import _, N_ |
|
21 |
from .qommon import _, N_, misc
|
|
22 | 22 | |
23 | 23 |
from wcs.carddata import CardData |
24 | 24 |
from wcs.formdef import FormDef |
... | ... | |
134 | 134 |
def store(self): |
135 | 135 |
self.roles = self.backoffice_submission_roles |
136 | 136 |
return super(CardDef, self).store() |
137 | ||
138 |
@classmethod |
|
139 |
def get_as_data_source_options(cls): |
|
140 |
for carddef in cls.select(lightweight=True, ignore_errors=True, order_by='name'): |
|
141 |
if not carddef.digest_template: |
|
142 |
continue |
|
143 |
data_source_id = 'carddef:%s' % carddef.url_name |
|
144 |
yield (data_source_id, carddef.name, data_source_id) |
|
145 | ||
146 |
@classmethod |
|
147 |
def get_data_source_items(cls, data_source_id): |
|
148 |
assert data_source_id.startswith('carddef:') |
|
149 |
try: |
|
150 |
carddef = cls.get_by_urlname(data_source_id[8:]) |
|
151 |
except KeyError: |
|
152 |
return [] |
|
153 |
items = [x.get_data_source_structured_item() |
|
154 |
for x in carddef.data_class().select() |
|
155 |
if not x.is_draft()] |
|
156 |
items.sort(key=lambda x: misc.simplify(x['text'])) |
|
157 |
return items |
wcs/data_sources.py | ||
---|---|---|
62 | 62 |
if allow_named_sources: |
63 | 63 |
options.extend([(x.slug, x.name, x.slug) for x in NamedDataSource.select()]) |
64 | 64 |
from wcs.carddef import CardDef |
65 |
options.extend([ |
|
66 |
('carddef:%s' % x.url_name, x.name, 'carddef:%s' % x.url_name) |
|
67 |
for x in CardDef.select(lightweight=True, ignore_errors=True) |
|
68 |
if x.digest_template]) |
|
65 |
options.extend(list(CardDef.get_as_data_source_options())) |
|
69 | 66 |
options.sort(key=lambda x: misc.simplify(x[1])) |
70 | 67 | |
71 | 68 |
options.insert(0, (None, _('None'), None)) |
... | ... | |
176 | 173 |
if data_source.get('type') and data_source.get('type').startswith('carddef:'): |
177 | 174 |
# cards |
178 | 175 |
from wcs.carddef import CardDef |
179 |
try: |
|
180 |
carddef = CardDef.get_by_urlname(data_source['type'][8:]) |
|
181 |
except KeyError: |
|
182 |
return [] |
|
183 |
items = [x.get_data_source_structured_item() |
|
184 |
for x in carddef.data_class().select() |
|
185 |
if not x.is_draft()] |
|
186 |
items.sort(key=lambda x: misc.simplify(x['text'])) |
|
187 |
return items |
|
176 |
return CardDef.get_data_source_items(data_source['type']) |
|
188 | 177 | |
189 | 178 |
if data_source.get('type') not in ('json', 'jsonp', 'geojson', 'formula'): |
190 | 179 |
# named data source |
191 |
- |