[Mayan EDMS: 452] describing metadata (default values and multiple choice)

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 452] describing metadata (default values and multiple choice)

Lau Llobet
As i've seen in the Mayan video there is the option to add a multiple choice box in the metadata filling step while uploading documents. How can i model it ? As far as i've seen the metadata value must be filled freely by the user with the possibility of making typos. The only place i guess it can be described it's in the Lookup box, is it there where i have to describe the multiple choices that user may have ? If it's so could you please post a example snippet of the code that shoud go there? i've haven't find anything in the documentation.

One other thing i'd like to point for people that is getting started and may find problems in this step is that default values for the metadata shoud be introduced with "" lihe  [ "high" ]  or  [ "low" ] instead of [ high ]  [ low ]

--
 
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 453] Re: describing metadata (default values and multiple choice)

Lau Llobet
I found the anwer by myselve , in the lookup field options are described like [ "hig","low" ] . Hope this post may be usefull for future begginers

--
 
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 459] Re: describing metadata (default values and multiple choice)

rosarior
Administrator
Hi Lau,

Yes, documentation is not my strong suite :)

The Lookup field is in fact interpreted as a Python statement, so things like Lists, Tuples and List comprehensions are possible as lookup values.  For example in the included "Simple permit management setup (Official)" bootstrap setup, a 'user' metadata type is included that automatically displays the list of active users for selection, the code is as follows:

sorted([user.get_full_name() or user for user in User.objects.all() if user.is_active])

if you want to display a list of years (say 1990 to 2000) you can create the list by hand:

['1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000']

but being a Python statement it can also be done with a list comprehension

[str(year) for year in range(1990, 2001)]

As you well noted the resulting values of the lookup and default values must be strings, hence enclosed in quotes (") or single quotes (').

--Roberto

On Monday, January 14, 2013 6:29:09 AM UTC-4, Lau Llobet wrote:
I found the anwer by myselve , in the lookup field options are described like [ "hig","low" ] . Hope this post may be usefull for future begginers

--
 
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Mayan EDMS: 508] Re: describing metadata (default values and multiple choice)

Lau Llobet
Hi everybody,

i've noticed that even i put a value in default metadata, when there's a closed list of items the default value still is "-----". Is there any reason not to put the default value in there ?

--
 
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Mayan EDMS: 528] Re: describing metadata (default values and multiple choice)

rosarior
Administrator
Just tried it and indeed is failing to pre-select the values, this is a regression as this used to work correctly.  Can you please open a ticket on github so I can track this and fix it.  Thanks,

--Roberto

On Sunday, February 10, 2013 10:55:38 AM UTC-4, Lau Llobet wrote:
Hi everybody,

i've noticed that even i put a value in default metadata, when there's a closed list of items the default value still is "-----". Is there any reason not to put the default value in there ?

--
 
---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 1582] Re: describing metadata (default values and multiple choice)

Manuel Reiter
In reply to this post by rosarior
These examples don't seem to work any more. Am I doing something wrong or has the syntax changed over the last couple of years? What would be the best way now to offer as choices
  • a range of years
  • the localized names of the months?

--

---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 1618] Re: describing metadata (default values and multiple choice)

rosarior
Administrator
Allowing interpreted Python code was later considered a security risk. These fields now use the template language of Django (https://docs.djangoproject.com/en/1.10/ref/templates/language/) and expect a comma delimited output. So the years example would now be:

'1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000'

without the brackets.

The second example cannot be done as the template language doesn't support range generators. This is some of the reasons switching to the Jinja2 template language is being considered. It is more secure than Python code, is a superset of Django's template language but add many Pythonistic tags line range().

With Jinja2 this would be the solution to generate a range of years.
{% for year in range(1990,2000) %}
{{ year }},
{% endfor %}

For a localized list of months, in theory (haven't tested yet) this would suffice:

{% load i18n %}
{% trans 'January' %},
{% trans 'February' %},
...
{% trans 'December' %}

The first line loads the internationalization tags (` trans `). The trans tag marks a text for translation. 

On Monday, April 10, 2017 at 10:34:14 AM UTC-4, Manuel Reiter wrote:
These examples don't seem to work any more. Am I doing something wrong or has the syntax changed over the last couple of years? What would be the best way now to offer as choices
  • a range of years
  • the localized names of the months?

--

---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 1619] Re: describing metadata (default values and multiple choice)

MacRobb Simpson
Is there any way to define a simple class somewhere and call it using the template language to do this?
Something like how validators are made?

On Thursday, April 20, 2017 at 12:27:29 AM UTC-7, Roberto Rosario wrote:
Allowing interpreted Python code was later considered a security risk. These fields now use the template language of Django (<a href="https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.10%2Fref%2Ftemplates%2Flanguage%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGH5bfzqqQg_T5-xttrWYt1G7EIhg" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.10%2Fref%2Ftemplates%2Flanguage%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGH5bfzqqQg_T5-xttrWYt1G7EIhg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.10%2Fref%2Ftemplates%2Flanguage%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGH5bfzqqQg_T5-xttrWYt1G7EIhg&#39;;return true;">https://docs.djangoproject.com/en/1.10/ref/templates/language/) and expect a comma delimited output. So the years example would now be:

'1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000'

without the brackets.

The second example cannot be done as the template language doesn't support range generators. This is some of the reasons switching to the Jinja2 template language is being considered. It is more secure than Python code, is a superset of Django's template language but add many Pythonistic tags line range().

--

---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Mayan EDMS: 1634] Re: describing metadata (default values and multiple choice)

rosarior
Administrator
Yes, they are called `Template tags and filters` in Django parlance. A tag has the form {% <tag name> %} and is replace in the final render with its output. a Filter has the form {{ |<filter name>: <filter parameters>  }} and works like a piped command in Linux, receiving the input from a variable and modifying it.

Documentation link: https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/

Custom tags need to be placed in the templatetags folders of an app. You can also make your own almost empty app to add your own custom tags if you don't to directly change committed code.

Example of custom tag in Mayan:

https://gitlab.com/mayan-edms/mayan-edms/blob/master/mayan/apps/documents/templatetags/printing_tags.py
https://gitlab.com/mayan-edms/mayan-edms/blob/master/mayan/apps/appearance/templatetags/appearance_tags.py

To enable a set of tags in a template you need to load then using {% load appearance_tags %} for example will enable all tags and filters in the file appearance_tags.py

You can have many tag libraries for each app templatetags directory but a common suggestion is to have just one per app with the app name as the prefix (appearance_tags.py, folders_tags.py, etc).

You can create a complex tag subclassing the Node class (example: when you need an opening and closing tag like {% for %} {% endfor %}), but the easiest way it to use a decorated function that can read the template context and return a value. Less common and not recommended, but tags and filters can also modify the context to insert variables or change values of other variables.

On Thursday, April 20, 2017 at 9:05:46 AM UTC-4, MacRobb Simpson wrote:
Is there any way to define a simple class somewhere and call it using the template language to do this?
Something like how validators are made?

On Thursday, April 20, 2017 at 12:27:29 AM UTC-7, Roberto Rosario wrote:
Allowing interpreted Python code was later considered a security risk. These fields now use the template language of Django (<a href="https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.10%2Fref%2Ftemplates%2Flanguage%2F&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNGH5bfzqqQg_T5-xttrWYt1G7EIhg" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.10%2Fref%2Ftemplates%2Flanguage%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGH5bfzqqQg_T5-xttrWYt1G7EIhg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.10%2Fref%2Ftemplates%2Flanguage%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGH5bfzqqQg_T5-xttrWYt1G7EIhg&#39;;return true;">https://docs.djangoproject.com/en/1.10/ref/templates/language/) and expect a comma delimited output. So the years example would now be:

'1990', '1991', '1992', '1993', '1994', '1995', '1996', '1997', '1998', '1999', '2000'

without the brackets.

The second example cannot be done as the template language doesn't support range generators. This is some of the reasons switching to the Jinja2 template language is being considered. It is more secure than Python code, is a superset of Django's template language but add many Pythonistic tags line range().

--

---
You received this message because you are subscribed to the Google Groups "Mayan EDMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...