Beispiel #1
0
def AskView(request):
    if request.method == 'POST':
        form = AskForm(request.POST)
        if form.is_valid():
            form.save(request)
            url = request.POST.get('next', '/')
            return HttpResponseRedirect(url)
    else:
        form = AskForm()
    return render(request, "forum/ask.html", {'form': form})
Beispiel #2
0
def ask_book(request, short_name):
    if request.method == "POST":
        form = AskForm(request.POST)
        if form.is_valid():
            added_at = datetime.datetime.now()
            html = sanitize_html(markdowner.convert(form.cleaned_data['text']))
            question = Question(
                title            = strip_tags(form.cleaned_data['title']),
                author           = request.user,
                added_at         = added_at,
                last_activity_at = added_at,
                last_activity_by = request.user,
                wiki             = form.cleaned_data['wiki'],
                tagnames         = form.cleaned_data['tags'].strip(),
                html             = html,
                summary          = strip_tags(html)[:120]
            )
            if question.wiki:
                question.last_edited_by = question.author
                question.last_edited_at = added_at
                question.wikified_at = added_at

            question.save()

            # create the first revision
            QuestionRevision.objects.create(
                question   = question,
                revision   = 1,
                title      = question.title,
                author     = request.user,
                revised_at = added_at,
                tagnames   = question.tagnames,
                summary    = CONST['default_version'],
                text       = form.cleaned_data['text']
            )

            books = Book.objects.extra(where=['short_name = %s'], params=[short_name])
            match_count = len(books)
            if match_count == 1:
                # the book info
                book = books[0]
                book.questions.add(question)

            return HttpResponseRedirect(question.get_absolute_url())
    else:
        form = AskForm()

    tags = _get_tags_cache_json()
    return render_to_response('ask.html', {
        'form' : form,
        'tags' : tags,
        'email_validation_faq_url': reverse('faq') + '#validate',
        }, context_instance=RequestContext(request))
Beispiel #3
0
def ask(request, tag=None):
    form = AskForm(request.POST)
    if request.method == 'POST':
        if not form.is_valid():
            return render(request, 'forum/ask.html', {'form': form})
        else:
            question = request.POST.get('question')
            title = form.cleaned_data.get('title')
            user = request.user
            anonymous = request.POST.get('anonymous')
            if anonymous:
                question = Question(question=question,
                                    title=title,
                                    user=user,
                                    anonymous=True)
            else:
                question = Question(question=question, title=title, user=user)
            question.save()
            image0 = request.FILES.get('image0', None)
            image1 = request.FILES.get('image1', None)
            image2 = request.FILES.get('image2', None)
            if image0:
                i = Images()
                a = i.upload_image(image=image0, user=user)
                question.images.add(a)
            if image1:
                i = Images()
                a = i.upload_image(image=image1, user=user)
                question.images.add(a)
            if image2:
                i = Images()
                a = i.upload_image(image=image2, user=user)
                question.images.add(a)
            tags = request.POST.get('tag')
            if len(tags):
                question.set_tags(tags)
            slug = question.slug
            return HttpResponseRedirect('/forum/' + slug)
    else:
        if tag:
            t = []
            t1 = Tags.objects.get(id=tag)
            t.append(t1)
            return render(request, 'forum/ask.html', {'form': form, 't': t})
        else:
            return render(request, 'forum/ask.html', {'form': form})
Beispiel #4
0
def ask(request):
    form = AskForm(request.POST)
    if request.method == 'POST':
        if not form.is_valid():
            return render(request, 'forum/ask.html', {'form': form})
        else:
            question = request.POST.get('question')
            title = form.cleaned_data.get('title')
            user = request.user
            anonymous = request.POST.get('anonymous')
            category = request.POST.get('category')
            if anonymous:
                question = Question(question=question,
                                    title=title,
                                    user=user,
                                    anonymous=True,
                                    category=category)
            else:
                question = Question(question=question,
                                    title=title,
                                    user=user,
                                    category=category)
            question.save()
            image0 = request.FILES.get('image0', None)
            image1 = request.FILES.get('image1', None)
            image2 = request.FILES.get('image2', None)
            if image0:
                i = Images()
                a = i.upload_image(image=image0, user=user)
                question.images.add(a)
            if image1:
                i = Images()
                a = i.upload_image(image=image1, user=user)
                question.images.add(a)
            if image2:
                i = Images()
                a = i.upload_image(image=image2, user=user)
                question.images.add(a)
            tags = request.POST.get('tag')
            question.set_tags(tags)
            slug = question.slug
            return HttpResponseRedirect('/forum/' + slug)
    else:
        return render(request, 'forum/ask.html', {'form': form})
Beispiel #5
0
def ask(request, tag=None):
    form = AskForm(request.POST)
    if request.method == 'POST':
        if not form.is_valid():
            return render(request, 'forum/ask.html', {'form': form})
        else:
            question = request.POST.get('question')
            title = form.cleaned_data.get('title')
            user = request.user
            anonymous = request.POST.get('anonymous')
            if anonymous:
                question = Question(question=question, title=title, user=user, anonymous=True)
            else:
                question = Question(question=question, title=title, user=user)
            question.save()
            image0 = request.FILES.get('image0', None)
            image1 = request.FILES.get('image1', None)
            image2 = request.FILES.get('image2', None)
            if image0:
                i = Images()
                a = i.upload_image(image=image0, user=user)
                question.images.add(a)
            if image1:
                i = Images()
                a = i.upload_image(image=image1, user=user)
                question.images.add(a)
            if image2:
                i = Images()
                a = i.upload_image(image=image2, user=user)
                question.images.add(a)
            tags = request.POST.get('tag')
            if len(tags):
                question.set_tags(tags)
            slug = question.slug
            return HttpResponseRedirect('/forum/'+slug)
    else:
        if tag:
            t = []
            t1 = Tags.objects.get(id=tag)
            t.append(t1)
            return render(request, 'forum/ask.html', {'form': form, 't': t})
        else:
            return render(request, 'forum/ask.html', {'form': form})
Beispiel #6
0
def ask(request):
    form = AskForm(request.POST)
    if request.method == 'POST':
        if not form.is_valid():
            return render(request, 'forum/ask.html', {'form': form})
        else:
            question = request.POST.get('question')
            title = form.cleaned_data.get('title')
            user = request.user
            anonymous = request.POST.get('anonymous')
            category = request.POST.get('category')
            if anonymous:
                question = Question(question=question, title=title, user=user, anonymous=True, category=category)
            else:
                question = Question(question=question, title=title, user=user, category=category)
            question.save()
            image0 = request.FILES.get('image0', None)
            image1 = request.FILES.get('image1', None)
            image2 = request.FILES.get('image2', None)
            if image0:
                i = Images()
                a = i.upload_image(image=image0, user=user)
                question.images.add(a)
            if image1:
                i = Images()
                a = i.upload_image(image=image1, user=user)
                question.images.add(a)
            if image2:
                i = Images()
                a = i.upload_image(image=image2, user=user)
                question.images.add(a)
            tags = request.POST.get('tag')
            question.set_tags(tags)
            slug = question.slug
            return HttpResponseRedirect('/forum/'+slug)
    else:
        return render(request, 'forum/ask.html', {'form': form})