Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Use viewset.layout in the detail view #194

Open
kmmbvnr opened this issue Nov 15, 2016 · 8 comments
Open

Use viewset.layout in the detail view #194

kmmbvnr opened this issue Nov 15, 2016 · 8 comments

Comments

@kmmbvnr
Copy link
Collaborator

kmmbvnr commented Nov 15, 2016

https://gitter.im/viewflow/django-material

Jose Juan Tapia @jjtapia 02:47
Another question. I noticed that the default view contains a simple enumeration of the model fields from a given entry
like so: http://forms.viewflow.io/integration/sea/11/detail/
while the change option contained the layout defined in views.py: http://forms.viewflow.io/integration/sea/11/change/
is there a way of making this change layout the default that is shown in .../detail?

@marctc
Copy link
Contributor

marctc commented Feb 20, 2017

I'm working on this but my approach needs that you have to pass form_class to DetailView and then rewrite all the templates in material/fields in order to only print the label and the value. What do you think? Could be useful for you?

cheers!

@kmmbvnr
Copy link
Collaborator Author

kmmbvnr commented Feb 21, 2017

Yeah, that's the hard question.

To have reasonable looking good detail view by default is the nice feature, but anyway it's supposed to be overridden in real projects. So it won't be good if the solution for this optional feature would overcomplicate the other part of the codebase.

Currently the layout primitives Row/Column/Fieldset are too bound to the form rendering. From another side, getting a text representation for a model value is hard without a widget. So, there is no simple way to reuse a layout without form instance. But I don't think that the detail view should look exactly like a form but with all widgets disabled. That's is too crudy. Just a disabled text inputs would be enough for most cases.

Your approach looks reasonable, as implementing a template pack that renders a form in a read-only state, without actually do the tricks on a python side.

{% form template='material/readonly/form.html' %}

This would be the really useful feature, in many scenarios beyond the frontend.detail view.

It looks that only a few templates could be overridden. django-material lookup for the template according to a class inheritance mro. So the material/readonly/fields/django_widget.html is the catch-all template.

django-material have some code to get a field value for the list view. You can take a look what django have in django.contrib.admin.utils.display_for_field and django.contrib.admin.utils.display_for_value and what placed in the material.frontend.views.list.DataTableMixin.display_for_field

We can move display_for_field code to the utility module and expose it as a template tag to use it in a widget generic template. If it isn't enough, few templates for a Select/FK could also be added.

@marctc
Copy link
Contributor

marctc commented Feb 21, 2017

Hi,

But I don't think that the detail view should look exactly like a form but with all widgets disabled.

Absolutely agree, thats why I want to replace field template with non-form elements (inputs, radios, etc).

Take a look at the PoC:

APSL@789fd1b

This is that's look like:

form:
selection_040

detail:
selection_041

@kmmbvnr
Copy link
Collaborator Author

kmmbvnr commented Feb 21, 2017

{% form template='' %} sets the base path for the whole template_pack. So, there is possibility to write {% form template='bootstrap/form.html' %} to render a boostrap styled form with django-material =)

Check the template selection code; it chooses the most specific template for the widget. If the template pack contains a single fields/django_widget.html file, the template would be selected for all form fields.

@marctc
Copy link
Contributor

marctc commented Feb 21, 2017

{% form template='' %} sets the base path for the whole template_pack. So, there is possibility to write {% form template='bootstrap/form.html' %} to render a boostrap styled form with django-material =)

cool!

Check the template selection code; it chooses the most specific template for the widget. If the template pack contains a single fields/django_widget.html file, the template would be selected for all form fields.

Are you sure about that? For an input field, it drops me the following:

template_names
Out[2]: 
['material/frontend/detail/fields/django_textinput.html',
 'material/frontend/detail/fields/django_input.html',
 'material/frontend/detail/fields/django_charfield/django_textinput.html',
 'material/frontend/detail/fields/django_charfield/django_input.html']

@kmmbvnr
Copy link
Collaborator Author

kmmbvnr commented Feb 21, 2017

ups, that's b/c we have -2 here

It could be simply adjusted to -1

@marctc
Copy link
Contributor

marctc commented Feb 21, 2017

Yeah, it worked. Thanks

@kmmbvnr
Copy link
Collaborator Author

kmmbvnr commented Mar 16, 2017

Several material-design samples of the detail view

material-design-sketch-template
material-design-view

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants