librelist archives

« back to archive

[PATCH 0 of 3] Patches to contrib.admin templates ans forms

[PATCH 0 of 3] Patches to contrib.admin templates ans forms

From:
Krivushin Mihail
Date:
2010-08-11 @ 13:41
Patches to admin and forms.

In admin site rename block from content to admin_content.

In forms add float to fields and correct validators logic.

[PATCH 1 of 3] fields

From:
Krivushin Mihail
Date:
2010-08-11 @ 13:41
# HG changeset patch
# User Mikhail Krivushin <krivushinme@gmail.com>
# Date 1272729377 -25200
# Branch fields
# Node ID 985372412a4a58655ec1bf9b8379c2cd74e1eeda
# Parent  728289952b1c1e35d3112f34c01a7083bc4c5640
fields

diff -r 728289952b1c -r 985372412a4a svarga/core/metadata.py
--- a/svarga/core/metadata.py	Sat Apr 24 13:48:48 2010 +0300
+++ b/svarga/core/metadata.py	Sat May 01 22:56:17 2010 +0700
@@ -48,3 +48,4 @@
     def __init__(cls, name, bases, attrs):
         inherit_metadata(cls, bases, attrs)
         super(MetadataMeta, cls).__init__(name, bases, attrs)
+
diff -r 728289952b1c -r 985372412a4a svarga/db/models.py
--- a/svarga/db/models.py	Sat Apr 24 13:48:48 2010 +0300
+++ b/svarga/db/models.py	Sat May 01 22:56:17 2010 +0700
@@ -45,8 +45,12 @@
     def count(self):
         raise NotImplemented()
 
-# Foreign key column
-class StringColumn(object):
+
+# columns
+class Column(object):
+    pass
+
+class StringColumn(Column):
     def __init__(self, max_length=None, **kwargs):
         self.max_length = max_length
         self.kwargs = kwargs
@@ -60,45 +64,64 @@
 class UnicodeTextColumn(StringColumn):
     pass
 
-class BooleanColumn(object):
+class BooleanColumn(Column):
     def __init__(self, **kwargs):
         self.kwargs = kwargs
 
-class IntegerColumn(object):
+class IntegerColumn(Column):
     def __init__(self, **kwargs):
         self.kwargs = kwargs
 
-class FloatColumn(object):
+class FloatColumn(Column):
     def __init__(self, **kwargs):
         self.kwargs = kwargs
 
-class DateTimeColumn(object):
+class DateTimeColumn(Column):
     def __init__(self, **kwargs):
         self.kwargs = kwargs
 
-class DateColumn(object):
+class DateColumn(Column):
     def __init__(self, **kwargs):
         self.kwargs = kwargs
 
-class TimeColumn(object):
+class TimeColumn(Column):
     def __init__(self, **kwargs):
         self.kwargs = kwargs
 
-class ForeignKeyColumn(object):
+class ForeignKeyColumn(Column):
     def __init__(self, model, **kwargs):
         self.model = model
         self.kwargs = kwargs
 
-class OneToOneColumn(object):
+class OneToOneColumn(Column):
     def __init__(self, model, **kwargs):
         self.model = model
         self.kwargs = kwargs
 
-class ManyToManyColumn(object):
+class ManyToManyColumn(Column):
     def __init__(self, model, **kwargs):
         self.model = model
         self.kwargs = kwargs
 
+
+class Fields(object):
+    """ Container class for columns
+    """
+    StringColumn = StringColumn
+    UnicodeColumn = UnicodeColumn
+    TextColumn = TextColumn
+    UnicodeTextColumn = UnicodeTextColumn
+    BooleanColumn = BooleanColumn
+    IntegerColumn = IntegerColumn
+    FloatColumn = FloatColumn
+    DateTimeColumn = DateTimeColumn
+    DateColumn = DateColumn
+    TimeColumn = TimeColumn
+    ForeignKeyColumn = ForeignKeyColumn
+    OneToOneColumn = OneToOneColumn
+    ManyToManyColumn = ManyToManyColumn
+
+
 # Model factory
 def factory(table_prefix=None, backend=None):
     return DbBackends.get_backend_class(backend).get_factory(table_prefix)
@@ -111,3 +134,4 @@
     "sync_db() shortcut"
     for f in DbBackends.get_backend_instances():
         f.sync_db()
+
diff -r 728289952b1c -r 985372412a4a svarga/db/sqla/process.py
--- a/svarga/db/sqla/process.py	Sat Apr 24 13:48:48 2010 +0300
+++ b/svarga/db/sqla/process.py	Sat May 01 22:56:17 2010 +0700
@@ -3,9 +3,19 @@
 import sqlalchemy as sa
 
 from svarga.utils.imports import import_attribute
+from svarga.db.models import Column as BaseColumn
 
 TABLE_PREFIX_ATTRIBUTE = '_svarga_table_prefix'
 
+#######
+class Column(BaseColumn, sa.Column):
+    pass
+
+class StringColumn(Column):
+    pass
+
+#############
+
 def preprocess_generic(cell):
     def preprocessor(cls, bases, fields, primary_key, name, column):
         fields[name] = sa.Column(cell, **column.kwargs)
@@ -151,6 +161,25 @@
     'ManyToManyColumn': preprocess_manytomany,
     }
 
+
+class Fields(object):
+    """ Container class for columns
+    """
+    StringColumn = StringColumn
+    UnicodeColumn = UnicodeColumn
+    TextColumn = TextColumn
+    UnicodeTextColumn = UnicodeTextColumn
+    BooleanColumn = BooleanColumn
+    IntegerColumn = IntegerColumn
+    FloatColumn = FloatColumn
+    DateTimeColumn = DateTimeColumn
+    DateColumn = DateColumn
+    TimeColumn = TimeColumn
+    ForeignKeyColumn = ForeignKeyColumn
+    OneToOneColumn = OneToOneColumn
+    ManyToManyColumn = ManyToManyColumn
+
+
 class ModelContribute(object):
     # Common exceptions
     IntegrityError = sa.exc.IntegrityError

[PATCH 2 of 3] Rename Admin 'context' to 'admin_context' for better integration in sites

From:
Krivushin Mihail
Date:
2010-08-11 @ 13:41
# HG changeset patch
# User Mikhail Krivushin <krivushinme@gmail.com>
# Date 1281534006 -14400
# Node ID b4065b3a9013e9ec3929f07f389c338ba4f36178
# Parent  72f22c914f8750a9a9d674ed10f8f97247c88d23
Rename Admin 'context' to 'admin_context' for better integration in sites.

diff -r 72f22c914f87 -r b4065b3a9013 svarga/contrib/admin/templates/index.html
--- a/svarga/contrib/admin/templates/index.html	Mon Jul 19 18:15:17 2010 +0300
+++ b/svarga/contrib/admin/templates/index.html	Wed Aug 11 17:40:06 2010 +0400
@@ -1,3 +1,3 @@
 {% extends env.settings.ADMIN_TEMPLATE %}
-{% block content %}
+{% block admin_content %}
 {% endblock %}
diff -r 72f22c914f87 -r b4065b3a9013 svarga/contrib/admin/templates/master.html
--- a/svarga/contrib/admin/templates/master.html	Mon Jul 19 18:15:17 2010 +0300
+++ b/svarga/contrib/admin/templates/master.html	Wed Aug 11 17:40:06 2010 +0400
@@ -1,7 +1,7 @@
 {% import 'contrib.admin/lib.html' as lib %}
 <html>
   <head>
-    {% block head %}{% endblock %}
+    {% block admin_head %}{% endblock %}
     <title>
       {% block title %}
       {% if env.admin_view.Meta.menu %}
@@ -16,12 +16,12 @@
   <body>
     <div class="svarga">
       <div class="admin_menu">
-        {% block menu %}
+        {% block admin_menu %}
         {{ lib.menu(env.admin_view.menu_node) }}
         {% endblock %}
       </div>
       <div class="admin_content">
-        {% block content %}{% endblock %}
+        {% block admin_content %}{% endblock %}
       </div>
     </div>
   </body>
diff -r 72f22c914f87 -r b4065b3a9013 
svarga/contrib/admin/templates/model/edit.html
--- a/svarga/contrib/admin/templates/model/edit.html	Mon Jul 19 18:15:17 
2010 +0300
+++ b/svarga/contrib/admin/templates/model/edit.html	Wed Aug 11 17:40:06 
2010 +0400
@@ -1,5 +1,5 @@
 {% extends env.settings.ADMIN_TEMPLATE %}
-{% block content %}
+{% block admin_content %}
 
 <form method="POST" action="">
   <table>
diff -r 72f22c914f87 -r b4065b3a9013 
svarga/contrib/admin/templates/model/index.html
--- a/svarga/contrib/admin/templates/model/index.html	Mon Jul 19 18:15:17 
2010 +0300
+++ b/svarga/contrib/admin/templates/model/index.html	Wed Aug 11 17:40:06 
2010 +0400
@@ -1,5 +1,5 @@
 {% extends env.settings.ADMIN_TEMPLATE %}
-{% block content %}
+{% block admin_content %}
 
 <div>
   <a href="{{ env.admin_view.reverse('new') }}">Add new</a>

[PATCH 3 of 3] change validators apply logic and add float

From:
Krivushin Mihail
Date:
2010-08-11 @ 13:41
# HG changeset patch
# User Mikhail Krivushin <krivushinme@gmail.com>
# Date 1281534065 -14400
# Node ID 752113ba9066026f30999065f4d56157b586edf5
# Parent  b4065b3a9013e9ec3929f07f389c338ba4f36178
change validators apply logic and add float.

diff -r b4065b3a9013 -r 752113ba9066 svarga/forms/model.py
--- a/svarga/forms/model.py	Wed Aug 11 17:40:06 2010 +0400
+++ b/svarga/forms/model.py	Wed Aug 11 17:41:05 2010 +0400
@@ -150,6 +150,7 @@
         'Text': fields.TextAreaField,
         'Integer': fields.IntegerField,
         'SmallInteger': fields.IntegerField,
+        'Float': fields.DecimalField,
         'Numeric': fields.IntegerField,
         'DateTime': fields.DateTimeField,
         'Boolean': fields.BooleanField,
@@ -177,7 +178,7 @@
             kwargs['validators'].append(
                 validators.length(max=field.max_length))
 
-        if not field.nullable:
+        if not field.nullable and not field.default and not ftype in 
('ForeignKey', 'ManyToMany', 'ManyToOne'):
             kwargs['validators'].append(validators.required())
 
         # If relation - try to find related class and feed it to the field