Permalink
Browse files

cil-713f4705: Done, pending further testing

  • Loading branch information...
1 parent 172d402 commit 5e4e90b34e7ba2ad163c1a9810c6849b5adc1fa2 @chilts chilts committed Feb 15, 2010
Showing with 295 additions and 51 deletions.
  1. +7 −7 admin.py
  2. +88 −20 config.py
  3. +12 −3 filter.py
  4. +9 −0 issues/c_22c60361.cil
  5. +3 −2 issues/i_713f4705.cil
  6. +10 −10 lollysite.py
  7. +4 −0 models.py
  8. +3 −3 queue.py
  9. +32 −0 theme/admin/config-del.html
  10. +38 −0 theme/admin/config-form.html
  11. +42 −0 theme/admin/config-list.html
  12. +8 −2 theme/admin/wrapper.html
  13. +39 −4 util.py
View
@@ -39,7 +39,7 @@
# local modules
import webbase
-import property
+import config
import section
import page
import image
@@ -73,12 +73,12 @@ def get(self, page):
('/admin/', Home),
('/admin/credits.html', Credit),
- # properties
- ('/admin/property/', property.List),
- ('/admin/property/new.html', property.Edit),
- ('/admin/property/edit.html', property.Edit),
- ('/admin/property/uncache.html', property.UnCache),
- ('/admin/property/del.html', property.Del),
+ # config
+ ('/admin/config/', config.List),
+ ('/admin/config/new.html', config.Edit),
+ ('/admin/config/edit.html', config.Edit),
+ ('/admin/config/uncache.html', config.UnCache),
+ ('/admin/config/del.html', config.Del),
# sections
('/admin/section/', section.List),
View
108 config.py
@@ -29,35 +29,103 @@
import logging
# Google specific modules
+from google.appengine.ext import db
from google.appengine.api import memcache
-from google.appengine.ext.webapp import template
# local modules
-from models import Property
+from models import Config
+import webbase
+import util
## ----------------------------------------------------------------------------
-register = template.create_template_register()
+# List
+class List(webbase.WebBase):
+ def get(self):
+ config = util.get_config()
+ vals = {
+ 'config' : config,
+ }
+ self.template( 'config-list.html', vals, 'admin' );
-# utility functions
-def value(title):
- # see if this is in Memcache
- value = memcache.get(title, 'property')
- if value is not None:
- return value
+# Edit
+class Edit(webbase.WebBase):
+ def get(self):
+ config = util.get_config()
+ title = None
+ value = None
+ if self.request.get('title'):
+ title = self.request.get('title')
+ if title in config.config:
+ value = config.config[title]
- # not in Memcached, so ask the datastore
- data = Property.all().filter("title =", title)
- if not data.count():
- return None
+ vals = {
+ 'item' : {
+ 'title' : title,
+ 'value' : value,
+ }
+ }
+ self.template( 'config-form.html', vals, 'admin' );
- # if this property has no value
- value = data[0].value
- if value is None:
- return None
+ def post(self):
+ title = None
+ value = None
+ config = util.get_config()
+ try:
+ # get all the incoming values
+ title = self.request.get('title').strip()
+ value = self.request.get('value').strip()
- # set the new value in memcache and return it
- memcache.set(title, value, namespace='property')
- return value
+ config.config[title] = value
+
+ config.put()
+ memcache.delete(title, namespace='config')
+ self.redirect('.')
+
+ except Exception, err:
+ vals['item'] = self.request.POST
+ vals['err'] = err
+ self.template( 'config-form.html', vals, 'admin' );
+
+
+# Empty Form (ie. never seen ... does something then goes back to the PropertyList)
+class UnCache(webbase.WebBase):
+ def get(self):
+ title = self.request.get('title')
+ if title:
+ memcache.delete(title, namespace='config')
+ self.redirect('.')
+
+# Delete
+class Del(webbase.WebBase):
+ def get(self):
+ try:
+ title = self.request.get('title').strip()
+ if title:
+ config = util.get_config()
+ vals = {
+ 'item' : {
+ 'title' : title,
+ 'value' : config.config[title],
+ }
+ }
+ self.template( 'config-del.html', vals, 'admin' );
+ else:
+ self.redirect('.')
+ except:
+ self.redirect('.')
+
+ def post(self):
+ try:
+ title = self.request.get('title').strip()
+ if title:
+ config = util.get_config()
+ del config.config[title]
+ config.put()
+ memcache.delete(title, namespace='config')
+ # else, just redirect to this dir
+ self.redirect('.')
+ except:
+ self.redirect('.')
## ----------------------------------------------------------------------------
View
@@ -35,17 +35,17 @@
from django.template import Node
# local
-import config
from models import Node
+import util
register = template.create_template_register()
## ----------------------------------------------------------------------------
# filters
-# config.value should never (usually?) raise an exception
+# util.config_value() should never (usually?) raise an exception
def cfg(title):
- return config.value(title)
+ return util.config_value(title)
register.filter(cfg)
@@ -56,6 +56,15 @@ def list(l):
register.filter(list)
+# takes a dict and returns the value of the item passed
+def hash(h, key):
+ if key in h:
+ return h[key]
+ else:
+ return None
+
+register.filter(hash)
+
# finds the latest 'x' number of nodes in a particular section
def latest(section, limit):
nodes_query = Node.all().filter('section =', section.key()).order('-inserted')
View
@@ -0,0 +1,9 @@
+Issue: 713f4705
+CreatedBy: Andrew Chilton <andychilton@gmail.com>
+Inserted: 2010-02-15T10:49:56
+Updated: 2010-02-15T10:49:56
+
+I kept the ability to say 'title'|cfg but also added the ability to write
+util.config_value('title') which means that can be tested in templates.
+
+(well, at least I hope it can, else I'll cache the whole dictionary too.)
View
@@ -1,11 +1,12 @@
Summary: Using |cfg is bad, it's not a filter anymore, needs changing
-Status: InProgress
+Status: Finished
CreatedBy: Andrew Chilton <andychilton@gmail.com>
AssignedTo: Andrew Chilton <andychilton@gmail.com>
Label: Milestone-v0.05
+Comment: 22c60361
Comment: 6c1a7447
Inserted: 2010-01-01T22:10:08
-Updated: 2010-02-14T05:45:10
+Updated: 2010-02-15T10:55:51
When doing something like this in the templates:
View
@@ -92,7 +92,7 @@ def get(self):
'page' : 'index.html',
'section' : section,
}
- self.template( section.layout + '-index.html', vals, config.value('Theme') );
+ self.template( section.layout + '-index.html', vals, util.config_value('Theme') );
elif this_page == 'rss20' and this_ext == 'xml':
# rss20.xml
@@ -145,7 +145,7 @@ def get(self):
'nodes' : Node.all().filter('section =', section.key()).filter('label =', label).order('-inserted'),
'label' : label
}
- self.template( 'label-index.html', vals, config.value('Theme') );
+ self.template( 'label-index.html', vals, util.config_value('Theme') );
elif archive_page.search(this_page) and this_ext == 'html':
# path =~ 'archive:2009.html'
@@ -157,7 +157,7 @@ def get(self):
'nodes' : Node.all().filter('section =', section.key()).filter('archive =', archive).order('-inserted'),
'archive' : archive
}
- self.template( 'archive-index.html', vals, config.value('Theme') );
+ self.template( 'archive-index.html', vals, util.config_value('Theme') );
elif this_page == 'comment' and this_ext == 'html':
# get the comment if it exists
@@ -177,7 +177,7 @@ def get(self):
'node' : comment.node,
'comment' : comment,
}
- self.template( 'comment.html', vals, config.value('Theme') );
+ self.template( 'comment.html', vals, util.config_value('Theme') );
elif this_ext == 'html':
# get the node itself
@@ -198,7 +198,7 @@ def get(self):
'node' : node,
'comments' : comments,
}
- self.template( 'node.html', vals, config.value('Theme') );
+ self.template( 'node.html', vals, util.config_value('Theme') );
else:
# 404
self.error(404)
@@ -254,11 +254,11 @@ def post(self):
comment.put()
# send a mail to the admin
- admin_email = config.value('Admin Email')
+ admin_email = util.config_value('Admin Email')
if mail.is_email_valid(admin_email):
- url_post = 'http://www.' + config.value('Naked Domain') + node.section.path + node.name + '.html'
- url_mod = 'http://www.' + config.value('Naked Domain') + '/admin/comment/?key=' + str(comment.key()) + ';status='
- url_del = 'http://www.' + config.value('Naked Domain') + '/admin/comment/del.html?key='+ str(comment.key())
+ url_post = 'http://www.' + util.config_value('Naked Domain') + node.section.path + node.name + '.html'
+ url_mod = 'http://www.' + util.config_value('Naked Domain') + '/admin/comment/?key=' + str(comment.key()) + ';status='
+ url_del = 'http://www.' + util.config_value('Naked Domain') + '/admin/comment/del.html?key='+ str(comment.key())
body = 'From: ' + name + ' <' + email + '>\n'
body = body + 'Site: ' + website + '\n\n'
@@ -303,7 +303,7 @@ def post(self):
msg.put()
# send a mail to the admin
- admin_email = config.value('Admin Email')
+ admin_email = util.config_value('Admin Email')
if mail.is_email_valid(admin_email):
body = 'type : ' + type + '\n'
body = body + 'subject : ' + subject + '\n'
View
@@ -68,6 +68,10 @@ class Property(BaseModel):
title = db.StringProperty( required=True )
value = db.StringProperty( required=True )
+# Config class so the application can be configured
+class Config(BaseModel):
+ config = properties.JsonProperty()
+
# Section: to group Nodes together
class Section(BaseModel):
# path := usually something starting with '/', like '/', '/blog/', '/article/' and '/path/to/'
View
@@ -132,12 +132,12 @@ def post(self):
msg = 'More than one node named [%s] in section [%s]' % (name, section.path)
self.write(msg)
logging.warn(msg)
- admin_email = config.value('Admin Email')
+ admin_email = util.config_value('Admin Email')
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')
+ # url_edit = 'http://www.' + util.config_value('Naked Domain') + '/admin/node/'
+ url_edit = 'http://www.%s/admin/node/' % util.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)
@@ -0,0 +1,32 @@
+{% extends "wrapper.html" %}
+
+{% block content %}
+
+<h2>Remove Property?</h2>
+
+<p><a href=".">&laquo;&laquo; Back to Property List</a></p>
+
+{% include 'msg.html' %}
+
+<form method="post" action="">
+ <input type="hidden" name="title" value="{{ item.title|urlencode }}">
+
+ <table class="edit">
+ <tbody>
+
+ <tr>
+ <th>Title:</th>
+ <td>{{ item.title|escape }}</td>
+ </tr>
+
+ <tr>
+ <th>Value:</th>
+ <td>{{ item.value|escape }}</td>
+ </tr>
+
+ </tbody>
+ </table>
+ <input type="submit" value="Delete Config" />
+</form>
+
+{% endblock %}
@@ -0,0 +1,38 @@
+{% extends "wrapper.html" %}
+
+{% block content %}
+
+{% if item %}
+<h2>Edit Config</h2>
+{% else %}
+<h2>New Config</h2>
+{% endif %}
+
+<p><a href=".">&laquo;&laquo; Back to Config List</a></p>
+
+{% include 'msg.html' %}
+
+<form method="post" action="">
+{% if item.title %}
+ <input type="hidden" name="title" value="{{ item.title|urlencode }}">
+{% endif %}
+
+ <table class="edit">
+ <tbody>
+
+ <tr>
+ <th><label for="id_title">Title:</label></th>
+ <td><input type="text" id="id_title" name="title" value="{{ item.title|default:""|escape }}" /></td>
+ </tr>
+
+ <tr>
+ <th><label for="id_value">Value:</label></th>
+ <td><input type="text" id="id_value" name="value" value="{{ item.value|default:""|escape }}" /></td>
+ </tr>
+
+ </tbody>
+ </table>
+ <input type="submit" value="Save Config" />
+</form>
+
+{% endblock %}
Oops, something went wrong.

0 comments on commit 5e4e90b

Please sign in to comment.