Ejemplo n.º 1
0
            "description": instance.html[:20],
            "state": state,
        }
        res = requests.post(settings.KIPINHALL_QA_SEND_UPDATE, data=data).json()
    except Exception as ex:
        log.error("Error occured attemtpting to update KH %s" % str(ex))


def add_question_event(instance, **kwargs):
    """
    delegation event called on question creation
    """
    post_to_kipinhall(instance, "new")


node_create.connect(add_question_event, sender=Question)


def fetch_kipinhall_profile(tikcet):
    """
    performs a request to the server with the ticket
    """
    user_info = requests.get(
        settings.KIPINHALL_PROFILE_URL,
        params={"c": settings.KIPINHALL_AUTH_CLIENT_NAME, "k": settings.KIPINHALL_AUTH_UNSALTED_KEY, "ticket": tikcet},
    )
    return user_info.json()


def redirect_to_kipinhall_login(request):
    """
Ejemplo n.º 2
0
import datetime
from django.db.models.signals import post_save
from forum.models import *
from forum.models.base import marked_deleted, mark_canceled
from forum.models.node import node_create
from forum.models.answer import answer_accepted
from forum.authentication import user_updated
from forum.const import *

def record_ask_event(instance, **kwargs):
    activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ASK_QUESTION)
    activity.save()

node_create.connect(record_ask_event, sender=Question)


def record_answer_event(instance, **kwargs):
    activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ANSWER)
    activity.save()

node_create.connect(record_answer_event, sender=Answer)


def record_comment_event(instance, **kwargs):
    act_type = (instance.content_object.__class__ is Question) and TYPE_ACTIVITY_COMMENT_QUESTION or TYPE_ACTIVITY_COMMENT_ANSWER
    activity = Activity(user=instance.user, active_at=instance.added_at, content_object=instance, activity_type=act_type)
    activity.save()

node_create.connect(record_comment_event, sender=Comment)

Ejemplo n.º 3
0
        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)


node_create.connect(question_posted, sender=Question)


def answer_posted(instance, **kwargs):
    answer = instance
    question = answer.question

    subscribers = (
        question.subscribers.values("email", "username")
        .filter(
            subscription_settings__enable_notifications=True,
            subscription_settings__notify_answers=True,
            subscription_settings__subscribed_questions="i",
        )
        .exclude(id=answer.author.id)
        .distinct()
Ejemplo n.º 4
0
    })

    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)

node_create.connect(question_posted, sender=Question)


def answer_posted(instance, **kwargs):
    answer = instance
    question = answer.question

    subscribers = question.subscribers.values('email', 'username').filter(
            subscription_settings__enable_notifications=True,
            subscription_settings__notify_answers=True,
            subscription_settings__subscribed_questions='i'
    ).exclude(id=answer.author.id).distinct()
    recipients = create_recipients_dict(subscribers)

    send_email(settings.EMAIL_SUBJECT_PREFIX + _("New answer to '%(question_title)s'") % dict(question_title=question.title),
               recipients, "notifications/newanswer.html", {