def get(self):

        #   Default template values that we'll pass over
        template_values = {"status": "ok", "msg": {"kittens": 23, "puppies": 1}}

        #   We first need to see if we have the guardian
        #   api key in memcache...
        settingsJSON = memcache.get("settingsJSON")

        #   ...if we don't the apiKey in memcache then we
        #   will try and fetch it from the database...
        if settingsJSON is None:

            rows = Settings.all()

            #   If there isn't a database entry then we
            #   know that the thing hasn't been setup
            #   so we should send the user to the setup
            #   page
            if rows.count() == 0:
                path = os.path.join(os.path.dirname(__file__), "templates/apiKey.html")
                self.response.out.write(template.render(path, template_values))
            else:
                row = rows[0]
                settingsJSON = json.loads(row.settingsJSON)
                memcache.set("settingsJSON", settingsJSON, 86400)  # 60s * 60m *24h

        #   Now that we have the settings file (and
        #   if we have a settings file we automatically
        #   have the api key, we need to look and see
        #   if we need to backfill the old Picture Desk
        #   Live blogs
        if settingsJSON is not None:
            self.response.write("Check backfill")
    def get(self):

        # build an empty template_values object that we can stuff full
        # of handy information and so on
        template_values = {
          'msg': 'Hello World',
        }

        #   grab the settings file
        #   TODO: put this into memcache
        settingsRows = Settings.all()

        #   If we don't have the settings file, then we need to
        #   take the user to the settings page
        if settingsRows.count() == 0:
            path = os.path.join(os.path.dirname(__file__), 'templates/setup.html')
            self.response.out.write(template.render(path, template_values))
        else:

            #   Grab the JSON out of the settings row
            settingsJSON = simplejson.loads(settingsRows[0].json)

            #   If we don't have enough stories then we need to go to the
            #   setup page and let it carry on backfilling
            if len(settingsJSON['storiesList']) < 60:
                template_values['backfilling'] = True
                template_values['backfill'] = len(settingsJSON['storiesList'])
                path = os.path.join(os.path.dirname(__file__), 'templates/setup.html')
                self.response.out.write(template.render(path, template_values))
            else:
                template_values['settingsJSON'] = settingsJSON
                path = os.path.join(os.path.dirname(__file__), 'templates/index.html')
                self.response.out.write(template.render(path, template_values))
Beispiel #3
0
 def update_setting(id, name, value, description):
     setting_item = Settings.get_by_id(int(id))
     if setting_item:
         if setting_item.name != name:
             BlogInfo.__shared_values.pop(setting_item.name)
             setting_item.name = name
         setting_item.value = value
         setting_item.description = description
         setting_item.put()
         BlogInfo.__shared_values[name] = value
Beispiel #4
0
    def init_settings(self):
        init_values = { 
            'author' : ('CoderZh', u'博客作者名称'),
            'email' : ('*****@*****.**', u'博客作者名称'),
            'homepage' : ('http://blog.coderzh.com', u'作者主页'),
            'blogtitle' : ('Nancy Blog', u'博客标题'),
            'subtitle' : ('This is NancyBlog', u'子标题'),
            'theme' : ('default', u'博客皮肤'),
            'announce' : (u'欢迎使用NancyBlog', u'公告'),
            'admin_pages' : ('20', u'管理页面每页显示条数'),
            'blog_pages' : ('20', u'首页博客每页显示条数'),
            'comment_pages' : ('50', u'评论每页显示条数'),
            'tag_pages' : ('50', u'Tag每页显示条数'),
            'rss_coderzh' : ('http://feeds.feedburner.com/coderzh', u'rss地址'),
            'rss_coderzh_description' : (u'我的技术博客', u'rss描述'),
        }

        for name, value in init_values.items():
            setting = Settings(name=name, value=value[0], description=value[1])
            setting.put()
            BlogInfo.__shared_values[name] = value[0]
Beispiel #5
0
    def __init__(self):
        if not BlogInfo.__shared_values:
            settings = Settings.all()
            hasData = False
            for setting in settings:
                hasData = True
                BlogInfo.__shared_values[setting.name] = setting.value

            if not hasData:
                self.init_settings()

        self.__dict__ = BlogInfo.__shared_values
Beispiel #6
0
    def create_setting(name, value, description):
		new_setting = Settings(name=name, value=value, description=description)
		new_setting.put()
		BlogInfo.__shared_values[name] = value
Beispiel #7
0
 def delete_setting(id):
     setting_item = Settings.get_by_id(int(id))
     if setting_item:
         key = 'setting_%s' % setting_item.name
         setting_item.delete()
         BlogInfo.__shared_values.pop(setting_item.name)
#!/usr/bin/env python
import os
import simplejson
from admin.models import Settings
from google.appengine.api import memcache
from admin.functions import get_query_string

args = get_query_string(os.environ['QUERY_STRING'])

memkey = 'settings'

itemsRows = memcache.get(memkey)
if itemsRows is None:
    itemsRows = Settings.all()
    memcache.add(memkey, itemsRows, 60 * 1)

if itemsRows.count() == 0:
    newResults = {'stat': 'error'}
else:
    results = simplejson.loads(itemsRows[0].json)
    del results['rejects']
    del results['rejectsList']

    #   TODO: validate limit in args as positive numerical
    if 'limit' in args:
        newStories = {}
        newStoriesList = []
        for i in range(int(args['limit'])):
            newStories[results['storiesList'][i]] = results['stories'][results['storiesList'][i]]
            newStoriesList.append(results['storiesList'][i])
#!/usr/bin/env python
import simplejson

from admin.models import Settings
from admin.functions import fetchStories

#   Get the settings file, if there isn't one then throw an error
settingsRows = Settings.all()

if settingsRows.count() == 0:
    statusJSON = {'status': 'error', 'msg': 'no settingsJSON record'}
else:
    #   Now we need to grab the API key and go fetch a whole bunch
    #   of stories from the Guardian
    apiKey = settingsRows[0].apiKey
    settingsJSON = simplejson.loads(settingsRows[0].json)

    #   go and top up the settingsJSON with a bunch of stories
    fetchStories(1, apiKey, 'prepend', settingsJSON)

    #   Now we need to put the data back into the database
    storeRow = settingsRows[0]
    storeRow.json = simplejson.dumps(settingsJSON)
    storeRow.put()

    statusJSON = {'status': 'ok', 'msg': len(settingsJSON['storiesList'])}

print 'Content-Type: application/json; charset=UTF-8'
print ''
print simplejson.dumps(statusJSON)
import os
import simplejson

from admin.models import Settings
from admin.functions import get_query_string

args = get_query_string(os.environ['QUERY_STRING'])

if 'apiKey' not in args:
    statusJSON = {'status': 'error', 'msg': 'you need to pass an apiKey. ?apiKey=xxxxxx'}
else:
    #   We need to check that we don't already have the data in the database as
    #   we don't want people to overwrite what we already have, yup, that's right
    #   once we've made a selection there's no going back unless we either blow
    #   away the database, or go in by hand and update it
    settingsRows = Settings.all()

    if settingsRows.count() == 0:
        newJSON = {
            'stories': {},
            'storiesList': [],
            'rejects': {},
            'rejectsList': []
        }

        #   Now put it into the database
        settingsRow = Settings()
        settingsRow.apiKey = args['apiKey']
        settingsRow.json = simplejson.dumps(newJSON)
        settingsRow.put()