[Hejes-devel] [962] blog new feature: posts.showing field

hejes-devel at nytud.hu hejes-devel at nytud.hu
Tue Oct 1 11:49:37 CEST 2013


Revision: 962
Author:   root
Date:     2013-10-01 11:49:37 +0200 (Tue, 01 Oct 2013)
Log Message:
-----------
blog new feature: posts.showing field

Modified Paths:
--------------
    trunk/web2py/applications/helyesiras_webdev/controllers/blog.py
    trunk/web2py/applications/helyesiras_webdev/databases/blog_posts.table
    trunk/web2py/applications/helyesiras_webdev/databases/sql.log
    trunk/web2py/applications/helyesiras_webdev/databases/storage.sqlite
    trunk/web2py/applications/helyesiras_webdev/languages/hu-hu.py
    trunk/web2py/applications/helyesiras_webdev/models/dbblog.py
    trunk/web2py/applications/helyesiras_webdev/modules/blogutil.py
    trunk/web2py/applications/helyesiras_webdev/progress.log

Modified: trunk/web2py/applications/helyesiras_webdev/controllers/blog.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/controllers/blog.py	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/controllers/blog.py	2013-10-01 09:49:37 UTC (rev 962)
@@ -17,7 +17,7 @@
 def index():
   """Starting page for the blog.
      returns following keys:
-     posts: Rows object with most recent 5 blog posts
+     posts: Rows object with most recent 5 blog posts (where posts.showing=True)
      categories: Rows object with all category names and ids (for sidebar)
      tags: Rows object with all tag names and ids (for sidebar)
      ntotal: total number of posts available
@@ -28,8 +28,8 @@
     # all categories & tags for sidebar
     cats = dbblog().select(dbblog.categories.ALL, orderby=dbblog.categories.ordering)
     tags = dbblog().select(dbblog.tags.ALL, orderby=dbblog.tags.name)
-    # assemble query:  posts filtered by category or tag specified via args
-    query = dbblog.posts.category == dbblog.categories.id
+    # assemble query:  posts showing & filtered by category or tag specified via args
+    query = (dbblog.posts.showing == True) & (dbblog.posts.category == dbblog.categories.id)
     usercat = request.vars.get('category')
     if usercat:
       query &= (dbblog.categories.name == usercat)
@@ -39,7 +39,7 @@
     # prepare pagination
     rset = dbblog(query)
     ntotal = rset.count()
-    if ntotal == 0: # 0 articles found: redirect to index page with no args
+    if ntotal == 0 and (usercat or usertag): # 0 articles found: redirect to index page with no args
       redirect(URL(c='blog', f='index'))
     perpage = 5
     npages = (ntotal / perpage) + (1 if ntotal % perpage > 0 else 0)

Modified: trunk/web2py/applications/helyesiras_webdev/databases/blog_posts.table
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/databases/blog_posts.table	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/databases/blog_posts.table	2013-10-01 09:49:37 UTC (rev 962)
@@ -42,20 +42,20 @@
 ssS'lead'
 p16
 (dp17
-S'length'
+S'sortable'
 p18
-I255
-sS'unique'
+I5
+sS'sql'
 p19
-I00
-sS'sortable'
+S'VARCHAR(255)'
 p20
-I5
-sS'sql'
+sS'length'
 p21
-S'VARCHAR(255)'
+I255
+sS'notnull'
 p22
-sS'notnull'
+I00
+sS'unique'
 p23
 I00
 sS'type'
@@ -85,14 +85,37 @@
 p34
 S'string'
 p35
-ssS'title'
+ssS'showing'
 p36
 (dp37
+S'length'
+p38
+I255
+sS'unique'
+p39
+I00
+sS'sortable'
+p40
+I2
+sS'sql'
+p41
+S'CHAR(1)'
+p42
+sS'notnull'
+p43
+I00
+sS'type'
+p44
+S'boolean'
+p45
+ssS'title'
+p46
+(dp47
 g4
 I3
 sg5
 S'VARCHAR(255)'
-p38
+p48
 sg7
 I255
 sg8
@@ -101,32 +124,31 @@
 I00
 sg10
 S'string'
-p39
-ssS'id'
-p40
-(dp41
+p49
+ssS'slug'
+p50
+(dp51
 g4
-I1
+I2
 sg5
-S'INT AUTO_INCREMENT NOT NULL'
-p42
+S'VARCHAR(255) UNIQUE'
+p52
 sg7
 I255
 sg8
 I00
 sg9
-I00
+I01
 sg10
-S'id'
-p43
+g49
 ssS'created_on'
-p44
-(dp45
+p53
+(dp54
 g4
 I8
 sg5
 S'DATETIME'
-p46
+p55
 sg7
 I255
 sg8
@@ -135,31 +157,32 @@
 I00
 sg10
 S'datetime'
-p47
-ssS'slug'
-p48
-(dp49
+p56
+ssS'id'
+p57
+(dp58
 g4
-I2
+I1
 sg5
-S'VARCHAR(255) UNIQUE'
-p50
+S'INT AUTO_INCREMENT NOT NULL'
+p59
 sg7
 I255
 sg8
 I00
 sg9
-I01
+I00
 sg10
-g39
+S'id'
+p60
 ssS'tags'
-p51
-(dp52
+p61
+(dp62
 g4
 I6
 sg5
 S'LONGTEXT'
-p53
+p63
 sg7
 I255
 sg8
@@ -168,28 +191,28 @@
 I00
 sg10
 S'list:string'
-p54
+p64
 ssS'image_filename'
-p55
-(dp56
+p65
+(dp66
 S'sortable'
-p57
+p67
 I4
 sS'sql'
-p58
+p68
 S'VARCHAR(255)'
-p59
+p69
 sS'length'
-p60
+p70
 I255
 sS'notnull'
-p61
+p71
 I00
 sS'unique'
-p62
+p72
 I00
 sS'type'
-p63
+p73
 S'string'
-p64
+p74
 ss.
\ No newline at end of file

Modified: trunk/web2py/applications/helyesiras_webdev/databases/sql.log
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/databases/sql.log	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/databases/sql.log	2013-10-01 09:49:37 UTC (rev 962)
@@ -133,3 +133,8 @@
 timestamp: 2013-09-25T15:56:57.441677
 ALTER TABLE posts ADD lead VARCHAR(255);
 success!
+timestamp: 2013-10-01T11:15:18.415564
+ALTER TABLE posts ADD show CHAR(1);
+timestamp: 2013-10-01T11:16:33.625946
+ALTER TABLE posts ADD showing CHAR(1);
+success!

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

Modified: trunk/web2py/applications/helyesiras_webdev/languages/hu-hu.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/languages/hu-hu.py	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/languages/hu-hu.py	2013-10-01 09:49:37 UTC (rev 962)
@@ -105,6 +105,7 @@
 'Internal State': 'Internal State',
 'Introduction': 'Introduction',
 'Invalid email': 'Invalid email',
+'Invalid login': 'Invalid login',
 'Invalid Query': 'Hibás lekérdezés',
 'invalid request': 'hibás kérés',
 'Is Active': 'Is Active',
@@ -140,6 +141,7 @@
 'new record inserted': 'új bejegyzés felvéve',
 'next 100 rows': 'következő 100 sor',
 'No databases in this application': 'Nincs adatbázis ebben az alkalmazásban',
+'not authorized': 'not authorized',
 'not in': 'not in',
 'Nyitóoldal': 'Nyitóoldal',
 'Névkereső': 'Névkereső',
@@ -147,6 +149,7 @@
 'Online examples': 'online példákért kattints ide',
 'Or': 'Or',
 'or import from csv file': 'vagy betöltés csv fájlból',
+'Ordering': 'Ordering',
 'Origin': 'Origin',
 'Other Recipes': 'Other Recipes',
 'Overview': 'Overview',

Modified: trunk/web2py/applications/helyesiras_webdev/models/dbblog.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/models/dbblog.py	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/models/dbblog.py	2013-10-01 09:49:37 UTC (rev 962)
@@ -29,8 +29,9 @@
   #print('after update: {0}, {1}'.format(s, f))  
   dbblog.executesql('LOCK TABLES tags WRITE, posts READ;') # prevent other sessions from accessing while we're doing maintenance
   id = long(s.query.second) # s.select(dbblog.posts.id).first().id # id of post just updated
-  # 1. check whether each new tag is referred to from table tags
-  for tag in f['tags']: # tags just assigned to post
+  mytags = f['tags'] if f['showing'] else [] # set of tags in just updated post; if post is not showing, emulate empty set of tags
+  # 1. check whether each new tag is referred to from table tags  
+  for tag in mytags: # tags just assigned to post
     r = dbblog(dbblog.tags.name == tag).select() # get matching record from table tags
     if len(r) == 1: # matching record exists:
       if id not in r[0].posts: # check if contains reference to post, if not, update it
@@ -41,7 +42,7 @@
   # 2. for each record in table tags that refers to post: check if post still has tag, if not, delete reference/record
   to_delete = [] # ids of records that have to be deleted from table tags
   for row in dbblog(dbblog.tags.posts.contains(id)).select():
-    if row.name not in f['tags']:
+    if row.name not in mytags:
       if len(row.posts) > 1:
         dbblog(dbblog.tags.id == rid).update(posts = [x for x in row.posts if x != id]) # remove reference to post in question
       else:
@@ -56,10 +57,11 @@
   """Callback functions on insert operations on table posts in order to maintain table tags.
      f: a dict of fields passed to insert, id: the id of the newly inserted record
   """
-  print('after insert: {0}, {1}'.format(f, id))
-  #dbblog.executesql('LOCK TABLES tags WRITE, posts READ;') # prevent other sessions from accessing
+  #print('after insert: {0}, {1}'.format(f, id))
+  dbblog.executesql('LOCK TABLES tags WRITE, posts READ;') # prevent other sessions from accessing
+  mytags = f['tags'] if f['showing'] else [] # set of tags in just updated post; if post is not showing, emulate empty set of tags
   # Add each tag to table tags
-  for tag in f['tags']:
+  for tag in mytags:
     r = dbblog(dbblog.tags.name == tag).select() # get matching record from table tags
     if len(r) == 1: # matching record exists: update it
       dbblog(dbblog.tags.name == tag).update(posts = r.first().posts + [id])
@@ -73,10 +75,9 @@
   """Callback functions on insert operations on table posts in order to maintain table tags.
      s: Set object, records deleted
   """
-  print('after delete: {0}'.format(s))
-  #dbblog.executesql('LOCK TABLES tags WRITE, posts READ;') # prevent other sessions from accessing while we're doing maintenance
+  #print('after delete: {0}'.format(s))
+  dbblog.executesql('LOCK TABLES tags WRITE, posts READ;') # prevent other sessions from accessing while we're doing maintenance
   id = long(s.query.second) # id of post just deleted (gluon.DAL uses <Set (table.id = id)> for delete/update)
-  print('id of post just deleted: {0}'.format(id))
   # Delete references from matching records in table tags or delete matching records that only referenced this post
   to_delete = [] # ids of records that have to be deleted from table tags
   for row in dbblog(dbblog.tags.posts.contains(id)).select():
@@ -112,6 +113,7 @@
   )
   
 dbblog.define_table('posts', 
+  Field('showing', 'boolean'),
   Field('slug', unique=True), 
   Field('title'), 
   Field('image_filename'),

Modified: trunk/web2py/applications/helyesiras_webdev/modules/blogutil.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/blogutil.py	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/modules/blogutil.py	2013-10-01 09:49:37 UTC (rev 962)
@@ -24,7 +24,7 @@
      Note: all strings returned are type str, utf8 enc.
   """
   entries = []
-  posts = db(db.posts.category == db.categories.id).select(orderby=~db.posts.created_on, limitby=(0, limit))
+  posts = db((db.posts.showing == True) & (db.posts.category == db.categories.id)).select(orderby=~db.posts.created_on, limitby=(0, limit))
   for row in posts:
     post = row.posts
     entries.append(dict(title = post.title,
@@ -38,5 +38,3 @@
               description = "A helyesiras.mta.hu oldal hivatalos blogja",
               created_on = formatdate(mktime(datetime.datetime.now().timetuple()), localtime=True),
               entries = entries)
-
-

Modified: trunk/web2py/applications/helyesiras_webdev/progress.log
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/progress.log	2013-10-01 09:10:17 UTC (rev 961)
+++ trunk/web2py/applications/helyesiras_webdev/progress.log	2013-10-01 09:49:37 UTC (rev 962)
@@ -882,3 +882,29 @@
 [2013-09-27 15:28:23] EDIT helyesiras_webdev/views/right_sidebar.html: 2
 [2013-09-27 15:29:01] EDIT helyesiras_webdev/views/right_sidebar.html: -2
 [2013-09-27 15:37:42] EDIT helyesiras_webdev/views/right_sidebar.html: 0
+[2013-09-30 15:44:58] EDIT helyesiras_webdev/static/css/main.css: 2
+[2013-10-01 11:12:12] EDIT helyesiras_webdev/models/dbblog.py: 1
+[2013-10-01 11:14:59] EDIT helyesiras_webdev/models/dbblog.py: 1
+[2013-10-01 11:15:09] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:15:12] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:16:27] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:17:05] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:19:18] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:19:26] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:20:10] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:20:28] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:20:53] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:21:57] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:24:53] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:26:05] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:26:09] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:26:43] EDIT helyesiras_webdev/controllers/blog.py: 0
+[2013-10-01 11:27:39] EDIT helyesiras_webdev/models/dbblog.py: -1
+[2013-10-01 11:31:33] EDIT helyesiras_webdev/models/dbblog.py: 2
+[2013-10-01 11:31:53] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:32:09] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:33:31] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:33:46] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:34:29] EDIT helyesiras_webdev/models/dbblog.py: -1
+[2013-10-01 11:35:23] EDIT helyesiras_webdev/models/dbblog.py: 0
+[2013-10-01 11:40:05] EDIT helyesiras_webdev/modules/blogutil.py: 0




More information about the Hejes-devel mailing list