Exemple #1
0
def render_news_feed(request_user, user, type, show_items_after_timestamp=None):
	from flowgram.core.newsfeed import get_news_feed_items
	
	items = get_news_feed_items(request_user, user, show_items_after_timestamp)
	
	if not request_user == user:
	    items = items.exclude(eventCode='UNSUB')
	
	if type == 'S':
		# If a short list.
		items = items[:SHORT_SITE_MAX_ITEMS]
	elif type == 'L' or type == 'R':
		# If a long list or RSS.
		items = items[:LONG_SITE_MAX_ITEMS]
	
	output = []
	
	for item in items:
		if item.currentUser == request_user:
			message = item.secondPersonPresent
		elif item.targetUser == request_user:
			message = item.secondPersonPast
		else:
			message = item.thirdPersonPast
		messageFull = "<li><div>%s<div class=\"clearer\"></div></div></li>" % (message)
		output.append(messageFull)
	
	return ''.join(output)
Exemple #2
0
def render_news_feed(request_user, user, type, show_items_after_timestamp=None, rss_key=None):
    from flowgram.core.newsfeed import get_news_feed_items
    from flowgram import localsettings, settings
    from flowgram.core.securerandom import secure_random_id

    items = get_news_feed_items(request_user, user, show_items_after_timestamp)
    
    if rss_key != None:
        items100 = items.filter(eventCode='BADGE_FGVIEWS_100')
        items500 = items.filter(eventCode='BADGE_FGVIEWS_500')
        items1k = items.filter(eventCode='BADGE_FGVIEWS_1k')
        items5k = items.filter(eventCode='BADGE_FGVIEWS_5k')
        items10k = items.filter(eventCode='BADGE_FGVIEWS_10k')
        items = items.exclude(currentUser=user)
        items = items | items100 | items500 | items1k | items5k | items10k
        rss_title = 'Your Flowgram Newsfeed'
    else:
        rss_title = '%s activity on Flowgram' % user.username

    items = items.exclude(eventCode='UNSUB')

    output = []

    output.extend(['<?xml version="1.0"?>',
                   '<rss version="2.0"><channel>',
                   '<title>%s</title>' % rss_title,
                   '<link>%srss/%s/</link>' % (localsettings.my_URL_BASE, user.username),
                   '<description>A Flowgrammer\'s Newsfeed</description>',
                  ])

    feed_id = secure_random_id(settings.ID_ACTUAL_LENGTH)

    for item in items:
        timestamp = time.mktime(item.eventTime.timetuple())
        pubDate = datetime.datetime.utcfromtimestamp(timestamp).strftime("%a, %d %b %Y %H:%M:%S GMT")
        message = ''.join(['<item>',
                           '<title>%s</title>' % \
                               remove_html_tags(item.thirdPersonPast),
                           '<description>%s</description>' % \
                               item.thirdPersonPast.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;'),
                           '<pubDate>%s</pubDate>' % pubDate,
                           '</item>',
                          ])
        output.append(message)

    output.append('</channel></rss>');

    return ''.join(output)
Exemple #3
0
def render_news_feed(request_user, user, type, show_items_after_timestamp=None):
    from flowgram.core.newsfeed import get_news_feed_items
    from flowgram import localsettings, settings
     
    items = get_news_feed_items(request_user, user, show_items_after_timestamp)
    print "there are %d" % len(items)
    items = items.exclude(currentUser=user)
    print "there are now %d" % len(items)
    
    items = items.exclude(eventCode='UNSUB')
    if not request_user == user:
        items = items.exclude(eventCode='BADGE_FGVIEWS_100')
        items = items.exclude(eventCode='BADGE_FGVIEWS_10k')
        items = items.exclude(eventCode='BADGE_FGVIEWS_1k')
        items = items.exclude(eventCode='BADGE_FGVIEWS_500')
        items = items.exclude(eventCode='BADGE_FGVIEWS_5k')
        items = items.exclude(eventCode='BADGE_FGVIEWS_GENERIC')

    if not len(items):
        return ''

    output = []
    
    messageIntro = "<p><strong>Hello!  Here are your Flowgram subscription updates:</strong></p><p>"
    
    output.append(messageIntro)

    for item in items:
        if item.currentUser == request_user:
            message = item.secondPersonPresent
        elif item.targetUser == request_user:
            message = item.secondPersonPast
        else:
            message = item.thirdPersonPast
        messageFull = "%s<br/>" % (message)
        output.append(messageFull)
    
    updateUrl = "%ssubscriptions/" % (localsettings.my_URL_BASE)
    
    messageFooter = "</p><p><a href=\"%s\"><strong>Click here to update your Flowgram notification settings</strong></a>.</p><p>Flowgram subscriptions is a new feature that allows you to track things on Flowgram that are important to you. You can subscribe to any user and get notified when they make a new Flowgram, comment on something and so on. We'll also let you know about activity related to your Flowgrams.</p><p>You can control how notifications are delivered and the frequency by visiting your <a href=\"%s\">Flowgram notifications</a> page.</p>" % (updateUrl, updateUrl)
    
    output.append(messageFooter)

    return ''.join(output)