Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cil-cf2c65d5: Now does a check to see if duplicate nodes names are in…

… the same section
  • Loading branch information...
commit 4c3872fcaae01899301ac4e97590209a6aeebea1 1 parent b74fe77
@chilts chilts authored
View
6 issues/c_d604556a.cil
@@ -0,0 +1,6 @@
+Issue: cf2c65d5
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+Inserted: 2009-12-17T09:21:31
+Updated: 2009-12-17T09:21:47
+
+Added some code. Will check in production whether it works or not :)
View
5 issues/i_cf2c65d5.cil
@@ -1,10 +1,11 @@
Summary: After a node has been inserted or updated, check for duplicates
-Status: New
+Status: Finished
CreatedBy: Andrew Chilton <andychilton@gmail.com>
AssignedTo: Andrew Chilton <andychilton@gmail.com>
Label: Milestone-v0.03
+Comment: d604556a
Inserted: 2009-11-22T04:51:45
-Updated: 2009-12-17T04:10:13
+Updated: 2009-12-17T09:21:47
After a node has been inserted or updated, checks to make sure a duplicate node
name hasn't been used. If a clash has been found, the author of the newer
View
3  page.py
@@ -5,6 +5,7 @@
# Google specific modules
from google.appengine.ext import db
+from google.appengine.api.labs.taskqueue import Task
# local modules
from models import Section, Page
@@ -81,6 +82,8 @@ def post(self):
item.put()
# once saved, regenerate certain section properties
section.regenerate()
+ # also, check that this section doesn't have duplicate content
+ Task( params={ 'key': str(section.key()), 'name': item.name }, countdown=30, ).add( queue_name='section-check-duplicate-nodes' )
self.redirect('.')
except Exception, err:
vals['item'] = self.request.POST
View
38 queue.py
@@ -33,6 +33,7 @@ def post(self):
section = db.get( self.request.get('key') )
if section is None:
self.write('No section found')
+ logging.warn( 'No section found for key: ' + key )
return
# keep a count of all these things
@@ -79,6 +80,43 @@ def post(self):
self.write('Finished')
+# try http://localhost:8080/_ah/queue/section-check-duplicate-nodes?key=?&name=?
+class SectionCheckDuplicateNodes(webbase.WebBase):
+ def post(self):
+ self.response.headers['Content-Type'] = 'text/plain'
+ self.write('Started section duplicate node check:')
+
+ key = self.request.get('key')
+ name = self.request.get('name')
+ self.write('- key = ' + key)
+ self.write('- name = ' + name)
+ logging.info( 'Checking for duplicate nodes named [%s] in section [%s]: ' % name, section.path )
+
+ # ok, so get the section first
+ section = db.get( self.request.get('key') )
+ if section is None:
+ self.write('No section found')
+ logging.warn( 'No section found for key: ' + key )
+ return
+
+ nodes = Node.all().filter('section =', key).filter('name =', name).fetch()
+ if nodes.count() <= 1:
+ msg = 'Only [%d] nodes of this name in this section' % nodes.count()
+ self.write(msg)
+ logging.info(msg)
+ return
+
+ msg = 'More than one node named [%s] in section [%s]' % name, section.path
+ self.write(msg)
+ logging.warn(msg)
+ if not mail.is_email_valid(admin_email):
+ return
+
+ # url_edit = 'http://www.' + config.value('Naked Domain') + '/admin/node/'
+ url_edit = 'http://www.%s/admin/node/' % config.value('Naked Domain')
+ body = 'Section %s has two nodes named %s ' % section.path, name
+ mail.send_mail(admin_email, admin_email, 'Duplicate node name in section ' + section.path, body)
+
# try http://localhost:8080/_ah/queue/node-regenerate?key=?
class NodeRegenerate(webbase.WebBase):
def post(self):
View
2  queue.yaml
@@ -1,5 +1,7 @@
queue:
- name: section-regenerate
rate: 6/m
+- name: section-check-duplicate-nodes
+ rate: 6/m
- name: node-regenerate
rate: 1/s
Please sign in to comment.
Something went wrong with that request. Please try again.