예제 #1
0
def view_files_of_group(request,
                        group_id=None,
                        suggested_label_title=None,
                        page=None):
    from curia.labels.models import SuggestedLabel
    if group_id != None:
        group = get_object_or_404_and_check_access(request,
                                                   Group,
                                                   pk=group_id,
                                                   command='view')
    else:
        group = get_current_community()

    page_size = get_integer(request, 'page_size', default=10)
    search = get_string(request, 'search', default='')

    suggested_labels = get_objects_from(SuggestedLabel,
                                        deleted=False,
                                        group=group_id,
                                        content_type=get_content_type(File))

    class SearchForm(django.forms.Form):
        search = django.forms.CharField(max_length=2048,
                                        label=_('Search'),
                                        required=False)

    if request.POST:
        form = SearchForm(request.POST)

        if form.is_valid():
            if 'upload_file' in request.REQUEST and request.REQUEST[
                    'upload_file'] == _('Upload file'):
                return HttpResponseRedirect(
                    '/files/add/?group_id=%s&fastsearch=%s' %
                    (group.id, get_string(request, 'fastsearch', default='')))
            return HttpResponseRedirect(
                '/files/groups/%s/?search=%s&fastsearch=%s' %
                (group_id, search, get_string(
                    request, 'fastsearch', default='')))

    else:
        form = SearchForm(initial={'search': search})

    full_search = search + ',' + get_string(request, 'fastsearch', default='')
    files = search_objects_from(full_search, File, owner_group=group)

    paginator = Paginator(files.order_by('-creation_time'), page_size)

    number_of_pages = paginator.num_pages
    got_page_size = False

    if number_of_pages != 0:
        if not page:
            page = 1
        page = int(page)
        # TODO: implement getting page ranges
        #end_page = int(request.GET['end_page'])
        end_page = page
        files = paginator.page(page)
    else:
        end_page = 0
        page = 0
        files = []

    next_page = page + 1
    has_next_page = paginator.page(page).has_next()

    on_all = True
    for suggested_label in suggested_labels:
        if suggested_label.title == get_string(request,
                                               'fastsearch',
                                               default=''):
            on_all = False

    return render_to_response(
        request, 'files/view_files.html', {
            'owner': group,
            'user': request.user,
            'files': files,
            'type': 'groups',
            'base_url': '/files/groups/' + str(group.id) + '/',
            'is_paginated': True,
            'form': form,
            'suggested_labels': suggested_labels,
            'group': group,
            'number_of_pages': number_of_pages,
            'page': page,
            'end_page': end_page,
            'has_next_page': has_next_page,
            'has_previous_page': paginator.page(page).has_previous(),
            'next_page': next_page,
            'previous_page': page - 1,
            'page_size': page_size,
            'fastsearch': get_string(request, 'fastsearch', default=''),
            'search': search,
            'on_all': on_all,
            'paginator': paginator
        })
예제 #2
0
파일: views.py 프로젝트: boxed/curia
def view_forum(request, group_id=None, suggested_label_title=None, page=None):
    if group_id:
        group = get_object_or_404_and_check_access(request, Group, pk=group_id, command="view")
    else:
        group = request.community
    check_access(request.user, group, "view")
    page_size = get_integer(request, "page_size", default=12)
    search = get_string(request, "search", default="")

    suggested_labels = get_objects_from(
        SuggestedLabel, deleted=False, group=group_id, content_type=get_content_type(Thread)
    )

    import django.forms

    class SearchForm(django.forms.Form):
        search = django.forms.CharField(max_length=2048, label=_("Search"), required=False)

    if request.POST:
        form = SearchForm(request.POST)

        if form.is_valid():
            if "create_thread" in request.REQUEST and request.REQUEST["create_thread"] == _("Create thread"):
                return HttpResponseRedirect(
                    "/forums/add/?group_id=%s&labels=%s" % (group.id, get_string(request, "fastsearch", default=""))
                )
            return HttpResponseRedirect(
                "/forums/%s/?search=%s&fastsearch=%s"
                % (group_id, search, get_string(request, "fastsearch", default=""))
            )
    else:
        form = SearchForm(initial={"search": search})

    full_search = search + "," + get_string(request, "fastsearch", default="")
    if full_search == ",":
        full_search = ""
    threads = search_objects_from(full_search, Thread, owner_group=group)

    paginator = Paginator(threads.order_by("-last_changed_time"), page_size)

    number_of_pages = paginator.num_pages
    got_page_size = False

    if number_of_pages != 0:
        if not page:
            page = 1
        page = int(page)
        # TODO: implement getting page ranges
        # end_page = int(request.GET['end_page'])
        end_page = page
        threads = paginator.page(page)
    else:
        end_page = 0
        page = 0
        threads = []

    next_page = page + 1
    has_next_page = paginator.page(page).has_next()

    on_all = True
    for suggested_label in suggested_labels:
        if suggested_label.title == get_string(request, "fastsearch", default=""):
            on_all = False

    return render_to_response(
        request,
        "forums/view_forum.html",
        {
            "base_url": "/forums/" + str(group.id) + "/",
            "is_paginated": True,
            "form": form,
            "threads": threads,
            "suggested_labels": suggested_labels,
            "group": group,
            "number_of_pages": number_of_pages,
            "page": page,
            "end_page": end_page,
            "has_next_page": has_next_page,
            "has_previous_page": paginator.page(page).has_previous(),
            "next_page": next_page,
            "previous_page": page - 1,
            "page_size": page_size,
            "search": search,
            "fastsearch": get_string(request, "fastsearch", default=""),
            "on_all": on_all,
            "paginator": paginator,
            "add_form": get_add_form()(initial={}),
        },
    )
예제 #3
0
파일: views.py 프로젝트: boxed/curia
def view_files_of_group(request, group_id=None, suggested_label_title=None, page=None):
    from curia.labels.models import SuggestedLabel
    if group_id != None:
        group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='view')
    else:
        group = get_current_community()
        
    page_size = get_integer(request, 'page_size', default=10)
    search = get_string(request, 'search', default='')
  
    suggested_labels = get_objects_from(SuggestedLabel, deleted=False, group=group_id, content_type=get_content_type(File))
    
    class SearchForm(django.forms.Form):
        search = django.forms.CharField(max_length=2048, label=_('Search'), required=False)
       
    if request.POST:
        form = SearchForm(request.POST)

        if form.is_valid():
            if 'upload_file' in request.REQUEST and request.REQUEST['upload_file'] == _('Upload file'):
                return HttpResponseRedirect('/files/add/?group_id=%s&fastsearch=%s' % (group.id, get_string(request, 'fastsearch', default='')))
            return HttpResponseRedirect('/files/groups/%s/?search=%s&fastsearch=%s' % (group_id, search, get_string(request, 'fastsearch', default='')))
 
    else:
        form = SearchForm(initial={'search':search})
    
    full_search = search+','+get_string(request, 'fastsearch', default='')
    files = search_objects_from(full_search, File, owner_group=group)
    
    paginator = Paginator(files.order_by('-creation_time'), page_size)

    number_of_pages = paginator.num_pages
    got_page_size = False

    if number_of_pages != 0:
        if not page:
            page = 1
        page = int(page)
        # TODO: implement getting page ranges
        #end_page = int(request.GET['end_page'])
        end_page = page
        files = paginator.page(page)
    else:
        end_page = 0
        page = 0
        files = []

    next_page = page+1
    has_next_page = paginator.page(page).has_next()
    
    on_all = True
    for suggested_label in suggested_labels:
        if suggested_label.title == get_string(request, 'fastsearch', default=''):
            on_all = False

    return render_to_response(request, 'files/view_files.html', 
        {
            'owner':group,
            'user':request.user,
            'files':files,
            'type':'groups',
            'base_url':'/files/groups/'+str(group.id)+'/', 
            'is_paginated':True, 
            'form':form, 
            'suggested_labels':suggested_labels, 
            'group':group, 
            'number_of_pages':number_of_pages, 
            'page':page, 
            'end_page':end_page, 
            'has_next_page':has_next_page, 
            'has_previous_page':paginator.page(page).has_previous(), 
            'next_page':next_page, 
            'previous_page':page - 1, 
            'page_size':page_size, 
            'fastsearch': get_string(request, 'fastsearch', default=''),
            'search': search,
            'on_all': on_all,
            'paginator':paginator
        })
예제 #4
0
def view_forum(request, group_id=None, suggested_label_title=None, page=None):
    if group_id:
        group = get_object_or_404_and_check_access(request,
                                                   Group,
                                                   pk=group_id,
                                                   command='view')
    else:
        group = request.community
    check_access(request.user, group, 'view')
    page_size = get_integer(request, 'page_size', default=12)
    search = get_string(request, 'search', default='')

    suggested_labels = get_objects_from(SuggestedLabel,
                                        deleted=False,
                                        group=group_id,
                                        content_type=get_content_type(Thread))

    import django.forms

    class SearchForm(django.forms.Form):
        search = django.forms.CharField(max_length=2048,
                                        label=_('Search'),
                                        required=False)

    if request.POST:
        form = SearchForm(request.POST)

        if form.is_valid():
            if 'create_thread' in request.REQUEST and request.REQUEST[
                    'create_thread'] == _('Create thread'):
                return HttpResponseRedirect(
                    '/forums/add/?group_id=%s&labels=%s' %
                    (group.id, get_string(request, 'fastsearch', default='')))
            return HttpResponseRedirect(
                '/forums/%s/?search=%s&fastsearch=%s' %
                (group_id, search, get_string(
                    request, 'fastsearch', default='')))
    else:
        form = SearchForm(initial={'search': search})

    full_search = search + ',' + get_string(request, 'fastsearch', default='')
    if full_search == ',':
        full_search = ''
    threads = search_objects_from(full_search, Thread, owner_group=group)

    paginator = Paginator(threads.order_by('-last_changed_time'), page_size)

    number_of_pages = paginator.num_pages
    got_page_size = False

    if number_of_pages != 0:
        if not page:
            page = 1
        page = int(page)
        # TODO: implement getting page ranges
        #end_page = int(request.GET['end_page'])
        end_page = page
        threads = paginator.page(page)
    else:
        end_page = 0
        page = 0
        threads = []

    next_page = page + 1
    has_next_page = paginator.page(page).has_next()

    on_all = True
    for suggested_label in suggested_labels:
        if suggested_label.title == get_string(request,
                                               'fastsearch',
                                               default=''):
            on_all = False

    return render_to_response(
        request, 'forums/view_forum.html', {
            'base_url': '/forums/' + str(group.id) + '/',
            'is_paginated': True,
            'form': form,
            'threads': threads,
            'suggested_labels': suggested_labels,
            'group': group,
            'number_of_pages': number_of_pages,
            'page': page,
            'end_page': end_page,
            'has_next_page': has_next_page,
            'has_previous_page': paginator.page(page).has_previous(),
            'next_page': next_page,
            'previous_page': page - 1,
            'page_size': page_size,
            'search': search,
            'fastsearch': get_string(request, 'fastsearch', default=''),
            'on_all': on_all,
            'paginator': paginator,
            'add_form': get_add_form()(initial={})
        })