Example #1
0
def ask(request):
    form = None

    if request.POST:
        if request.session.pop('reviewing_pending_data', False):
            form = AskForm(initial=request.POST, user=request.user)
        elif "text" in request.POST:
            form = AskForm(request.POST, user=request.user)
            if form.is_valid():
                if request.user.is_authenticated(
                ) and request.user.email_valid_and_can_ask():
                    ask_action = AskAction(
                        user=request.user,
                        ip=request.META['REMOTE_ADDR']).save(
                            data=form.cleaned_data)
                    question = ask_action.node

                    if settings.WIKI_ON and request.POST.get('wiki', False):
                        question.nstate.wiki = ask_action

                    if "expert_email" in form.cleaned_data:
                        email = form.cleaned_data["expert_email"].split()
                        u = User(username=_("Friend"), email=email)

                        send_template_email([u],
                                            "notifications/newquestion.html", {
                                                'question': question,
                                                "exclude_finetune": True
                                            })

                    return HttpResponseRedirect(question.get_absolute_url())
                else:
                    request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
                        'POST': request.POST,
                        'data_name': _("question"),
                        'type': 'ask',
                        'submission_url': reverse('ask'),
                        'time': datetime.datetime.now()
                    }

                    if request.user.is_authenticated():
                        request.user.message_set.create(
                            message=_("Your question is pending until you %s.")
                            % html.hyperlink(reverse('send_validation_email'),
                                             _("validate your email")))
                        return HttpResponseRedirect(reverse('index'))
                    else:
                        return HttpResponseRedirect(reverse('auth_signin'))
        elif "go" in request.POST:
            form = AskForm({'title': request.POST['q']}, user=request.user)

    if not form:
        form = AskForm(user=request.user)

    return render_to_response('ask.html', {
        'form': form,
        'tab': 'ask'
    },
                              context_instance=RequestContext(request))
Example #2
0
def ask(request):
    form = None

    if request.POST:
        if request.session.pop('reviewing_pending_data', False):
            form = AskForm(initial=request.POST, user=request.user)
        elif "text" in request.POST:
            form = AskForm(request.POST, user=request.user)
            if form.is_valid():
                if request.user.is_authenticated(
                ) and request.user.email_valid_and_can_ask():
                    ask_action = AskAction(
                        user=request.user,
                        ip=request.META['REMOTE_ADDR']).save(
                            data=form.cleaned_data)
                    question = ask_action.node

                    if settings.WIKI_ON and request.POST.get('wiki', False):
                        question.nstate.wiki = ask_action

                    return HttpResponseRedirect(question.get_absolute_url())
                else:
                    request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
                        'POST': request.POST,
                        'data_name': _("question"),
                        'type': 'ask',
                        'submission_url': reverse('ask'),
                        'time': datetime.datetime.now()
                    }

                    if request.user.is_authenticated():
                        messages.info(
                            request,
                            _("Your question is pending until you %s.") %
                            html.hyperlink(
                                django_settings.APP_URL +
                                reverse('send_validation_email', prefix='/'),
                                _("validate your email")))
                        return HttpResponseRedirect(reverse('index'))
                    else:
                        return HttpResponseRedirect(reverse('auth_signin'))
        elif "go" in request.POST:
            form = AskForm({'title': request.POST['q']}, user=request.user)

    if not form:
        form = AskForm(user=request.user)

    return render_to_response('ask.html', {
        'form': form,
        'tab': 'ask'
    },
                              context_instance=RequestContext(request))
Example #3
0
def ask(request):
    if request.POST and "text" in request.POST:
        form = AskForm(request.POST)
        if form.is_valid():
            if request.user.is_authenticated():
                question = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data).node
                return HttpResponseRedirect(question.get_absolute_url())
            else:
                request.session['temp_node_data'] = request.POST
                request.session['temp_node_type'] = 'question'
                return HttpResponseRedirect(reverse('auth_action_signin', kwargs={'action': 'newquestion'}))
    elif request.method == "POST" and "go" in request.POST:
        form = AskForm({'title': request.POST['q']})
    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))
Example #4
0
    room.speak(unicode(message))


def full_app_url(url):
    return APP_URL + url


def question_posted(action, new):
    if not enabled():
        return
    question = action.node
    speak(_('New question: %(headline)s - %(url)s' % {
            'headline': question.headline,
            'url': full_app_url(question.get_absolute_url())
            }))


def answer_posted(action, new):
    if not enabled():
        return
    answer = action.node
    question = answer.question
    speak(_('New answer posted for question: %(headline)s - %(url)s' % {
        'headline': question.headline,
        'url': full_app_url(question.get_absolute_url())
        }))


AskAction.hook(question_posted)
AnswerAction.hook(answer_posted)
Example #5
0
    subscription = QuestionSubscription(question=question,
                                        user=question.author)
    subscription.save()

    new_subscribers = User.objects.filter(
        Q(subscription_settings__all_questions=True)
        | Q(subscription_settings__all_questions_watched_tags=True,
            marked_tags__name__in=question.tagnames.split(' '),
            tag_selections__reason='good'))

    for user in new_subscribers:
        create_subscription_if_not_exists(question, user)


AskAction.hook(question_posted)


def answer_posted(action, new):
    answer = action.node
    question = answer.question

    logging.error("Answer posted: %s" % str(answer.is_notifiable))

    if not answer.is_notifiable or not question.is_notifiable:
        return

    subscribers = question.subscribers.filter(
        subscription_settings__enable_notifications=True,
        subscription_settings__notify_answers=True,
        subscription_settings__subscribed_questions='i').exclude(
Example #6
0
def ask(request):
    form = None
    if request.POST:
        if request.session.pop('reviewing_pending_data', False):
            form = AskForm(initial=request.POST, user=request.user)
        elif "text" in request.POST:
            form = AskForm(request.POST, user=request.user)
            if form.is_valid():
                if request.user.is_authenticated(
                ) and request.user.email_valid_and_can_ask():
                    ask_action = AskAction(
                        user=request.user,
                        ip=request.META['REMOTE_ADDR']).save(
                            data=form.cleaned_data)
                    question = ask_action.node

                    if settings.WIKI_ON and request.POST.get('wiki', False):
                        question.nstate.wiki = ask_action

                    return HttpResponseRedirect(question.get_absolute_url())
                else:
                    request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
                        'POST': request.POST,
                        'data_name': _("question"),
                        'type': 'ask',
                        'submission_url': reverse('ask'),
                        'time': datetime.datetime.now(pytz.utc)
                    }

                    if request.user.is_authenticated():
                        messages.info(
                            request,
                            _("Your question is pending until you %s.") %
                            html.hyperlink(
                                django_settings.APP_URL +
                                reverse('send_validation_email', prefix='/'),
                                _("validate your email")))
                        return HttpResponseRedirect(reverse('index'))
                    else:
                        return HttpResponseRedirect(reverse('auth_signin'))
        elif "go" in request.POST:
            form = AskForm({'title': request.POST['q']}, user=request.user)

    #BEGIN

    template_name = 'ask.html'
    if not form:
        # BEGIN
        # Changed this part to link OSQA to Magnate's zinnia entries
        #
        # Original: form = AskForm(user=request.user)
        from zinnia.models.entry import Entry
        entry_id = None
        entry_title = None
        try:
            entry_id = int(request.GET.get('entry_id'))
            entry = Entry.objects.get(pk=entry_id)
            if entry.is_public(
            ):  # Can only ask questions about public entries
                form = AskForm(user=request.user,
                               initial={
                                   'entry_id': entry_id,
                                   'entry_title': entry.title
                               })
                template_name = 'ask_about.html'
            else:
                # No point to ask questions about private entries,
                # as this is likely a mistake.
                raise Http404
        except (TypeError, ValueError, Entry.DoesNotExist) as e:
            # No point to ask questions about no entry in particular,
            # as nobody will ever find them.
            #
            # form = AskForm(user=request.user)
            # template_name='ask.html'
            raise Http404

    # Also changed below ask.html --> ask_about.html
    # END

    # template_name was just ask.html
    return render_to_response(template_name, {
        'form': form,
        'tab': 'ask',
    },
                              context_instance=RequestContext(request))
Example #7
0
    send_template_email(subscribers, "notifications/newquestion.html", {'question': question})

    if question.author.subscription_settings.questions_asked:
        subscription = QuestionSubscription(question=question, user=question.author)
        subscription.save()

    new_subscribers = User.objects.filter(
            Q(subscription_settings__all_questions=True) |
            Q(subscription_settings__all_questions_watched_tags=True,
                    marked_tags__name__in=question.tagnames.split(' '),
                    tag_selections__reason='good'))

    for user in new_subscribers:
        create_subscription_if_not_exists(question, user)

AskAction.hook(question_posted)


def answer_posted(action, new):
    answer = action.node
    question = answer.question

    subscribers = question.subscribers.filter(
            subscription_settings__enable_notifications=True,
            subscription_settings__notify_answers=True,
            subscription_settings__subscribed_questions='i'
    ).exclude(id=answer.author.id).distinct()

    subscribers = filter_subscribers(subscribers)

    send_template_email(subscribers, "notifications/newanswer.html", {'answer': answer})