Esempio n. 1
0
def contributed_content(request, user_id, content_type):
    """
    Need to remove this for a core method.
    """
    page = request_helpers.get_page(request)

    content_type_object = ContentType.objects.get(id=content_type)
    content_model = content_type_object.model_class()

    user_object = shortcuts.get_object_or_404(User, id=user_id)
    content_objects = content_model.objects.filter(user=user_object)
    current_page, page_range = paginate_queryset_ajax(
        content_objects, 10, 5, page,
        "%ss_page_" % (content_type_object.model),
        reverse('community-contributed-content',
                args=[user_object.id, content_type_object.id]))

    return shortcuts.render_to_response(
        'django_community/elements/generic_contributed_content.html',
        {
            'current_page': current_page,
            'content_type': content_type_object.id,
            'page_range': page_range
        },
        context_instance=RequestContext(request),
    )
Esempio n. 2
0
def build_profile_information(user):
    """
    Returns a dictionary containing information relevant to an user's 
    profile.
    
    Override this function to add additional information to an user's 
    profile.
    """
    context = {}
    context['user'] = user
    
    up_votes = Vote.objects.filter(user = user,  mode = 'up').count()
    down_votes = Vote.objects.filter(user = user,  mode = 'down').count()
    context['up_votes'] = up_votes
    context['down_votes'] = down_votes
    
    contributed_questions = Question.objects.filter(user = user)
    contributed_apps = App.objects.filter(user = user)
    contributed_codes = Code.objects.filter(user = user)
    contributed_tutorials = Tutorial.objects.filter(user = user)
    contributed_answers = Answer.objects.filter(user = user)
    
    apps_page,  apps_page_range = \
        paginate_queryset_ajax(contributed_apps,  10,  5,  1,  'apps_page_',  
                               reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(App).id]))
    codes_page,  codes_page_range = \
        paginate_queryset_ajax(contributed_codes,  10,  5,  1,  'codes_page_', 
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Code).id]))
    tutorials_page,  tutorials_page_range = \
        paginate_queryset_ajax(contributed_tutorials,  10,  5,  1,  'tutorials_page_', 
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Tutorial).id]))
    questions_page,  questions_page_range = \
        paginate_queryset_ajax(contributed_questions,  10,  5,  1,  'questions_page_',
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Question).id]))
    answers_page,  answers_page_range = \
        paginate_queryset_ajax(contributed_answers,  10,  5,  1,  'answers_page_', 
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Answer).id]))
    
    favorite_content = Favorite.objects.filter(user = user).order_by('-date_created')
    favorites_page,  favorites_page_range = paginate_queryset_ajax(favorite_content,  10,  5,  1,  'favorites_page_',  
                               reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Favorite).id]))
    
    user_history = UserHistory.objects.filter(user = user).order_by('-date_created')[0:30]
    badges = Badge.objects.distinct_badges_for_user_with_count(user)
    
    context['apps_page'],  context['apps_page_range']  = apps_page,  apps_page_range
    context['codes_page'], context['codes_page_range'] = codes_page,  codes_page_range
    context['tutorials_page'],  context['tutorials_page_range'] = tutorials_page,  tutorials_page_range
    context['questions_page'],  context['questions_page_range'] = questions_page,  questions_page_range
    context['answers_page'],  context['answers_page_range'] = answers_page,  answers_page_range
    context['favorites_page'],  context['favorites_page_range'] = favorites_page,  favorites_page_range
    context['user_history'] = user_history
    context['badges'] = badges
    
    return context
Esempio n. 3
0
def contributed_content(request, user_id, content_type):
    """
    Need to remove this for a core method.
    """
    page = request_helpers.get_page(request)
    
    content_type_object = ContentType.objects.get(id = content_type)
    content_model = content_type_object.model_class()
    
    user_object = shortcuts.get_object_or_404(User,  id = user_id)
    content_objects = content_model.objects.filter(user = user_object)
    current_page,  page_range = paginate_queryset_ajax(content_objects,  10,  5,  page,  "%ss_page_" % (content_type_object.model), 
                            reverse('community-contributed-content',  args=[user_object.id,  content_type_object.id]))
    
    return shortcuts.render_to_response(
                'django_community/elements/generic_contributed_content.html', 
                {'current_page':current_page, 'content_type':content_type_object.id,  'page_range':page_range}, 
                context_instance = RequestContext(request),
    )
Esempio n. 4
0
def build_profile_information(user):
    """
    Returns a dictionary containing information relevant to an user's 
    profile.
    
    Override this function to add additional information to an user's 
    profile.
    """
    context = {}
    context['user'] = user

    up_votes = Vote.objects.filter(user=user, mode='up').count()
    down_votes = Vote.objects.filter(user=user, mode='down').count()
    context['up_votes'] = up_votes
    context['down_votes'] = down_votes

    contributed_questions = Question.objects.filter(user=user)
    contributed_apps = App.objects.filter(user=user)
    contributed_codes = Code.objects.filter(user=user)
    contributed_tutorials = Tutorial.objects.filter(user=user)
    contributed_answers = Answer.objects.filter(user=user)

    apps_page,  apps_page_range = \
        paginate_queryset_ajax(contributed_apps,  10,  5,  1,  'apps_page_',
                               reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(App).id]))
    codes_page,  codes_page_range = \
        paginate_queryset_ajax(contributed_codes,  10,  5,  1,  'codes_page_',
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Code).id]))
    tutorials_page,  tutorials_page_range = \
        paginate_queryset_ajax(contributed_tutorials,  10,  5,  1,  'tutorials_page_',
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Tutorial).id]))
    questions_page,  questions_page_range = \
        paginate_queryset_ajax(contributed_questions,  10,  5,  1,  'questions_page_',
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Question).id]))
    answers_page,  answers_page_range = \
        paginate_queryset_ajax(contributed_answers,  10,  5,  1,  'answers_page_',
                                reverse('community-contributed-content',  args=[user.id,  ContentType.objects.get_for_model(Answer).id]))

    favorite_content = Favorite.objects.filter(
        user=user).order_by('-date_created')
    favorites_page, favorites_page_range = paginate_queryset_ajax(
        favorite_content, 10, 5, 1, 'favorites_page_',
        reverse('community-contributed-content',
                args=[user.id,
                      ContentType.objects.get_for_model(Favorite).id]))

    user_history = UserHistory.objects.filter(
        user=user).order_by('-date_created')[0:30]
    badges = Badge.objects.distinct_badges_for_user_with_count(user)

    context['apps_page'], context[
        'apps_page_range'] = apps_page, apps_page_range
    context['codes_page'], context[
        'codes_page_range'] = codes_page, codes_page_range
    context['tutorials_page'], context[
        'tutorials_page_range'] = tutorials_page, tutorials_page_range
    context['questions_page'], context[
        'questions_page_range'] = questions_page, questions_page_range
    context['answers_page'], context[
        'answers_page_range'] = answers_page, answers_page_range
    context['favorites_page'], context[
        'favorites_page_range'] = favorites_page, favorites_page_range
    context['user_history'] = user_history
    context['badges'] = badges

    return context