Beispiel #1
0
def edit_poll(request, group, poll_id):
    poll = get_object_or_404(Poll, pk = poll_id)
    if not poll.allow_editing():
        raise PermissionDenied()

    postdata = None
    if request.method == 'POST':
        postdata = request.POST

    form = PollForm(postdata, instance = poll)
    choiceforms = [ PollChoiceForm( postdata,
                                    prefix = 'choice_%d' % choice.id,
                                    instance = choice,
                                    ) for choice in poll.pollchoice_set.all() ]

    if request.method == 'POST' and form.is_valid() \
            and not [ True for choiceform in choiceforms if not choiceform.is_valid() ]:
        form.save()
        for choiceform in choiceforms:
            choiceform.save()

        return HttpResponseRedirect(sph_reverse('sphene.sphboard.views.showThread',
                                                kwargs = { 'thread_id': poll.post.get_thread().id }))

    return sph_render_to_response('sphene/sphboard/edit_poll.html',
                                  { 'form': form,
                                    'choiceforms': choiceforms,
                                    })
def edit_poll(request, group, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    if not poll.allow_editing():
        raise PermissionDenied()

    postdata = None
    if request.method == "POST":
        postdata = request.POST

    form = PollForm(postdata, instance=poll)
    choiceforms = [
        PollChoiceForm(postdata, prefix="choice_%d" % choice.id, instance=choice)
        for choice in poll.pollchoice_set.all()
    ]

    if (
        request.method == "POST"
        and form.is_valid()
        and not [True for choiceform in choiceforms if not choiceform.is_valid()]
    ):
        form.save()
        for choiceform in choiceforms:
            choiceform.save()

        return HttpResponseRedirect(
            sph_reverse("sphene.sphboard.views.showThread", kwargs={"thread_id": poll.post.get_thread().id})
        )

    return sph_render_to_response("sphene/sphboard/edit_poll.html", {"form": form, "choiceforms": choiceforms})
Beispiel #3
0
def edit_poll(request, group, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    if not poll.allow_editing():
        raise PermissionDenied()

    postdata = None
    if request.method == 'POST':
        postdata = request.POST

    form = PollForm(postdata, instance=poll)
    choiceforms = [
        PollChoiceForm(
            postdata,
            prefix='choice_%d' % choice.id,
            instance=choice,
        ) for choice in poll.pollchoice_set.all()
    ]

    if request.method == 'POST' and form.is_valid() \
            and not [ True for choiceform in choiceforms if not choiceform.is_valid() ]:
        form.save()
        for choiceform in choiceforms:
            choiceform.save()

        return HttpResponseRedirect(
            sph_reverse('sphene.sphboard.views.showThread',
                        kwargs={'thread_id': poll.post.get_thread().id}))

    return sph_render_to_response('sphene/sphboard/edit_poll.html', {
        'form': form,
        'choiceforms': choiceforms,
    })
Beispiel #4
0
def view_search_posts(request, group):
    query = request.GET.get('query', '')
    results = None
    terms = query.split(' ')
    start = 0
    end = 0
    prev = False
    next = False
    count = 0
    category = None
    category_id = ''
    try:
        category_id = int(request.GET.get('category_id', 0))
        try:
            category = Category.objects.get(pk=category_id)
        except Category.DoesNotExist:
            pass
    except ValueError:
        pass

    if query:
        results = search_posts(query=query, category=category)
        start = int(request.GET.get('start', 0))
        end = start + pagingsize
        count = results.count()
        results = results[start:end]

        start += 1
        if start > 1:
            prev = mark_safe(u'?query=%s&start=%d&category_id=%s' %
                             (urlquote_plus(query),
                              max(0, start - pagingsize - 1), category_id))
        if end < count:
            next = mark_safe(u'?query=%s&amp;start=%d&amp;category_id=%s' %
                             (urlquote_plus(query), end, category_id))
        if end > count:
            end = count

    return sph_render_to_response(
        'sphene/sphsearchboard/search.html', {
            'query': query,
            'results': results,
            'terms': terms,
            'start': start,
            'end': end,
            'prev': prev,
            'next': next,
            'count': count,
            'category': category,
        })
Beispiel #5
0
def view_search_posts(request, group):
    query = request.GET.get('query', '')
    results = None
    terms = query.split(' ')
    start = 0
    end = 0
    prev = False
    next = False
    count = 0
    category = None
    category_id = ''
    try:
        category_id = int(request.GET.get('category_id', 0))
        try:
            category = Category.objects.get(pk = category_id)
        except Category.DoesNotExist:
            pass
    except ValueError:
        pass

    if query:
        results = search_posts(query=query, category=category)
        start = int(request.GET.get('start', 0))
        end = start + pagingsize
        count = results.count()
        results = results[start:end]

        start += 1
        if start > 1:
            prev = mark_safe(u'?query=%s&amp;start=%d&amp;category_id=%s' % (urlquote_plus(query), max(0,start-pagingsize-1), category_id))
        if end < count:
            next = mark_safe(u'?query=%s&amp;start=%d&amp;category_id=%s' % (urlquote_plus(query), end, category_id))
        if end > count:
            end = count

    return sph_render_to_response('sphene/sphsearchboard/search.html',
                                  { 'query': query,
                                    'results': results,
                                    'terms': terms,
                                    'start': start,
                                    'end': end,
                                    'prev': prev,
                                    'next': next,
                                    'count': count,
                                    'category': category, })
def listThreads(request, group, category_id):
    """
    THIS IS JUST FOR TESTING PURPOSES FOR NOW !!!
    """
    from sphene.sphboard.lists import ThreadList

    # TODO check permissions
    queryset = ThreadInformation.objects.filter(category__pk=category_id)
    queryset = queryset.select_related("root_post", "latest_post")
    threadlist = ThreadList(
        objlist.QuerySetProvider(queryset),
        object_name=_("Threads"),
        prefix="threadlist",
        session=request.session,
        requestvars=request.GET,
        defaultsortby="latestpostdate",
        defaultsortorder="desc",
        defaultcolconfig=("newpost", ("subject", "author"), "views", "posts", ("latestpostdate", "latestpostauthor")),
    )
    return sph_render_to_response("sphene/sphboard/new_list_threads.html", {"threadlist": threadlist})
Beispiel #7
0
def listThreads(request, group, category_id):
    """
    THIS IS JUST FOR TESTING PURPOSES FOR NOW !!!
    """
    from sphene.sphboard.lists import ThreadList
    # TODO check permissions
    queryset = ThreadInformation.objects.filter( category__pk = category_id )
    queryset = queryset.select_related( 'root_post', 'latest_post', )
    threadlist = ThreadList(objlist.QuerySetProvider(queryset),
                            object_name = ugettext_lazy( 'Threads' ),
                            prefix = 'threadlist',
                            session = request.session,
                            requestvars = request.GET,
                            defaultsortby = 'latestpostdate',
                            defaultsortorder = 'desc',
                            defaultcolconfig = ( 'newpost',
                                                 ( 'subject',
                                                   'author', ),
                                                 'views',
                                                 'posts', 
                                                 ( 'latestpostdate',
                                                   'latestpostauthor', ), ), )
    return sph_render_to_response( 'sphene/sphboard/new_list_threads.html',
                                   { 'threadlist': threadlist, })
Beispiel #8
0
def listThreads(request, group, category_id):
    """
    THIS IS JUST FOR TESTING PURPOSES FOR NOW !!!
    """
    from sphene.sphboard.lists import ThreadList
    # TODO check permissions
    queryset = ThreadInformation.objects.filter(category__pk=category_id)
    queryset = queryset.select_related(
        'root_post',
        'latest_post',
    )
    threadlist = ThreadList(
        objlist.QuerySetProvider(queryset),
        object_name=_('Threads'),
        prefix='threadlist',
        session=request.session,
        requestvars=request.GET,
        defaultsortby='latestpostdate',
        defaultsortorder='desc',
        defaultcolconfig=(
            'newpost',
            (
                'subject',
                'author',
            ),
            'views',
            'posts',
            (
                'latestpostdate',
                'latestpostauthor',
            ),
        ),
    )
    return sph_render_to_response('sphene/sphboard/new_list_threads.html', {
        'threadlist': threadlist,
    })