当前位置: 首页>>代码示例>>Python>>正文


Python QuestionSubscription.save方法代码示例

本文整理汇总了Python中forum.models.QuestionSubscription.save方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionSubscription.save方法的具体用法?Python QuestionSubscription.save怎么用?Python QuestionSubscription.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forum.models.QuestionSubscription的用法示例。


在下文中一共展示了QuestionSubscription.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: question_posted

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_posted(action, new):
    question = action.node

    if not question.is_notifiable:
        return

    subscribers = User.objects.filter(
            Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') |
            (Q(subscription_settings__new_question_watched_tags='i') &
              Q(marked_tags__name__in=question.tagnames.split(' ')) &
              Q(tag_selections__reason='good'))
    ).exclude(id=question.author.id).distinct()

    subscribers = filter_subscribers(subscribers)

    send_template_email(subscribers, "notifications/newquestion.html", {'question': question})

    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)
开发者ID:leevenluo,项目名称:QaServer,代码行数:30,代码来源:subscriptions.py

示例2: question_posted

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_posted(sender, instance, **kwargs):
    question = instance.content_object

    subscribers = User.objects.values('email', 'username').filter(
            Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') |
            (Q(subscription_settings__new_question_watched_tags='i') &
              Q(marked_tags__name__in=question.tagnames.split(' ')) &
              Q(tag_selections__reason='good'))
    ).exclude(id=question.author.id)

    recipients = create_recipients_dict(subscribers)

    send_email(settings.EMAIL_SUBJECT_PREFIX + _("New question on %s") % settings.APP_SHORT_NAME,
               recipients, "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)
开发者ID:gvasilev,项目名称:osqa,代码行数:31,代码来源:subscriptions.py

示例3: create_subscription_if_not_exists

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def create_subscription_if_not_exists(question, user):
    try:
        subscription = QuestionSubscription.objects.get(
            question=question, user=user)
    except:
        subscription = QuestionSubscription(question=question, user=user)
        subscription.save()
开发者ID:gvasilev,项目名称:osqa,代码行数:9,代码来源:subscriptions.py

示例4: question_viewed

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_viewed(sender, user, **kwargs):
    try:
        subscription = QuestionSubscription.objects.get(question=sender, user=user)
        subscription.last_view = datetime.datetime.now()
        subscription.save()
    except:
        if user.subscription_settings.questions_viewed:
            subscription = QuestionSubscription(question=sender, user=user)
            subscription.save()
开发者ID:gvasilev,项目名称:osqa,代码行数:11,代码来源:subscriptions.py

示例5: handle_noargs

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
    def handle_noargs(self, **options):
        users = User.objects.all()
        for u in users:
            s = SubscriptionSettings(user=u)
            s.save()

            user_questions = u.questions.all()

            for q in user_questions:
                sub = QuestionSubscription(user=u, question=q)
                sub.save()
开发者ID:CLLKazan,项目名称:iCQA,代码行数:13,代码来源:create_subscriptions.py

示例6: question_viewed

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_viewed(action, new):
    if not action.viewuser.is_authenticated():
        return

    try:
        subscription = QuestionSubscription.objects.get(question=action.node, user=action.viewuser)
        subscription.last_view = datetime.datetime.now()
        subscription.save()
    except:
        if action.viewuser.subscription_settings.questions_viewed:
            subscription = QuestionSubscription(question=action.node, user=action.viewuser)
            subscription.save()
开发者ID:viikasgarg,项目名称:osqa,代码行数:14,代码来源:subscriptions.py

示例7: create_subscription_if_not_exists

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def create_subscription_if_not_exists(question, user):
    try:
        subscription = QuestionSubscription.objects.get(question=question, user=user)
        return subscription
    except QuestionSubscription.MultipleObjectsReturned:
        pass
    except QuestionSubscription.DoesNotExist:
        subscription = QuestionSubscription(question=question, user=user)
        subscription.save()
        return subscription
    except Exception, e:
        logging.error(e)
开发者ID:viikasgarg,项目名称:osqa,代码行数:14,代码来源:subscriptions.py

示例8: question_viewed

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_viewed(instance, user, **kwargs):
    if not user.is_authenticated():
        return

    try:
        subscription = QuestionSubscription.objects.get(question=instance, user=user)
        subscription.last_view = datetime.datetime.now()
        subscription.save()
    except:
        if user.subscription_settings.questions_viewed:
            subscription = QuestionSubscription(question=instance, user=user)
            subscription.save()
开发者ID:pombredanne,项目名称:osqa,代码行数:14,代码来源:subscriptions.py

示例9: create_subscription_for_mailing_list

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def create_subscription_for_mailing_list(question,userquery):
        userlist = [user for user in userquery if user != question.author]
        existingUserList = [subscription.user for  subscription in QuestionSubscription.objects.filter(question=question)]

## remove deleted Mailing List subscriptions
        for sub_remove in list(set(existingUserList) - set (userlist)):
                subscriptions = QuestionSubscription.objects.filter(question=question, user=sub_remove)
                subscriptions.delete()

## Add Mailing List subscriptions
        for sub_add in list(set(userlist) - set (existingUserList)):
                subscription = QuestionSubscription(question=question, user=sub_add)
                subscription.save()
开发者ID:viikasgarg,项目名称:osqa,代码行数:15,代码来源:subscriptions.py

示例10: question_posted

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_posted(instance, **kwargs):
    question = instance

    subscribers = (
        User.objects.values("email", "username")
        .filter(
            Q(subscription_settings__enable_notifications=True, subscription_settings__new_question="i")
            | (
                Q(subscription_settings__new_question_watched_tags="i")
                & Q(marked_tags__name__in=question.tagnames.split(" "))
                & Q(tag_selections__reason="good")
            )
        )
        .exclude(id=question.author.id)
        .distinct()
    )

    recipients = create_recipients_dict(subscribers)

    send_email(
        settings.EMAIL_SUBJECT_PREFIX + _("New question on %(app_name)s") % dict(app_name=settings.APP_SHORT_NAME),
        recipients,
        "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)
开发者ID:pombredanne,项目名称:osqa,代码行数:43,代码来源:subscriptions.py

示例11: question_posted

# 需要导入模块: from forum.models import QuestionSubscription [as 别名]
# 或者: from forum.models.QuestionSubscription import save [as 别名]
def question_posted(action, new):
    question = action.node

    if not question.is_notifiable:
        return

    '''
## Mailing List Depending Upon Category
    _recipient_ids = ",".join([category.mail_recipients for category in OsqaCategory.objects.filter(id__in = question.category.split(','))]).split(",")
    recipient_ids =[ recipient.strip()  for recipient in _recipient_ids if recipient.strip() ]
    if len(recipient_ids):
        category_subscribers = User.objects.filter(id__in =recipient_ids ).distinct()
        all_subscribers = category_subscribers

## Mailing List Subscribers
    recipient_list = [ recipient.strip()  for recipient in question.recipientnames.split(',') if recipient.strip() ]

    if len(recipient_list):
        mailing_subscribers = User.objects.filter(id__in = recipient_list ).distinct()

        if len(recipient_ids):
                all_subscribers = category_subscribers  | mailing_subscribers
        else:
                all_subscribers = mailing_subscribers
    '''
    send_template_email(all_subscribers, "notifications/newquestion.html", {'question': question})

    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)
开发者ID:viikasgarg,项目名称:osqa,代码行数:40,代码来源:subscriptions.py


注:本文中的forum.models.QuestionSubscription.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。