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


Python models.Activity类代码示例

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


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

示例1: create_activity_entry

 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,代码行数:27,代码来源:tasks.py

示例2: create_activity_entry

 def create_activity_entry(self, entry, sender, activity_prefix=None):
     """Create activity feed entries for the provided feed entry."""
     verb, object_type = None, None
     if activity_prefix:
         verb = self.get_namespaced_attr(
             entry, activity_prefix, 'verb')
         object_type = self.get_namespaced_attr(
             entry, activity_prefix, 'object-type')
     if not verb:
         verb = 'http://activitystrea.ms/schema/1.0/post'
     if not object_type:
         object_type = 'http://activitystrea.ms/schema/1.0/article'
     title = getattr(entry, 'title', None)
     uri = getattr(entry, 'link', None)
     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=verb, remote_object=remote_obj)
         if link.project:
             activity.target_project = link.project
         activity.save()
开发者ID:phastafrican,项目名称:lernanta,代码行数:25,代码来源:tasks.py

示例3: status_creation_handler

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='http://activitystrea.ms/schema/1.0/post',
        status=status,
    )
    if status.project:
        activity.target_project = 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:MJae,项目名称:lernanta,代码行数:25,代码来源:models.py

示例4: follow_handler

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,代码行数:31,代码来源:models.py

示例5: import_from_old_site

def import_from_old_site(request):
    user = request.user.get_profile()
    if request.method == 'POST':
        form = project_forms.ImportProjectForm(request.POST)
        if form.is_valid():
            course = form.cleaned_data['course']
            #CS - too much logic in view
            project = Project(name=course['name'], kind=course['kind'],
                short_description=course['short_description'],
                long_description=course['long_description'],
                imported_from=course['slug'])
            project.save()
            act = Activity(actor=user,
                verb=verbs['post'],
                scope_object=project,
                target_object=project)
            act.save()
            participation = Participation(project=project, user=user,
                organizing=True)
            participation.save()
            new_rel, created = Relationship.objects.get_or_create(source=user,
                target_project=project)
            new_rel.deleted = False
            new_rel.save()
            if course['detailed_description']:
                detailed_description_content = course['detailed_description']
            else:
                detailed_description_content = render_to_string(
                    "projects/detailed_description_initial_content.html",
                    {'project': project})
            detailed_description = Page(title=_('Full Description'),
                slug='full-description', content=detailed_description_content,
                listed=False, author_id=user.id, project_id=project.id)
            detailed_description.save()
            project.detailed_description_id = detailed_description.id
            sign_up = Signup(between_participants=course['sign_up'],
                author_id=user.id, project_id=project.id)
            sign_up.save()
            project.save()
            for title, content in course['tasks']:
                new_task = Page(title=title, content=content, author=user,
                    project=project)
                new_task.save()
            for name, url in course['links']:
                new_link = Link(name=name, url=url, user=user, project=project)
                new_link.save()
            project.create()
            messages.success(request,
                _('The %s has been imported.') % project.kind.lower())
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            msg = _("Problem importing the study group, course, ...")
            messages.error(request, msg)
    else:
        form = project_forms.ImportProjectForm()
    return render_to_response('projects/project_import.html', {
        'form': form, 'import_tab': True},
        context_instance=RequestContext(request))
开发者ID:Acidburn0zzz,项目名称:lernanta,代码行数:60,代码来源:views.py

示例6: follow_handler

def follow_handler(sender, **kwargs):
    rel = kwargs.get("instance", None)
    if not isinstance(rel, Relationship):
        return
    user_subject = _("%(name)s is following you on Drumbeat!" % {"name": rel.source.name})
    project_subject = _("%(name)s is following your project on Drumbeat!" % {"name": rel.source.name})
    activity = Activity(actor=rel.source, verb="http://activitystrea.ms/schema/1.0/follow")
    subject = _(u"%(name)s is now following")
    if rel.target_user:
        activity.target_user = rel.target_user
        user = rel.target_user
        pref_key = "no_email_new_follower"
        subject = user_subject
    else:
        activity.project = rel.target_project
        user = rel.target_project.created_by
        pref_key = "no_email_new_project_follower"
        subject = project_subject
    activity.save()

    preferences = AccountPreferences.objects.filter(user=user)
    for pref in preferences:
        if pref.value and pref.key == pref_key:
            return

    body = render_to_string(
        "relationships/emails/new_follower.txt", {"user": rel.source, "project": rel.target_project}
    )
    SendUserEmail.apply_async((user, subject, body))
开发者ID:rossbruniges,项目名称:batucada,代码行数:29,代码来源:models.py

示例7: follow_handler

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,代码行数:27,代码来源:models.py

示例8: clone

def clone(request):
    user = request.user.get_profile()
    if request.method == 'POST':
        form = project_forms.CloneProjectForm(request.POST)
        if form.is_valid():
            base_project = form.cleaned_data['project']
            project = Project(name=base_project.name, kind=base_project.kind,
                short_description=base_project.short_description,
                long_description=base_project.long_description,
                clone_of=base_project)
            project.save()
            act = Activity(actor=user,
                verb=verbs['post'],
                scope_object=project,
                target_object=project)
            act.save()
            participation = Participation(project=project, user=user,
                organizing=True)
            participation.save()
            new_rel, created = Relationship.objects.get_or_create(source=user,
                target_project=project)
            new_rel.deleted = False
            new_rel.save()
            detailed_description = Page(title=_('Full Description'),
                slug='full-description',
                content=base_project.detailed_description.content,
                listed=False, author_id=user.id, project_id=project.id)
            detailed_description.save()
            project.detailed_description_id = detailed_description.id
            sign_up = Page(title=_('Sign-Up'), slug='sign-up',
                content=base_project.sign_up.content, listed=False,
                editable=False, author_id=user.id, project_id=project.id)
            sign_up.save()
            project.sign_up_id = sign_up.id
            project.save()
            tasks = Page.objects.filter(project=base_project, listed=True,
                deleted=False).order_by('index')
            for task in tasks:
                new_task = Page(title=task.title, content=task.content,
                    author=user, project=project)
                new_task.save()
            links = Link.objects.filter(project=base_project).order_by('index')
            for link in links:
                new_link = Link(name=link.name, url=link.url, user=user,
                    project=project)
                new_link.save()
            project.create()
            messages.success(request,
                _('The %s has been cloned.') % project.kind.lower())
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            messages.error(request,
                _("There was a problem cloning the study group, course, ..."))
    else:
        form = project_forms.CloneProjectForm()
    return render_to_response('projects/project_clone.html', {
        'form': form, 'clone_tab': True,
    }, context_instance=RequestContext(request))
开发者ID:vtamara,项目名称:lernanta,代码行数:60,代码来源:views.py

示例9: status_creation_handler

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

    # convert status body to markdown and bleachify
    bl = Bleach()
    status.status = urlize(status.status)
    status.status = bl.clean(markdown(status.status), tags=TAGS)
    status.save()

    # fire activity
    activity = Activity(
        actor=status.author,
        verb='http://activitystrea.ms/schema/1.0/post',
        status=status,
    )
    if status.project:
        activity.target_project = status.project
    activity.save()
    # Send notifications.
    if activity.target_project:
        activity.target_project.send_update_notification(activity)
开发者ID:Suggsgested,项目名称:lernanta,代码行数:25,代码来源:models.py

示例10: create

def create(request, category=None):
    user = request.user.get_profile()
    if request.method == 'POST':
        form = project_forms.ProjectForm(category, request.POST)
        image_form = None
        if form.is_valid():
            project = form.save()
            if category:
                project.category = category
            image_form = project_forms.ProjectImageForm(request.POST,
                request.FILES, instance=project)
            if image_form.is_valid():
                image_form.save()
            project.set_duration(form.cleaned_data['duration'] or 0)
            #CS - too much logic in view
            act = Activity(actor=user,
                verb=verbs['post'],
                scope_object=project,
                target_object=project)
            act.save()
            participation = Participation(project=project, user=user,
                organizing=True)
            participation.save()
            new_rel, created = Relationship.objects.get_or_create(source=user,
                target_project=project)
            new_rel.deleted = False
            new_rel.save()
            detailed_description_content = render_to_string(
                "projects/detailed_description_initial_content.html",
                {'project': project})
            detailed_description = Page(title=_('Full Description'),
                slug='full-description', content=detailed_description_content,
                listed=False, author_id=user.id, project_id=project.id)
            if project.category != Project.STUDY_GROUP:
                detailed_description.collaborative = False
            detailed_description.save()
            project.detailed_description_id = detailed_description.id
            sign_up = Signup(author_id=user.id, project_id=project.id)
            sign_up.save()
            project.create()
            messages.success(request,
                _('The %s has been created.') % project.kind.lower())
            return http.HttpResponseRedirect(reverse('projects_create_tasks',
                kwargs={'slug': project.slug,}))
        else:
            msg = _("Problem creating the course")
            messages.error(request, msg)
    else:
        form = project_forms.ProjectForm(category, initial={'test':True})
        image_form = project_forms.ProjectImageForm()
    context = {
        'form': form,
        'image_form': image_form,
        'category': category,
        'is_challenge': (category == Project.CHALLENGE),
    }
    return render_to_response('projects/project_create_overview.html',
        context, context_instance=RequestContext(request))
开发者ID:aespaldi,项目名称:lernanta,代码行数:58,代码来源:views.py

示例11: plan

def plan(request):
    act = Activity()
    act.participants = selectUser(request.user)
    act.num_participants = 2
    act.save()
    for u in act.participants:
        feed = Feed(user=u, content=act)
        feed.save()
    return HttpResponse("ok")
开发者ID:fish1725,项目名称:Hit,代码行数:9,代码来源:views.py

示例12: create

def create(request):
    user = request.user.get_profile()
    school = None
    if request.method == 'POST':
        form = project_forms.CreateProjectForm(request.POST)
        if form.is_valid():
            project = form.save()
            act = Activity(actor=user,
                verb='http://activitystrea.ms/schema/1.0/post',
                project=project,
                target_project=project)
            act.save()
            participation = Participation(project= project, user=user, organizing=True)
            participation.save()
            new_rel = Relationship(source=user, target_project=project)
            try:
                new_rel.save()
            except IntegrityError:
                pass
            detailed_description_content = render_to_string(
                "projects/detailed_description_initial_content.html",
                {})
            detailed_description = Page(title=_('Full Description'), slug='full-description',
                content=detailed_description_content, listed=False,
                author_id=user.id, project_id=project.id)
            detailed_description.save()
            project.detailed_description_id = detailed_description.id
            sign_up_content = render_to_string("projects/sign_up_initial_content.html",
                {})
            sign_up = Page(title=_('Sign-Up'), slug='sign-up',
                content=sign_up_content, listed=False, editable=False,
                author_id=user.id, project_id=project.id)
            sign_up.save()
            project.sign_up_id = sign_up.id
            project.save()
            messages.success(request, _('The study group has been created.'))
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            messages.error(request,
                _("There was a problem creating the study group."))
    else:
        if 'school' in request.GET:
            try:
                school = School.objects.get(slug=request.GET['school'])
                form = project_forms.CreateProjectForm(initial={'school': school})
            except School.DoesNotExist:
                return http.HttpResponseRedirect(reverse('projects_create'))
        else:
            form = project_forms.CreateProjectForm()
    return render_to_response('projects/project_edit_summary.html', {
        'form': form, 'new_tab': True, 'school': school,
    }, context_instance=RequestContext(request))
开发者ID:lorichard,项目名称:lernanta,代码行数:54,代码来源:views.py

示例13: fire_activity

def fire_activity(sender, **kwargs):
    instance = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    is_comment = isinstance(instance, PageComment)
    if created and is_comment:
        instance.send_comment_notification()
        if instance.page_object.comments_fire_activity():
            from activity.models import Activity
            activity = Activity(actor=instance.author, verb=verbs['post'],
                target_object=instance, scope_object=instance.scope_object)
            activity.save()
开发者ID:Cyber-World-Uk-Ltd,项目名称:lernanta,代码行数:11,代码来源:models.py

示例14: follow_handler

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,代码行数:53,代码来源:models.py

示例15: fire_activity

def fire_activity(sender, **kwargs):
    instance = kwargs.get('instance', None)
    created = kwargs.get('created', False)
    is_comment = isinstance(instance, PageComment)
    if created and is_comment:
        from signups.models import SignupAnswer
        ct = ContentType.objects.get_for_model(SignupAnswer)
        if instance.page_content_type != ct:
            statsd.Statsd.increment('comments')
        if instance.page_object and instance.page_object.comments_fire_activity():
            from activity.models import Activity
            activity = Activity(actor=instance.author, verb=verbs['post'],
                target_object=instance, scope_object=instance.scope_object)
            activity.save()
开发者ID:hoocke,项目名称:lernanta,代码行数:14,代码来源:models.py


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