Exemplo n.º 1
0
def manage_page_widgets(request, page_name):    
    if 'POST' == request.method:
        params = request.POST.copy()
        # KISS stream and page have the same name
        page = get_object_or_404(lifestream.models.Webpage, name=page_name, user=request.user)        
        preferences = patchouli_auth.preferences.getPageProperties(page)
        
        preferences['before_profile_html_area'] = tidy_up(params['before_profile_html_area'], log)        
        preferences['after_profile_html_area'] = tidy_up(params['after_profile_html_area'], log)
        preferences['before_stream_html_area'] = tidy_up(params['before_stream_html_area'], log)
        preferences['after_stream_html_area'] = tidy_up(params['after_stream_html_area'], log)
        
        preferences['page_lang'] = params['page_lang']
        if preferences['page_lang'] not in lang.HTML_LANG.keys():
            preferences['page_lang'] = 'en'
        preferences['page_lang_dir'] = params['page_lang_dir']
        if preferences['page_lang_dir'] not in lang.DIR_CHOICES.keys():
            preferences['page_lang_dir'] = 'LTR'
        
        # Checkboxes
        if 'show_profile_blurb' in params:
            preferences['show_profile_blurb'] = True
        else:
            preferences['show_profile_blurb'] = False
        if 'show_follow_me_links' in params:
            preferences['show_follow_me_links'] = True
        else:
            preferences['show_follow_me_links'] = False
        
        
        patchouli_auth.preferences.savePageOrStreamProperties(page, preferences)
        manageUrl = "/manage/account/%s" % request.user.username.encode('utf-8')
        return django.http.HttpResponseRedirect(manageUrl)
Exemplo n.º 2
0
def prepare_entry(entryJSON, log):
    content = ''
    if 'content' in entryJSON:
        content = entryJSON['content'][0].value
    elif 'description' in entryJSON:
        content = entryJSON['description']
    else:
        #log.debug('unreadable... ' + str(entryJSON))
        pass
    image = None
    if 'links' in entryJSON:
        for link in entryJSON['links']:
            if link['rel'] == 'image':
                image = link['href']
    
    title = tidy_up(entryJSON['title'], log)
    content = tidy_up(content, log)
    
    tags = []
    if 'tags' in entryJSON:
        for tag in entryJSON['tags']:
            if 'term' in tag:
                tags.append({'tag': tag['term'], 'name': tag['term']})
    return {'entry': content, 'tags': tags, 'title': title, 'image': image, 'permalink': entryJSON['link'], 'raw': entryJSON}
    #return {'entry': str(entryJSON)}
Exemplo n.º 3
0
def prepare_entry(entryJSON, log):
    """ Given entryJSON, output a dictionary of variables for use in
    templates/identica/entry.html
    {u'updated': u'2010-05-15T06:09:36+00:00',
    u'subtitle': u"Bookclub just got weird. Looks like I'm reading World War Z next, but the "discussion" will be in a karaoke booth.",
    u'published_parsed': [2010, 5, 15, 6, 9, 36, 5, 135, 0],
    u'links': [{u'href': u'http://identi.ca/notice/32272261', u'type': u'text/html', u'rel': u'alternate'},
    {u'href': u'http://identi.ca/conversation/32149749', u'type': u'text/html', u'rel': u'ostatus:conversation'}],
    u'title': u'Bookclub just got weird. Looks like I\'m reading World War Z next, but the "discussion" will be in a karaoke booth.',
    u'content': [{u'base': u'http://identi.ca/api/statuses/user_timeline/69091.atom', u'type': u'text/html', u'language': u'en-US',
    u'value': u"Bookclub just got weird. Looks like I'm reading World War Z next, but the "discussion" will be in a karaoke booth."}],
    u'title_detail': {u'base': u'http://identi.ca/api/statuses/user_timeline/69091.atom', u'type': u'text/plain', u'language': u'en-US',
    u'value': u'Bookclub just got weird. Looks like I\'m reading World War Z next, but the "discussion" will be in a karaoke booth.'},
    u'link': u'http://identi.ca/notice/32272261', u'published': u'2010-05-15T06:09:36+00:00', u'id':
    u'http://identi.ca/notice/32272261', u'updated_parsed': [2010, 5, 15, 6, 9, 36, 5, 135, 0]}
    
    A conversation:
    {u'updated': u'2010-05-15T15:37:40+00:00',
    u'subtitle': u'@<span class="vcard"><a href="http://identi.ca/user/59637" class="url" title="Stefan Pampel"><span class="fn nickname">pisco</span></a></span> True Dat!',
    u'published_parsed': [2010, 5, 15, 15, 37, 40, 5, 135, 0],
    u'links': [{u'href': u'http://identi.ca/notice/32316840', u'type': u'text/html', u'rel': u'alternate'},
               {u'href': u'http://identi.ca/notice/32304325', u'type': u'text/html', u'rel': u'related'},
               {u'href': u'http://identi.ca/conversation/32175701', u'type': u'text/html', u'rel': u'ostatus:conversation'},
               {u'href': u'http://identi.ca/user/59637', u'type': u'text/html', u'rel': u'ostatus:attention'}],
    u'title': u'@pisco True Dat!', u'published': u'2010-05-15T15:37:40+00:00',
    u'content': [{u'base': u'http://identi.ca/api/statuses/user_timeline/69091.atom', u'type': u'text/html', u'language': u'en-US',
                u'value': u'@<span class="vcard"><a href="http://identi.ca/user/59637" class="url" title="Stefan Pampel"><span class="fn nickname">pisco</span></a></span> True Dat!'}], u'title_detail': {u'base': u'http://identi.ca/api/statuses/user_timeline/69091.atom', u'type': u'text/plain', u'language': u'en-US', u'value': u'@pisco True Dat!'},
                u'link': u'http://identi.ca/notice/32316840', u'in-reply-to': u'', u'id': u'http://identi.ca/notice/32316840',
                u'updated_parsed': [2010, 5, 15, 15, 37, 40, 5, 135, 0]}

   """
    status = ''
    if 'subtitle' in entryJSON:
        status = entryJSON['subtitle']
    elif 'title' in entryJSON:
        status = entryJSON['title']
    else:
        #log.debug("subtitle expected, missing %s" % str(entryJSON   ))
        pass
    if re.match(r'^\w+:.*$', status):
        parts = status.split(':')
        if parts:
            tweeter = parts[0]
            status = ':'.join(parts[1:])            
    
    rawtags = re.findall('#(\w+)', status)
    tags = [{'tag': r, 'name': r} for r in rawtags]
    
    status = re.sub('!(\w+)', r'<a href="http://identi.ca/group/\1">!\1</a>', status)
    status = re.sub('#(\w+)', r'<a href="http://identi.ca/tag/\1">#\1</a>', status)
    status = re.sub('@(\w+)', r'<a href="http://identi.ca/\1">@\1</a>', status)
    
    try:
        status = tidy_up(status.replace('\n', '<br />'), log)
    except Exception, x:
        log.error("Ouch, unable to linkify _%s_" % status)
        log.exception(x)
Exemplo n.º 4
0
def prepare_entry(entryJSON, log):
    content = ''
    if 'content' in entryJSON:
        content = entryJSON['content'][0].value
    elif 'description' in entryJSON:
        content = entryJSON['description']
    elif 'title' in entryJSON:
        content = entryJSON['title']
    else:
        content = 'unreadable... ' + str(entryJSON)    
    try:
        content = tidy_up(content, log)    
    except Exception, x:
        log.error("Ouch, unable to linkify _%s_" % content)
        log.exception(x)
Exemplo n.º 5
0
def prepare_entry(entryJSON, log):
    content = ''
    if 'content' in entryJSON:
        content = entryJSON['content'][0].value
    elif 'description' in entryJSON:
        content = entryJSON['description']
    elif 'title' in entryJSON:
        content = entryJSON['title']
    else:
        content = 'unreadable... ' + str(entryJSON)
    try:
        content = tidy_up(content, log)
    except Exception, x:
        log.error("Ouch, unable to linkify _%s_" % content)
        log.exception(x)
Exemplo n.º 6
0
def prepare_entry(entryJSON, log):
    """ Given entryJSON, output a dictionary of variables for use in
    templates/twitter_com/entry.html
    
    Here is the layout of a typical Twitter Entry looks like:
   {
   'summary_detail':{
      'base':'http://twitter.com/statuses/user_timeline/1127361.rss',
      'type':'text/html',
      'language':None,
      'value':"ozten: @mriggen I can only imagine... I'm getting sentimental about it and the future!"
   },
   'updated_parsed':[ 2010, 3, 18, 3, 35, 24, 3, 77, 0],
   'links':[
      { 'href':'http://twitter.com/ozten/statuses/10653573637',
         'type':'text/html',
         'rel':'alternate'}],
   'title':"ozten: @mriggen I can only imagine... I'm getting sentimental about it and the future!",
   'updated':'Thu, 18 Mar 2010 03:35:24 +0000',
   'summary':"ozten: @mriggen I can only imagine... I'm getting sentimental about it and the future!",
   'guidislink':True,
   'title_detail':{
      'base':'http://twitter.com/statuses/user_timeline/1127361.rss',
      'type':'text/plain',
      'language':None,
      'value':"ozten: @mriggen I can only imagine... I'm getting sentimental about it and the future!"
   },
   'link':'http://twitter.com/ozten/statuses/10653573637',
   'id':'http://twitter.com/ozten/statuses/10653573637'
   }
   #TODO if someone else is tweeting to me, don't remove the username
   
   Search is different
    {u'lang': u'fr', u'updated': u'2010-05-15T10:44:59Z',
    u'subtitle': u'<a href="http://search.twitter.com/search?q=%23Mozilla">#Mozilla</a> lance <a href="http://search.twitter.com/search?q=%23PluginCheck">#<b>PluginCheck</b></a>, un v\xe9rificateur de <a href="http://search.twitter.com/search?q=%23plugins">#plugins</a> multi-navigateurs | Jean-Marie Gall.com <a href="http://bit.ly/9Zmv8c">http://bit.ly/9Zmv8c</a>',
    u'published_parsed': [2010, 5, 15, 10, 44, 59, 5, 135, 0],
    u'links': [{u'href': u'http://twitter.com/jmgall/statuses/14030858884', u'type': u'text/html', u'rel': u'alternate'},
               {u'href': u'http://a3.twimg.com/profile_images/284467989/jmbg54000_normal.jpg', u'type': u'image/png', u'rel': u'image'}],
    u'title': u'#Mozilla lance #PluginCheck, un v\xe9rificateur de #plugins multi-navigateurs | Jean-Marie Gall.com http://bit.ly/9Zmv8c',
    u'author': u'jmgall (Jean-Marie Gall)',
    u'id': u'tag:search.twitter.com,2005:14030858884',
    u'content': [{u'base': u'http://search.twitter.com/search.atom?q=plugincheck', u'type': u'text/html', u'language': u'en-US',
                 u'value': u'<a href="http://search.twitter.com/search?q=%23Mozilla">#Mozilla</a> lance <a href="http://search.twitter.com/search?q=%23PluginCheck">#<b>PluginCheck</b></a>, un v\xe9rificateur de <a href="http://search.twitter.com/search?q=%23plugins">#plugins</a> multi-navigateurs | Jean-Marie Gall.com <a href="http://bit.ly/9Zmv8c">http://bit.ly/9Zmv8c</a>'}],
    u'source': {},
    u'title_detail': {u'base': u'http://search.twitter.com/search.atom?q=plugincheck', u'type': u'text/plain', u'language': u'en-US', u'value': u'#Mozilla lance #PluginCheck, un v\xe9rificateur de #plugins multi-navigateurs | Jean-Marie Gall.com http://bit.ly/9Zmv8c'},
    u'href': u'http://twitter.com/jmgall',
    u'link': u'http://twitter.com/jmgall/statuses/14030858884',
    u'published': u'2010-05-15T10:44:59Z',
    u'author_detail': {u'href': u'http://twitter.com/jmgall',
                u'name': u'jmgall (Jean-Marie Gall)'},
    u'geo': u'', u'result_type': u'recent',
    u'updated_parsed': [2010, 5, 15, 10, 44, 59, 5, 135, 0], u'metadata': u''}

   """
    title = entryJSON['title']
    tweet = title
    tweeter = ''
    if re.match(r'^\w+:.*$', title):
        parts = title.split(':')
        if parts:
            tweeter = parts[0]
            tweet = ':'.join(parts[1:])            
    elif 'author' in entryJSON:
        tweeter = entryJSON.author
    

    rawtags = re.findall('#(\w+)', tweet)
    tags = [{'tag': r, 'name': r} for r in rawtags]
    
    tweet = re.sub('#(\w+)', r'<a href="http://twitter.com/search?q=%23\1">#\1</a>', tweet)
    tweet = re.sub('@(\w+)', r'<a href="http://twitter.com/\1">@\1</a>', tweet)
    try:        
        tweet = tidy_up(tweet.replace('\n', '<br />'), log)
    except Exception, x:
        log.error("Ouch, unable to linkify _%s_ caught" % tweet)
        log.exception(x)