Metadata: Use generator to prepare lookup choices
Change the use of the list/zip combinarion to generate the full list of metadata lookup choices to a generator. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -163,7 +163,9 @@
|
||||
into a Mayan app. With change adds the new settings:
|
||||
"COMMON_AUTOADMIN_EMAIL", "AUTOADMIN_PASSWORD", and
|
||||
"AUTOADMIN_USERNAME".
|
||||
|
||||
- Changed the use of the list/zip combinarion to generate
|
||||
the full list of metadata lookup choices to a generator.
|
||||
|
||||
3.1.9 (2018-11-01)
|
||||
==================
|
||||
- Convert the furl instance to text to allow serializing it into
|
||||
|
||||
@@ -62,11 +62,15 @@ class DocumentMetadataForm(forms.Form):
|
||||
self.fields['value'] = forms.ChoiceField(
|
||||
label=self.fields['value'].label
|
||||
)
|
||||
choices = self.metadata_type.get_lookup_values()
|
||||
choices = list(zip(choices, choices))
|
||||
|
||||
if not required:
|
||||
choices.insert(0, ('', '------'))
|
||||
self.fields['value'].choices = choices
|
||||
first_choice=('', '------')
|
||||
else:
|
||||
first_choice=None
|
||||
|
||||
self.fields['value'].choices = self.metadata_type.get_lookup_choices(
|
||||
first_choice=first_choice
|
||||
)
|
||||
self.fields['value'].required = required
|
||||
self.fields['value'].widget.attrs.update(
|
||||
{'class': 'metadata-value'}
|
||||
|
||||
@@ -123,6 +123,16 @@ class MetadataType(models.Model):
|
||||
template = Template(self.default)
|
||||
return template.render()
|
||||
|
||||
def get_lookup_choices(self, first_choice=None):
|
||||
template = Template(self.lookup)
|
||||
context = MetadataLookup.get_as_context()
|
||||
|
||||
if first_choice:
|
||||
yield first_choice
|
||||
|
||||
for value in MetadataType.comma_splitter(template.render(**context)):
|
||||
yield (value, value)
|
||||
|
||||
def get_lookup_values(self):
|
||||
template = Template(self.lookup)
|
||||
context = MetadataLookup.get_as_context()
|
||||
|
||||
Reference in New Issue
Block a user