Esempio n. 1
0
def add_story(me,title,content,game):
    """ save a story in my name.
    """
    if title is None or title == '':
        logging.warning('title is empty')
        raise Exception('No title')
    if content is None or content == '':
        logging.warning('content is empty')
        raise Exception('No content')
    s = SuiStory()
    s.title = title.replace('<','&lt;')
    #s.text = content.replace('<','&lt;').replace('\n','<br/>').replace('\r','')
    s.game = game
    s.author = me.key().name()
    s.aname = me.name
    s.postime = datetime.utcnow()
    s.put()
    #save content text into SuiContent
    c = SuiContent(parent=s)
    if content.find('\n')>=0:
        content = content.replace('\r\n','<br>').replace('\n','<br>');
    c.text = XML_REPTN.sub(filter_tag, content)
    c.length = len(c.text)
    c.put()
    pages = from_cache('Stories_all')
    if pages is not None:
        page1 = pages[0]
        if len(page1[0]) > 40:
            decaches(['Stories_all','NewStories'])
        else:
            page1[0].insert(0,s)
            to_cache('Stories_all',pages)
            decache('NewStories')
Esempio n. 2
0
def add_story(me, title, content, game):
    """ save a story in my name.
    """
    if title is None or title == '':
        logging.warning('title is empty')
        raise Exception('No title')
    if content is None or content == '':
        logging.warning('content is empty')
        raise Exception('No content')
    s = SuiStory()
    s.title = title.replace('<', '&lt;')
    #s.text = content.replace('<','&lt;').replace('\n','<br/>').replace('\r','')
    s.game = game
    s.author = me.key().name()
    s.aname = me.name
    s.postime = datetime.utcnow()
    s.put()
    #save content text into SuiContent
    c = SuiContent(parent=s)
    if content.find('\n') >= 0:
        content = content.replace('\r\n', '<br>').replace('\n', '<br>')
    c.text = XML_REPTN.sub(filter_tag, content)
    c.length = len(c.text)
    c.put()
    pages = from_cache('Stories_all')
    if pages is not None:
        page1 = pages[0]
        if len(page1[0]) > 40:
            decaches(['Stories_all', 'NewStories'])
        else:
            page1[0].insert(0, s)
            to_cache('Stories_all', pages)
            decache('NewStories')
Esempio n. 3
0
def unregister_user(uid):
    """ Set user's active status to False because Facebook user issued a remove app, etc.
    """
    try:
        u = SuiUser.get_by_key_name(uid)
        if u:
            u.active = False
            u.put()
            decache(uid)
        else:
            logging.warning('User %s not found while de-authorizing'%uid)
    except Exception,e:
        logging.exception(e)
Esempio n. 4
0
def unregister_user(uid):
    """ Set user's active status to False because Facebook user issued a remove app, etc.
    """
    try:
        u = SuiUser.get_by_key_name(uid)
        if u:
            u.active = False
            u.put()
            decache(uid)
        else:
            logging.warning('User %s not found while de-authorizing' % uid)
    except Exception, e:
        logging.exception(e)
Esempio n. 5
0
def add_comment0(me,story,content):
    """ Add a comment to a story. """
    c = SuiComment()
    c.story = db.Key(story)
    logging.debug(story)
    c.text = content
    c.author = '%s[%s]'%(me.name,me.key().name())
    c.postime = datetime.utcnow()
    c.put()
    mckey = str(story)+'_cms'
    if mckey is not None:
        pages = from_cache(mckey)
        if pages is not None:
            page1 = pages[0][0]
            if len(page1) > 60:
                decache(mckey)
            else:
                page1.insert(0,c)
                to_cache(mckey,pages)
Esempio n. 6
0
def add_comment0(me, story, content):
    """ Add a comment to a story. """
    c = SuiComment()
    c.story = db.Key(story)
    logging.debug(story)
    c.text = content
    c.author = '%s[%s]' % (me.name, me.key().name())
    c.postime = datetime.utcnow()
    c.put()
    mckey = str(story) + '_cms'
    if mckey is not None:
        pages = from_cache(mckey)
        if pages is not None:
            page1 = pages[0][0]
            if len(page1) > 60:
                decache(mckey)
            else:
                page1.insert(0, c)
                to_cache(mckey, pages)
Esempio n. 7
0
def unlock_process(lock_key):
    """ Unlock the process/method that's just locked.
    """
    decache(lock_key)
Esempio n. 8
0
def unlock_process(lock_key):
    """ Unlock the process/method that's just locked.
    """
    decache(lock_key)