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


Python Activity.scope_object方法代码示例

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


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

示例1: create_activity_entry

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
 def create_activity_entry(self, entry, sender, activity_prefix=None):
     """Create activity feed entries for the provided feed entry."""
     object_type = None
     if activity_prefix:
         object_type = self.get_namespaced_attr(
             entry, activity_prefix, 'object-type')
     if not object_type:
         object_type = object_types['article']
     title = getattr(entry, 'title', None)
     uri = getattr(entry, 'link', None)
     if not title:
         title = entry.get('title')
     if not uri:
         uris = entry.get('links')
         if uris:
             uri = uris[0].get('href')
     if not (title and uri):
         return
     for link in sender.link_set.all():
         remote_obj = RemoteObject(
             link=link, title=title, uri=uri, object_type=object_type)
         remote_obj.save()
         activity = Activity(
             actor=link.user, verb=verbs['share'], target_object=remote_obj)
         if link.project:
             activity.scope_object = link.project
         activity.save()
开发者ID:Acidburn0zzz,项目名称:lernanta,代码行数:29,代码来源:tasks.py

示例2: follow_handler

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
def follow_handler(sender, **kwargs):
    rel = kwargs.get("instance", None)
    created = kwargs.get("created", False)
    if not created or not isinstance(rel, Relationship) or rel.deleted:
        return
    activity = Activity(actor=rel.source, verb=verbs["follow"], target_object=rel)
    recipients = []
    if rel.target_user:
        preferences = AccountPreferences.objects.filter(user=rel.target_user, key="no_email_new_follower")
        for pref in preferences:
            if pref.value:
                break
        else:
            recipients.append(rel.target_user)
    else:
        activity.scope_object = rel.target_project
        for organizer in rel.target_project.organizers():
            if organizer.user != rel.source:
                preferences = AccountPreferences.objects.filter(
                    user=organizer.user, key="no_email_new_project_follower"
                )
                for pref in preferences:
                    if pref.value:
                        break
                else:
                    recipients.append(organizer.user)
    activity.save()
    subject_template = "relationships/emails/new_follower_subject.txt"
    body_template = "relationships/emails/new_follower.txt"
    context = {"user": rel.source, "project": rel.target_project, "domain": Site.objects.get_current().domain}
    send_notifications_i18n(recipients, subject_template, body_template, context)
开发者ID:Inkbug,项目名称:lernanta,代码行数:33,代码来源:models.py

示例3: status_creation_handler

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
def status_creation_handler(sender, **kwargs):
    status = kwargs.get('instance', None)
    created = kwargs.get('created', False)

    if not created or not isinstance(status, Status):
        return

    # clean html
    status.status = bleach.clean(status.status,
        tags=settings.REDUCED_ALLOWED_TAGS,
        attributes=settings.REDUCED_ALLOWED_ATTRIBUTES, strip=True)
    status.save()

    # fire activity
    activity = Activity(
        actor=status.author,
        verb=verbs['post'],
        target_object=status,
    )
    if status.project:
        activity.scope_object = status.project
    if status.in_reply_to:
        activity.parent = status.in_reply_to
    activity.save()
    # Send notifications.
    if status.project:
        status.send_wall_notification()
开发者ID:vtamara,项目名称:lernanta,代码行数:29,代码来源:models.py

示例4: follow_handler

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
def follow_handler(sender, **kwargs):
    rel = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    if not created or not isinstance(rel, Relationship) or rel.deleted:
        return
    activity = Activity(actor=rel.source,
                        verb=verbs['follow'],
                        target_object=rel)
    recipients = []
    if rel.target_user:
        recipients.append(rel.target_user)
    else:
        activity.scope_object = rel.target_project
        for organizer in rel.target_project.organizers():
            if organizer.user != rel.source:
                recipients.append(organizer.user)
    activity.save()
    subject_template = 'relationships/emails/new_follower_subject.txt'
    body_template = 'relationships/emails/new_follower.txt'
    context = {
        'user': rel.source,
        'project': rel.target_project,
        'domain': Site.objects.get_current().domain
    }
    send_notifications_i18n(recipients, subject_template, body_template,
        context, notification_category='new-follower'
    )
开发者ID:Acidburn0zzz,项目名称:lernanta,代码行数:29,代码来源:models.py

示例5: follow_handler

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
def follow_handler(sender, **kwargs):
    rel = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    if not created or not isinstance(rel, Relationship) or rel.deleted:
        return
    activity = Activity(actor=rel.source,
                        verb=verbs['follow'],
                        target_object=rel)
    receipts = []
    ulang = get_language()
    subject = {}
    body = {}
    if rel.target_user:
        for l in settings.SUPPORTED_LANGUAGES:
            activate(l[0])
            subject[l[0]] = ugettext(
                '%(user)s is following you on P2PU!') % {
                'user': rel.source}
        preferences = AccountPreferences.objects.filter(user=rel.target_user)
        for pref in preferences:
            if pref.value and pref.key == 'no_email_new_follower':
                break
        else:
            receipts.append(rel.target_user)
    else:
        activity.scope_object = rel.target_project
        for l in settings.SUPPORTED_LANGUAGES:
            activate(l[0])
            msg = ugettext(
                '%(user)s is following %(project)s on P2PU!')
            subject[l[0]] = msg % {'user': rel.source,
                'project': rel.target_project}
        for organizer in rel.target_project.organizers():
            if organizer.user != rel.source:
                preferences = AccountPreferences.objects.filter(
                    user=organizer.user, key='no_email_new_project_follower')
                for pref in preferences:
                    if pref.value:
                        break
                else:
                    receipts.append(organizer.user)
    activity.save()

    for l in settings.SUPPORTED_LANGUAGES:
        activate(l[0])
        body[l[0]] = render_to_string(
            "relationships/emails/new_follower.txt", {'user': rel.source,
                'project': rel.target_project,
                'domain': Site.objects.get_current().domain})
    activate(ulang)
    for user in receipts:
        pl = user.preflang or settings.LANGUAGE_CODE
        SendUserEmail.apply_async((user, subject[pl], body[pl]))
开发者ID:vtamara,项目名称:lernanta,代码行数:55,代码来源:models.py

示例6: status_creation_handler

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
def status_creation_handler(sender, **kwargs):
    status = kwargs.get('instance', None)
    created = kwargs.get('created', False)

    if not created or not isinstance(status, Status):
        return

    # fire activity
    activity = Activity(
        actor=status.author,
        verb=verbs['post'],
        target_object=status,
    )
    if status.project:
        activity.scope_object = status.project
    activity.save()
开发者ID:PforPain,项目名称:lernanta,代码行数:18,代码来源:models.py

示例7: follow_handler

# 需要导入模块: from activity.models import Activity [as 别名]
# 或者: from activity.models.Activity import scope_object [as 别名]
def follow_handler(sender, **kwargs):
    rel = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    if not created or not isinstance(rel, Relationship) or rel.deleted:
        return
    activity = Activity(actor=rel.source,
                        verb=verbs['follow'],
                        target_object=rel)
    receipts = []
    if rel.target_user:
        preferences = AccountPreferences.objects.filter(
            user=rel.target_user, key='no_email_new_follower')
        for pref in preferences:
            if pref.value:
                break
        else:
            receipts.append(rel.target_user)
    else:
        activity.scope_object = rel.target_project
        for organizer in rel.target_project.organizers():
            if organizer.user != rel.source:
                preferences = AccountPreferences.objects.filter(
                    user=organizer.user, key='no_email_new_project_follower')
                for pref in preferences:
                    if pref.value:
                        break
                else:
                    receipts.append(organizer.user)
    activity.save()
    context = {
        'user': rel.source,
        'project': rel.target_project,
        'domain': Site.objects.get_current().domain
    }
    subjects, bodies = localize_email(
        'relationships/emails/new_follower_subject.txt',
        'relationships/emails/new_follower.txt', context)
    for user in receipts:
        SendUserEmail.apply_async((user, subjects, bodies))
开发者ID:Cyber-World-Uk-Ltd,项目名称:lernanta,代码行数:41,代码来源:models.py


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