예제 #1
0
파일: show.py 프로젝트: scipy/SciPyCentral
def show_items(request, what_view='', extra_info=''):
    """ Show different views onto all **revision** items (not submissions)
    """
    what_view = what_view.lower()
    extra_info = extra_info.lower()
    entry_order = []
    page_title = ''
    template_name = 'submission/show-entries.html'
    if what_view == 'tag':
        all_revs = models.Revision.objects.most_recent().\
                                filter(tags__slug=slugify(extra_info))
        page_title = 'All entries tagged'
        entry_order = list(all_revs)
    elif what_view == 'show' and extra_info == 'all-tags':
        page_title = 'All tags'
        template_name = 'submission/show-tag-cloud.html'
    elif what_view == 'show' and extra_info == 'all-revisions':
        # Show all submissions in reverse time order
        all_revs = models.Revision.objects.all().order_by('-date_created')
        page_title = 'All revisions'
        extra_info = ''
        entry_order = list(all_revs)
    elif what_view == 'show' and extra_info == 'all-unique-revisions':
        all_subs = models.Submission.objects.all().order_by('-date_created')
        page_title = 'All submissions'
        extra_info = ' (only showing the latest revision)'
        entry_order = [
            sub.last_revision for sub in all_subs
            if sub.last_revision.is_displayed
        ]
    elif what_view == 'sort' and extra_info == 'most-viewed':
        page_title = 'All submissions in order of most views'
        extra_info = ''
        all_subs = set()
        for rev in models.Revision.objects.all():
            all_subs.add(rev.entry)
        entry_order, _ = sort_items_by_page_views(all_subs, 'submission')
        entry_order = [entry.last_revision for entry in entry_order]
    elif what_view == 'show' and extra_info == 'top-contributors':
        page_title = 'Top contributors'
        extra_info = ''
        entry_order = top_authors('', 0)
    elif what_view == 'validate':
        return validate_submission(request, code=extra_info)

    entries = paginated_queryset(request, entry_order)
    return render_to_response(template_name, {},
                              context_instance=RequestContext(
                                  request, {
                                      'entries': entries,
                                      'page_title': page_title,
                                      'extra_info': extra_info,
                                      'what_view': what_view,
                                  }))
예제 #2
0
파일: views.py 프로젝트: pv/SciPyCentral
def show_items(request, what_view='', extra_info=''):
    """ Show different views onto all **revision** items (not submissions)
    """
    what_view = what_view.lower()
    extra_info = extra_info.lower()
    entry_order = []
    page_title = ''
    template_name = 'submission/show-entries.html'
    if what_view == 'tag':
        all_revs = models.Revision.objects.all().\
                                        filter(tags__slug=slugify(extra_info))
        page_title = 'All entries tagged'
        entry_order = list(all_revs)
    elif what_view == 'show' and extra_info == 'all-tags':
        page_title = 'All tags'
        template_name = 'submission/show-tag-cloud.html'
    elif what_view == 'show' and extra_info == 'all-revisions':
        # Show all submissions in reverse time order
        all_revs = models.Revision.objects.all().order_by('-date_created')
        page_title = 'All revisions'
        extra_info = ''
        entry_order = list(all_revs)
    elif what_view == 'show' and extra_info == 'all-unique-revisions':
        all_subs = models.Submission.objects.all().order_by('-date_created')
        page_title = 'All submissions'
        extra_info = ' (only showing the latest revision)'
        entry_order = [sub.last_revision for sub in all_subs if sub.last_revision.is_displayed]
    elif what_view == 'sort' and extra_info == 'most-viewed':
        page_title = 'All submissions in order of most views'
        extra_info = ''
        all_subs = set()
        for rev in models.Revision.objects.all():
            all_subs.add(rev.entry)
        entry_order, _ = sort_items_by_page_views(all_subs, 'submission')
        entry_order = [entry.last_revision for entry in entry_order]
    elif what_view == 'show' and extra_info == 'top-contributors':
        page_title = 'Top contributors'
        extra_info = ''
        entry_order = top_authors('', 0)
    elif what_view == 'validate':
        return validate_submission(request, code=extra_info)

    entries = paginated_queryset(request, entry_order)
    return render_to_response(template_name, {},
                              context_instance=RequestContext(request,
                                                {'entries': entries,
                                                 'page_title': page_title,
                                                 'extra_info': extra_info,
                                                 'what_view' : what_view,}))
예제 #3
0
파일: views.py 프로젝트: uvyouver/journal
def profile_page(request, slug=None, user_id=None):
    """
    Shows the user's profile.
    """
    try:
        if user_id:
            the_user = models.User.objects.get(id=user_id)
            if the_user.is_active:
                return redirect(profile_page, the_user.profile.slug)
        elif slug is None:
            the_user = request.user
        else:
            the_user = models.User.objects.get(profile__slug=slug)
    except ObjectDoesNotExist:
        return page_404_error(request, 'No profile for that user.')

    # Don't show the profile for inactive (unvalidated) users
    if not (the_user.is_active):
        return page_404_error(request, "That user's profile isn't available.")

    # Items created by this user. Use the ``all()`` function first, to prevent
    # unvalidated submissions from showing
    all_revs = Revision.objects.all().filter(created_by=the_user)\
                                                    .order_by('-date_created')

    if the_user == request.user:
        no_entries = 'You have not submitted any entries to SciPy Central.'
    else:
        no_entries = 'This user has not submitted any entries to SciPy Central.'

    permalink = settings.SPC['short_URL_root'] + 'user/' + str(
        the_user.id) + '/'

    create_hit(request, the_user)
    return render_to_response(
        'person/profile.html', {},
        context_instance=RequestContext(
            request, {
                'theuser': the_user,
                'permalink': permalink,
                'entries': paginated_queryset(request, all_revs),
                'no_entries_message': no_entries,
            }))
예제 #4
0
def profile_page(request, slug=None, user_id=None):
    """
    Shows the user's profile.
    """
    try:
        if user_id:
            the_user = models.User.objects.get(id=user_id)
            if the_user.is_active:
                return redirect(profile_page, the_user.profile.slug)
        elif slug is None:
            the_user = request.user
        else:
            the_user = models.User.objects.get(profile__slug=slug)
    except ObjectDoesNotExist:
        return page_404_error(request, 'No profile for that user.')

    # Don't show the profile for inactive (unvalidated) users
    if not(the_user.is_active):
        return page_404_error(request, "That user's profile isn't available.")


    # Items created by this user. Use the ``all()`` function first, to prevent
    # unvalidated submissions from showing
    all_revs = Revision.objects.all().filter(created_by=the_user)\
                                                    .order_by('-date_created')

    if the_user == request.user:
        no_entries = 'You have not submitted any entries to SciPy Central.'
    else:
        no_entries = 'This user has not submitted any entries to SciPy Central.'

    permalink = settings.SPC['short_URL_root'] + 'user/' + str(the_user.id) + '/'

    create_hit(request, the_user)
    return render_to_response('person/profile.html', {},
                context_instance=RequestContext(request,
                            {'theuser': the_user,
                             'permalink': permalink,
                             'entries':paginated_queryset(request, all_revs),
                             'no_entries_message': no_entries, }))