Browse Source

Several more bug-fixes

Marcos Dumay de Medeiros 9 years ago
parent
commit
738144a5ca

+ 5 - 0
src/rapid/templates/rapid/bare/select.html

@@ -62,6 +62,11 @@
     {% endfor %}
 </table>
 <p><a class="overlay-commit btn btn-default">Adicionar na seleção</a></p>
+<p>{% for a, u in model.actions %}
+	{% if a.action.name != 'list' %}
+		<a href="{{ u }}" class="better-in-overlay btn btn-default"><span class="fa {{ a.action.icon }}">{{ a.action.verbose_name.capitalize }}</span></a>
+	{% endif %}
+{% endfor %}</p>
 {% pagination %}
 <script>
      $(document).ready(function(){

+ 3 - 1
src/rapid/templates/rapid/list/show_value.html

@@ -3,5 +3,7 @@
         <a href={{ u }} class="better-in-overlay"><span class="fa {{ a.action.icon }}" label="{{ a.action.verbose_name.capitalize }}"></span></a>
     {% endfor %}
 {% else %}
-    {{ val }}
+    {{ val }}{% for a, u in val_data.list_actions %}
+        <a href={{ u }} class="better-in-overlay"><span class="fa {{ a.action.icon }}" label="{{ a.action.verbose_name.capitalize }}"></span></a>
+    {% endfor %}
 {% endif %}

+ 2 - 2
src/rapid/urls.py

@@ -27,7 +27,7 @@ _manage_users_permistion = permissions.Permission(
 urlpatterns = register.model(Application, write_set=permissions.to_superusers(), read_set=permissions.to_all()) +\
     register.model(Profile, write_set=permissions.to_superusers(), read_set=permissions.to_staff()) +\
     register.instance_form(Profile, 'manage_users', u'Gerenciar Usuários',
-                            ManageUsers, _manage_users_permistion, "fa-users",
-                            Action.Visibility.list) +\
+                            ManageUsers, _manage_users_permistion, icon="fa-users",
+                            visibility=Action.Visibility.list) +\
     register.select(User, ['username'], permissions.to_staff(), 'usuario')
 

+ 49 - 22
src/rapid/wrappers.py

@@ -21,12 +21,14 @@ class InstanceData:
         self._fields = fields if fields else self.model.fields()
 
     def values(self):
+        r = []
         o = self.instance
         for f in self.model.fields():
             if f.is_relation:
-                yield self._value_of_field(o, f)
+                r.append(self._value_of_field(o, f))
             else:
-                yield self._value_of_field(o, f)
+                r.append(self._value_of_field(o, f))
+        return r
 
     def _value_of_field(self, instance, field):
         """
@@ -36,8 +38,8 @@ class InstanceData:
         e o terceiro elemento é uma sequencia de URLs para os itens do primeiro elemento,
         ou um valor falso caso não haja links.
         """
-        if hasattr(instance, field.bare_name()):
-            v = getattr(instance, field.bare_name())
+        if hasattr(instance, field.accessor_name()):
+            v = getattr(instance, field.accessor_name())
         else:  # Many to many relations without value may disappear
             return [], True
         if hasattr(v, '__iter__'):
@@ -49,9 +51,11 @@ class InstanceData:
         return (v, ()), False
 
     def fields_and_values(self):
+        r = []
         for field in self.model.fields():
             value, is_multiple = self._value_of_field(self.instance, field)
-            yield field, value, is_multiple
+            r.append((field, value, is_multiple))
+        return r
 
     def is_controlled(self):
         return self.model.is_controlled()
@@ -91,27 +95,35 @@ class InstanceData:
         return registry.get_url_of_action(self.model.model, "select")
 
     def actions(self):
+        r = []
         acts = registry.model_entry(self.model.model)
-        if self.request:
+        if self.request and acts:
             for a in acts.values():
                 if self.has_permission(self.request, a.action.name) and\
                         a.action.visibility > Action.Visibility.hidden:
-                    yield (a, a.get_url(self.instance))
+                    r.append((a, a.get_url(self.instance)))
+        return r
 
     def model_actions(self):
+        r = []
         for (a, u) in self.actions():
             if not a.action.query_parameters:
-                yield (a, u)
+                r.append((a, u))
+        return r
 
     def instance_actions(self):
+        r = []
         for (a, u) in self.actions():
             if a.action.query_parameters:
-                yield (a, u)
+                r.append((a, u))
+        return r
 
     def list_actions(self):
+        r = []
         for (a, u) in self.instance_actions():
             if a.action.visibility == Action.Visibility.list:
-                yield (a, u)
+                r.append((a, u))
+        return r
 
     def has_permission(self, request, action_name):
         m = registry.model_entry(self.model.model).get(action_name)
@@ -146,32 +158,34 @@ class ModelData:
         return self.model._default_manager
 
     def all_fields(self):
+        r = []
         relations = []
         for f in itertools.chain(self.local_fields(), self.related_fields()):
             if f.is_relation():
                 relations.append(f)
             else:
                 if f.name not in self.excludes:
-                    yield f
+                    r.append(f)
         for f in relations:
             if f.name not in self.excludes:
-                yield f
+                r.append(f)
+        return r
 
     def fields(self):
-        for f in self._fields:
-            yield f
+        return self._fields
 
     def local_fields(self):
+        r = []
         for f in self.model._meta.local_fields:
             if f.name not in self.excludes:
-                yield FieldData(f, self.request)
+                r.append(FieldData(f, self.request))
         for f in self.model._meta.local_many_to_many:
             if f.name not in self.excludes:
-                yield FieldData(f, self.request)
+                r.append(FieldData(f, self.request))
+        return r
 
     def related_fields(self):
-        for f in self.model._meta.get_all_related_objects():
-            yield FieldData(f, self.request)
+        return [FieldData(f, self.request) for f in self.model._meta.get_all_related_objects()]
 
     def is_controlled(self):
         return registry.is_controlled(self.model)
@@ -200,13 +214,14 @@ class ModelData:
         return registry.get_url_of_action(self.model, "select")
 
     def actions(self):
+        r = []
         acts = registry.model_entry(self.model)
-        if self.request:
+        if self.request and acts:
             for a in acts.values():
                 if self.has_permission(self.request, a.action.name) and\
                         not a.action.query_parameters and\
                         a.action.visibility > Action.Visibility.hidden:
-                    yield (a, a.get_url())
+                    r.append((a, a.get_url()))
 
     def has_permission(self, request, action_name):
         m = registry.model_entry(self.model).get(action_name)
@@ -240,14 +255,21 @@ class FieldData:
     def bare_name(self):
         return unicode(self.field.name)
 
+    def accessor_name(self):
+        if hasattr(self.field, 'get_accessor_name'):
+            return unicode(self.field.get_accessor_name())
+        return unicode(self.field.name)
+
     def name(self):
-        if self.is_auto():
-            return ModelData(self.related_model()).model_name_plural()
+        if self.is_auto() and self.is_relation():
+            return self.related_model().model_name_plural() + u' - ' + self.related_field().name()
         if hasattr(self.field, "verbose_name"):
             return unicode(self.field.verbose_name)
         return unicode(self.field.name)
 
     def name_plural(self):
+        if self.is_auto() and self.is_relation():
+            return self.related_model().model_name_plural() + u' - ' + self.related_field().name_plural()
         if hasattr(self.field, "verbose_name_plural"):
             return unicode(self.field.verbose_name_plural)
         return self.name() + "s"
@@ -271,6 +293,11 @@ class FieldData:
             return ModelData(self.field.to)
         return None
 
+    def related_field(self):
+        if hasattr(self.field, "field"):
+            return FieldData(self.field.field, self.request)
+        return None
+
     def is_auto(self):
         return self.field.auto_created