Skip to content

Commit

Permalink
it's kinda fixed, except it does not call get_humane_value for linked…
Browse files Browse the repository at this point in the history
… model's properties.

rref #5459
#GH-86
  • Loading branch information
evrenesat committed Aug 31, 2016
1 parent d257c48 commit 4114530
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions zengine/views/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
This module holds CrudView and related classes that helps building
CRUDS (Create Read Update Delete Search) type of views.
"""
from operator import attrgetter

import six

Expand All @@ -26,7 +27,6 @@
from zengine.views.base import BaseView



class ListForm(forms.JsonForm):
"""
Holds list view form elements.
Expand All @@ -47,9 +47,10 @@ class ObjectForm(forms.JsonForm):
save_edit = fields.Button("Kaydet", cmd="save::add_edit_form")
save_list = fields.Button("Kaydet ve Listele", cmd="save::list")
save_as_new_edit = fields.Button("Yeni Olarak Kaydet",
cmd="save_as_new::add_edit_form")
cmd="save_as_new::add_edit_form")
save_as_new_list = fields.Button("Yeni Olarak Kaydet ve Listele",
cmd="save_as_new::list")
cmd="save_as_new::list")


class CrudMeta(type):
"""
Expand Down Expand Up @@ -174,8 +175,6 @@ def clear_model_list_cache(sender, *args, **kwargs):
SelectBoxCache.flush(sender.model_class.__name__)




@six.add_metaclass(CrudMeta)
class CrudView(BaseView):
"""
Expand Down Expand Up @@ -257,10 +256,9 @@ class ObjectForm(forms.JsonForm):
save_list = fields.Button("Kaydet ve Listele", cmd="save::list")
if settings.DEBUG:
save_as_new_edit = fields.Button("Yeni Olarak Kaydet",
cmd="save_as_new::add_edit_form")
cmd="save_as_new::add_edit_form")
save_as_new_list = fields.Button("Yeni Olarak Kaydet ve Listele",
cmd="save_as_new::list")

cmd="save_as_new::list")

def __init__(self, current=None):
self.FILTER_METHODS = []
Expand Down Expand Up @@ -391,8 +389,8 @@ def create_initial_object(self):
self.object = self.model_class(self.current).objects.get(object_id)
except ObjectDoesNotExist:
raise HTTPError(404, "Possibly you are trying to retrieve a just deleted "
"object or object key (%s) does not belong to current model:"
" %s" % (object_id, self.model_class.__name__))
"object or object key (%s) does not belong to current model:"
" %s" % (object_id, self.model_class.__name__))
except:
raise
# elif 'added_obj' in self.current.task_data:
Expand Down Expand Up @@ -489,13 +487,20 @@ def _apply_list_search(self, query):
@obj_filter
def _get_list_obj(self, obj, result):
fields = self.object.Meta.list_fields

if fields:
for f in self.object.Meta.list_fields:
field = getattr(obj, f)
if callable(field):
result['fields'].append(field())
field = getattr(obj, f, None)
field_str = ''
if isinstance(field, Model):
field_str = six.text_type(field)
elif callable(field):
field_str = field()
elif '.' in f:
field_str = attrgetter(f)(obj)
else:
result['fields'].append(obj.get_humane_value(f))
field_str = obj.get_humane_value(f)
result['fields'].append(field_str)
else:
result['fields'] = [six.text_type(obj)]

Expand Down Expand Up @@ -713,8 +718,8 @@ def select_list(self):
search_str = self.input.get('query', '')
cache = SelectBoxCache(self.model_class.__name__, search_str)
self.output['objects'] = cache.get() or cache.set(
[{'key': obj.key, 'value': six.text_type(obj)}
for obj in query])
[{'key': obj.key, 'value': six.text_type(obj)}
for obj in query])

@view_method
def object_name(self):
Expand All @@ -731,7 +736,7 @@ def show(self):
"""
self.set_client_cmd('show')
obj_form = forms.JsonForm(self.object, current=self.current, models=False,
list_nodes=False)._serialize(readable=True)
list_nodes=False)._serialize(readable=True)
obj_data = {}
for d in obj_form:
val = d['value']
Expand All @@ -743,11 +748,10 @@ def show(self):

obj_data[key] = val
self.form_out(forms.JsonForm(title="%s : %s" % (self.model_class.Meta.verbose_name,
self.object)))
self.object)))
self.output['object_key'] = self.object.key
self.output['object'] = obj_data


@view_method
def add_edit_form(self):
"""
Expand Down

0 comments on commit 4114530

Please sign in to comment.