Exemple #1
0
def add_friend(request, user):
    owner = get_object_or_404(User, username=user)
    if request.user.is_authenticated() == True:
        print request.user.useruserrelation_set.filter(friend=owner.id) 
        if not request.user.useruserrelation_set.filter(friend=owner.id):
            uur = UserUserRelation()
            uur.user = request.user
            uur.friend = owner
            uur.save()
            item = Item()
            item.user = request.user
            item.type = 'friend'
            item.link = '/user/%s/' % (owner.username)
            item.body = owner.username
            item.save()
            return render_to_response("msg.html", {'msg': _('Friend added to your friendlist successfuly.'), 'redirect_to': '/user/'+str(owner.username)+'/'},
                context_instance=RequestContext(request))
        return render_to_response("msg.html", {'msg': _('You have this user in friends.'), 'redirect_to': '/user/'+str(owner.username)+'/'},
            context_instance=RequestContext(request))
    return render_to_response("msg.html", {'msg': _('You are not logged in.'), 'redirect_to': '/user/'+str(owner.username)+'/'},
        context_instance=RequestContext(request))
Exemple #2
0
            fetched_feed = feedparser.parse(feed.link)
        #if feed.etag != fetched_feed['etag']:
            for feed_i in range(len(fetched_feed['entries'])):
                try:
                    Item.objects.get(user=feed.user.id, link = fetched_feed['entries'][feed_i]['link'])
                except:
                    try:
                        content = fetched_feed['entries'][feed_i].content[0].value
                    except:
                        content = fetched_feed['entries'][feed_i].get('summary',
                                     fetched_feed['entries'][feed_i].get('description', ''))
                    #try:
                    #    pubdate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.mktime( time.strptime(fetched_feed['entries'][feed_i]['published'], "%Y-%m-%dT%H:%M:%SZ")))))
                    #except:
                    #    pubdate = fetched_feed['entries'][feed_i]['pubDate']
                    i = Item()
                    i.user_id = feed.user.id
                    i.type = 'feed'
                    i.title = fetched_feed['entries'][feed_i]['title']
                    i.link = fetched_feed['entries'][feed_i]['link']
                    i.date = time.strftime("%Y-%m-%d %H:%M:%S", fetched_feed['entries'][feed_i].updated_parsed)
                    i.body = content
                    i.save()
                    print fetched_feed['entries'][feed_i]['title']
            f = Feed.objects.get(id=feed.id)
            f.etag = fetched_feed['etag']
            f.save()
    #except:
    #    print 'We cant get feed %s' % feed.link
print 'Checking and fetching feeds - done'