Beispiel #1
0
def main_page(request):
    import recommendations as rec
    # recommended posts
    # get user data
    user = request.user
    handler = ratings.get_handler(BlogPost)
    # others = User.objects.filter().exclude(username=user)
    # for test all users
    users = User.objects.all()
    critics = {}
    for other in users:
        scores = {}
        for vote in ratings.get_votes_by(other):
            scores[vote.content_object.title] = vote.score
            # print "%s -> %s" % (vote.content_object.title, vote.score)
        if scores != {}:
            critics[other] = scores
    print rec.getRecommendations(critics, user)
        
    # latest avtivities from following people
    following_people = [followingship.followers for followingship in user.following_set.all()]
    following_people_blogposts = BlogPost.objects.filter(
        user__in=following_people,
        status=BlogPost.LIVE_STATUS,
        ).order_by('-id')


    MAX_WEIGHT = 5
    tags = Tag.objects.order_by('name')
    # calculate tag, min and max counts.
    min_count = max_count = tags[0].blogposts.count()
    for tag in tags:
        tag.count = tag.blogposts.count()
        if tag.count < min_count:
            min_count = tag.count
        if max_count < tag.count:
            max_count = tag.count
    #calculate count range. Avoid dividing by zero.
    range = float(max_count - min_count)
    if range == 0.0:
        range = 1.0
    #calculate tag weights.
    for tag in tags:
        tag.weight = int(
            MAX_WEIGHT * (tag.count - min_count) / range
            )
    variables = RequestContext(request, {
        # 'username': user,
        'following_people': following_people,
        'blogposts': following_people_blogposts,
        'show_tags': True,
        'show_user': True,
        'show_body': True,
        'tags': tags,
        })
    # return render_to_response('tag_cloud_page.html', variables)
    return render_to_response('main_page.html', variables)
 def get(self, request, **kwargs):
     self.object = self.get_object()
     self.handler = ratings.get_handler(self.object)
     self.votes = self.get_votes(self.object, request)
     kwargs = {"object": self.object, self.get_context_votes_name(self.object): self.votes}
     context = self.get_context_data(**kwargs)
     response = self.render_to_response(context)
     # FIXME: try to avoid this workaround
     if hasattr(response, "render") and callable(response.render):
         response.render()
     return response
Beispiel #3
0
 def get(self, request, **kwargs):
     self.object = self.get_object()
     self.handler = ratings.get_handler(self.object)
     self.votes = self.get_votes(self.object, request)
     kwargs = {
         'object': self.object,
         self.get_context_votes_name(self.object): self.votes,
     }
     context = self.get_context_data(**kwargs)
     response = self.render_to_response(context)
     # FIXME: try to avoid this workaround
     if hasattr(response, 'render') and callable(response.render):
         response.render()
     return response