[Hejes-devel] [931] blog/manage: field image_filename can only take values of image file names in dir static /blog

hejes-devel at nytud.hu hejes-devel at nytud.hu
Wed Sep 11 16:02:34 CEST 2013


Revision: 931
Author:   mihaltz
Date:     2013-09-11 16:02:34 +0200 (Wed, 11 Sep 2013)
Log Message:
-----------
blog/manage: field image_filename can only take values of image file names in dir static/blog

Modified Paths:
--------------
    trunk/web2py/applications/helyesiras_webdev/databases/storage.sqlite
    trunk/web2py/applications/helyesiras_webdev/models/dbblog.py
    trunk/web2py/applications/helyesiras_webdev/modules/util.py

Modified: trunk/web2py/applications/helyesiras_webdev/databases/storage.sqlite
===================================================================
(Binary files differ)

Modified: trunk/web2py/applications/helyesiras_webdev/models/dbblog.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/models/dbblog.py	2013-09-11 13:12:34 UTC (rev 930)
+++ trunk/web2py/applications/helyesiras_webdev/models/dbblog.py	2013-09-11 14:02:34 UTC (rev 931)
@@ -5,6 +5,10 @@
 @author: MM
 """
 
+
+from util import list_image_files
+
+
 def create_index_if_not_exists(db, table, keyname, column, unique=False):
   """Check if index keyname on db.table.column exists.
      If not, execute sql statement 'CREATE (UNIQUE) INDEX...' and return True, otherwise return False.
@@ -86,7 +90,8 @@
     dbblog(dbblog.tags.id == rid).delete()
   dbblog.commit()
   dbblog.executesql('UNLOCK TABLES;') # remove lock
-  
+
+
 # -----------------------------------------------
 
 # Connection to the database (admin)
@@ -118,7 +123,7 @@
 
 dbblog.posts.slug.requires = IS_NOT_EMPTY()
 dbblog.posts.title.requires = IS_NOT_EMPTY()
-dbblog.posts.image_filename.requires = IS_NOT_EMPTY()
+dbblog.posts.image_filename.requires = IS_IN_SET(list_image_files('applications/'+URL('static', 'blog')))
 dbblog.posts.body.requires = IS_NOT_EMPTY()
 dbblog.posts.slug.requires = IS_NOT_EMPTY()
 dbblog.posts.category.requires = IS_IN_DB(dbblog, dbblog.categories.id, '%(name)s')

Modified: trunk/web2py/applications/helyesiras_webdev/modules/util.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/util.py	2013-09-11 13:12:34 UTC (rev 930)
+++ trunk/web2py/applications/helyesiras_webdev/modules/util.py	2013-09-11 14:02:34 UTC (rev 931)
@@ -54,4 +54,12 @@
   hn = [u'január', u'február', u'március', u'április', u'május', u'június', u'július', u'augusztus', u'szeptember', u'október', u'november', u'december']
   return u'{0}. {1} {2}. {3}:{4}'.format(d.year, hn[d.month-1], d.day, d.hour, d.minute)
   
-  
+
+def list_image_files(path):
+  """Return an array of image file names (relative) under path, sorted (sic)"""
+  from os.path import isfile
+  from os import listdir
+  from re import match
+  return sorted([x for x in listdir(path) if isfile(path+'/'+x) and match('.*\.[jpg|jpeg|png|gif|bmp|tif]', x)])
+
+




More information about the Hejes-devel mailing list