Permalink
Browse files

Fix STATIC_FOLDER process

  • Loading branch information...
1 parent bd0ddbb commit 611ca37dbb8996e0064db9607657eeeac6186e54 @limodou committed Feb 25, 2013
View
@@ -30,7 +30,7 @@ def test_1():
<div class="control-group" id="div_field_content">
<label class="control-label" for="field_content">Content:</label>
<div class="controls">
- <textarea class="field" cols id="field_content" name="content" placeholder="" rows="10"></textarea>
+ <textarea class="field" cols id="field_content" name="content" placeholder="" rows="4"></textarea>
<p class="help help-block"></p>
</div>
<BLANKLINE>
@@ -192,14 +192,14 @@ def test_text_field():
"""
>>> a = TextField(name='text', id='field_text')
>>> print a.html('Test')
- <textarea class="field" cols id="field_text" name="text" placeholder="" rows="10">Test</textarea>
+ <textarea class="field" cols id="field_text" name="text" placeholder="" rows="4">Test</textarea>
"""
def test_textlines_field():
"""
>>> a = TextLinesField(name='list', id='field_list')
>>> print a.html(['a', 'b'])
- <textarea class="field" cols="40" id="field_list" name="list" placeholder="" rows="4">a
+ <textarea class="field" cols id="field_list" name="list" placeholder="" rows="4">a
b</textarea>
"""
@@ -220,7 +220,7 @@ def test_int_field():
"""
>>> a = IntField(name='int', id='field_int')
>>> print a.html('Test')
- <input class="field" id="field_int" name="int" placeholder="" type="text" value="Test"></input>
+ <input class="field" id="field_int" name="int" placeholder="" type="number" value="Test"></input>
>>> print a.validate('')
(True, 0)
>>> print a.validate(None)
@@ -18,7 +18,7 @@ def __init__(self, app, STATIC_URL, disallow=None, cache=True,
self.exports = {}
self.cache = cache
self.cache_timeout = cache_timeout
- path = os.path.normpath(settings.STATICFILES.STATIC_FOLDER)
+ path = os.path.normpath(settings.STATICFILES.get('STATIC_FOLDER', ''))
if path == '.':
path = ''
self.exports[self.url_suffix] = self.loader(path)
@@ -1,6 +1,6 @@
#coding=utf-8
-from uliweb.orm import Model, Field, get_model as _get_model
+from uliweb.orm import Model, Field, get_model as _get_model, NotFound
from uliweb.utils.common import get_var
import datetime
@@ -24,12 +24,22 @@ def get_model(cls, table):
obj = cls.get(cls.c.table_name == table)
if obj:
return _get_model(obj.table_name)
+ else:
+ raise NotFound("Can't find model of table [%s]" % str(table))
+
+ @classmethod
+ def get_tablename(cls, table_id):
+ obj = cls.get(cls.c.id == table)
+ if obj:
+ return obj.table_name
+ else:
+ raise NotFound("Can't find table according to table_id [%d]" % table_id)
@classmethod
def get_object(cls, table, object_id):
model = cls.get_model(table)
if not model:
- raise Error('Table %r is not existed' % table)
+ raise NotFound('Table %r is not existed' % table)
return model.get(object_id)
def __unicode__(self):
@@ -1,3 +1,3 @@
[MODELS]
-tables = 'tables.models.Tables'
+tables = 'uliweb.contrib.tables.models.Tables'
View
@@ -189,7 +189,11 @@ def __call__(self, f):
from uliweb.utils.common import safe_import
if isinstance(f, (str, unicode)):
- _, f = safe_import(f)
+ try:
+ _, f = safe_import(f)
+ except:
+ log.error('Import error: rule=%s' % f)
+ raise
self.parse(f)
return f
View
@@ -292,29 +292,28 @@ def to_python(self, data):
"""
Convert a data to python format.
"""
- data = data.strip()
+ if data is None:
+ return ''
if isinstance(data, unicode):
data = data.encode(DEFAULT_ENCODING)
else:
data = str(data)
return data
class UnicodeField(BaseField):
- def __init__(self, label='', default='', required=False, validators=None, name='', html_attrs=None, help_string='', build=None, encoding='utf-8', **kwargs):
+ def __init__(self, label='', default='', required=False, validators=None, name='', html_attrs=None, help_string='', build=None, **kwargs):
BaseField.__init__(self, label=label, default=default, required=required, validators=validators, name=name, html_attrs=html_attrs, help_string=help_string, build=build, **kwargs)
- self.encoding = encoding
def to_python(self, data):
"""
Convert a data to python format.
"""
if data is None:
- return data
- data = data.strip()
+ return u''
if isinstance(data, unicode):
return data
else:
- return unicode(data, self.encoding)
+ return unicode(data, DEFAULT_ENCODING)
class PasswordField(StringField):
default_build = Password
@@ -360,6 +359,19 @@ def html(self, data='', py=True):
value = value.replace('&', '&amp;')
return str(self.build(value, id='field_'+self.name, name=self.name, rows=self.rows, cols=self.cols, **self.html_attrs))
+ def to_python(self, data):
+ """
+ Convert a data to python format.
+ """
+ if data is None:
+ return ''
+ if isinstance(data, self.datatype):
+ return data
+ if self.datatype is unicode:
+ return unicode(data, DEFAULT_ENCODING)
+ else:
+ return data.encode(DEFAULT_ENCODING)
+
class TextLinesField(TextField):
def __init__(self, label='', default=None, required=False, validators=None, name='', html_attrs=None, help_string='', build=None, datatype=str, rows=4, cols=None, **kwargs):
TextField.__init__(self, label=label, default=default, required=required, validators=validators, name=name, html_attrs=html_attrs, help_string=help_string, build=build, rows=rows, cols=cols, **kwargs)
View
@@ -12,6 +12,7 @@ class LazyString(object):
def __init__(self, func, message):
self._func = func
self.msg = message
+ self._format = []
def __unicode__(self):
if not self.msg:
@@ -31,8 +32,15 @@ def __str__(self):
else:
return str(value)
+ def format(self, *args, **kwargs):
+ self._format.append((args, kwargs))
+ return self
+
def getvalue(self):
- return self._func(self.msg)
+ v = self._func(self.msg)
+ for args, kwargs in self._format:
+ v = v.format(*args, **kwargs)
+ return v
def __repr__(self):
return "%s_lazy(%r)" % (self._func.__name__, self.msg)
View
@@ -453,7 +453,7 @@ def handle(self, options, global_options, *args):
for f in apps:
m = '%s.%s' % (f, command)
try:
- mod = __import__(m, {}, {}, [''])
+ mod = __import__(m, fromlist=['*'])
if global_options.verbose:
print "Importing... %s.%s" % (f, command)
if hasattr(mod, 'call'):
View
@@ -4,6 +4,7 @@
from uliweb.form import SelectField, BaseField
import os, sys
import time
+import inspect
from uliweb.orm import get_model, Model, Result, do_, Lazy
import uliweb.orm as orm
from uliweb import redirect, json, functions, UliwebError, Storage
@@ -218,10 +219,10 @@ def __set__(self, model_instance, value):
raise ValueError("The value of GenericReference should be two-elements tuple/list, or instance of Model, but %r found" % value)
table_id, object_id = value
- if issubclass(table_id, orm.Model):
- table_id = table_id.tablename
if isinstance(table_id, (str, unicode)):
table_id = self.table.get_table(table_id).id
+ if inspect.isclass(table_id) and issubclass(table_id, orm.Model):
+ table_id = table_id.tablename
elif isinstance(value, orm.Model):
table_id = self.table.get_table(value.tablename).id
object_id = value.id

0 comments on commit 611ca37

Please sign in to comment.