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


Python Participation.save方法代码示例

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


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

示例1: edit_participants

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def edit_participants(request, slug):
    project = get_object_or_404(Project, slug=slug)
    metric_permissions = project.get_metrics_permissions(request.user)
    if request.method == 'POST':
        form = project_forms.ProjectAddParticipantForm(project, request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            organizing = form.cleaned_data['organizer']
            participation = Participation(project=project, user=user,
                organizing=organizing)
            participation.save()
            new_rel, created = Relationship.objects.get_or_create(
                source=user, target_project=project)
            new_rel.deleted = False
            new_rel.save()
            messages.success(request, _('Participant added.'))
            return http.HttpResponseRedirect(reverse(
                'projects_edit_participants',
                kwargs=dict(slug=project.slug)))
        else:
            messages.error(request,
                _('There was an error adding the participant.'))
    else:
        form = project_forms.ProjectAddParticipantForm(project)
    return render_to_response('projects/project_edit_participants.html', {
        'project': project,
        'form': form,
        'participations': project.participants().order_by('joined_on'),
        'participants_tab': True,
        'can_view_metric_overview': metric_permissions[0],
        'is_challenge': (project.category == project.CHALLENGE),
    }, context_instance=RequestContext(request))
开发者ID:IAmCorbin,项目名称:lernanta,代码行数:34,代码来源:views.py

示例2: setUp

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
 def setUp(self):
     self.client = Client()
     self.locale = 'en'
     django_user = User(
         username=self.test_username,
         email=self.test_email,
     )
     self.user = create_profile(django_user)
     self.user.set_password(self.test_password)
     self.user.save()
     self.project = Project(name='My Cool Project',
         short_description='This project is awesome',
         long_description='No really, its good',
     )
     self.project.save()
     participation = Participation(project=self.project,
         user=self.user, organizing=True)
     participation.save()
     for i in xrange(3):
         page = Page(author=self.user,
             project=self.project,
             title='Old Title %s' % i,
             sub_header='Old Tagline %s' % i,
             content='Old Content %s' % i,
             index=2*(i+1))
         page.save()
开发者ID:JiaFeiX,项目名称:lernanta,代码行数:28,代码来源:tests.py

示例3: edit_participants

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def edit_participants(request, slug):
    project = get_object_or_404(Project, slug=slug)
    if request.method == 'POST':
        form = project_forms.ProjectAddParticipantForm(project, request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            participation = Participation(project= project, user=user)
            participation.save()
            new_rel = Relationship(source=user, target_project=project)
            try:
                new_rel.save()
            except IntegrityError:
                pass
            messages.success(request, _('Participant added.'))
            return http.HttpResponseRedirect(
                reverse('projects_edit_participants', kwargs=dict(slug=project.slug)))
        else:
            messages.error(request, _('There was an error adding the participant.'))
    else:
        form = project_forms.ProjectAddParticipantForm(project)
    return render_to_response('projects/project_edit_participants.html', {
        'project': project,
        'form': form,
        'participations': project.participants(),
    }, context_instance=RequestContext(request))
开发者ID:AndyHendy,项目名称:lernanta,代码行数:27,代码来源:views.py

示例4: direct_signup

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def direct_signup(request, slug):
    project = get_object_or_404(Project, slug=slug)
    profile = request.user.get_profile()
    is_organizing = project.organizers().filter(user=profile).exists()
    if is_organizing:
        return http.HttpResponseForbidden(
            _('Organizers can\'t use this page to leave their group.'))
    if request.method != 'POST':
        return http.HttpResponseForbidden(
            _('This page can not be accessed with a get request.'))
    participations = Participation.objects.filter(user=profile,
        project=project, left_on__isnull=True)
    if participations:
        for participation in participations:
            participation.left_on = datetime.today()
            participation.save()
        new_rel, created = Relationship.objects.get_or_create(
            source=profile, target_project=project)
        new_rel.deleted = True
    else:
        participation = Participation(user=profile, project=project)
        participation.save()
        new_rel, created = Relationship.objects.get_or_create(
            source=profile, target_project=project)
        new_rel.deleted = False
    new_rel.save()
    return http.HttpResponseRedirect(project.get_absolute_url())
开发者ID:LauraHilliger,项目名称:lernanta,代码行数:29,代码来源:views.py

示例5: accept_sign_up

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def accept_sign_up(request, slug, comment_id, as_organizer=False):
    page = get_object_or_404(Page, project__slug=slug, slug='sign-up')
    project = page.project
    answer = page.comments.get(pk=comment_id)
    organizing = project.organizers().filter(user=answer.author.user).exists()
    participating = project.participants().filter(user=answer.author.user).exists()
    if answer.reply_to or organizing or participating or request.method != 'POST':
        return HttpResponseForbidden(_("You can't see this page"))
    participation = Participation(project=project, user=answer.author, organizing=as_organizer)
    participation.save()
    new_rel = Relationship(source=answer.author, target_project=project)
    try:
        new_rel.save()
    except IntegrityError:
        pass
    accept_content = detail_description_content = render_to_string(
            "content/accept_sign_up_comment.html",
            {'as_organizer': as_organizer})
    accept_comment = PageComment(content=accept_content, 
        author = request.user.get_profile(), page = page, reply_to = answer, 
        abs_reply_to = answer)
    accept_comment.save()
    if as_organizer:
        messages.success(request, _('Organizer added!'))
    else:
        messages.success(request, _('Participant added!'))
    return HttpResponseRedirect(answer.get_absolute_url())
开发者ID:MJae,项目名称:lernanta,代码行数:29,代码来源:views.py

示例6: setUp

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
    def setUp(self):
        self.client = Client()
        self.locale = 'en'
        django_user = User(
            username=self.test_username,
            email=self.test_email,
        )
        self.user = create_profile(django_user)
        self.user.set_password(self.test_password)
        self.user.save()

        self.project = Project(name='Reply Project',
            short_description='This project is to test replies',
            long_description='No really, its good',
        )
        self.project.save()
        
        participation = Participation(project=self.project,
            user=self.user, organizing=True)
        participation.save()
        
        self.page = Page(author=self.user,
            project=self.project,
            title='task title',
            sub_header='Tagline',
            content='Content',
            index=2)
        self.page.save()

        self.comment = PageComment()
        self.comment.page_object = self.page
        self.comment.scope_object = self.project
        self.comment.author = self.user
        self.comment.content = "blah blah"
        self.comment.save()
开发者ID:Astalaseven,项目名称:lernanta,代码行数:37,代码来源:tests.py

示例7: clone

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
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,代码行数:62,代码来源:views.py

示例8: import_from_old_site

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
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,代码行数:62,代码来源:views.py

示例9: create

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
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,代码行数:60,代码来源:views.py

示例10: create

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
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,代码行数:56,代码来源:views.py

示例11: edit_participants_make_organizer

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def edit_participants_make_organizer(request, slug, username):
    participation = get_object_or_404(Participation, project__slug=slug, user__username=username, left_on__isnull=True)
    if participation.organizing or request.method != "POST":
        return http.HttpResponseForbidden(_("You can't make that person an organizer"))
    participation.left_on = datetime.datetime.now()
    participation.save()
    participation = Participation(user=participation.user, project=participation.project)
    participation.organizing = True
    participation.save()
    messages.success(request, _("The participant is now an organizer."))
    return http.HttpResponseRedirect(
        reverse("projects_edit_participants", kwargs=dict(slug=participation.project.slug))
    )
开发者ID:ajufrancis,项目名称:lernanta,代码行数:15,代码来源:views.py

示例12: create

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def create(request):
    user = request.user.get_profile()
    if request.method == 'POST':
        form = project_forms.CreateProjectForm(request.POST)
        if form.is_valid():
            project = form.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_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.create()
            messages.success(request,
                _('The %s has been created.') % project.kind.lower())
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            msg = _("Problem creating the study group, course, ...")
            messages.error(request, msg)
    else:
        form = project_forms.CreateProjectForm()
    return render_to_response('projects/project_edit_summary.html', {
        'form': form, 'new_tab': True,
    }, context_instance=RequestContext(request))
开发者ID:vtamara,项目名称:lernanta,代码行数:49,代码来源:views.py

示例13: accept

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
 def accept(self, as_organizer=False, reviewer=None):
     if not reviewer:
         reviewer = self.sign_up.author
     is_organizing = self.project.organizers().filter(
         user=self.author).exists()
     is_participating = self.project.participants().filter(
         user=self.author).exists()
     if not is_organizing and not is_participating:
         participation = Participation(project=self.project,
             user=self.author, organizing=as_organizer)
         participation.save()
     accept_content = render_to_string(
         "signups/accept_sign_up_comment.html",
         {'as_organizer': as_organizer})
     accept_comment = PageComment(content=accept_content,
         author=reviewer, page_object=self, scope_object=self.project)
     accept_comment.save()
     self.accepted = True
     self.save()
开发者ID:Inkbug,项目名称:lernanta,代码行数:21,代码来源:models.py

示例14: edit_participants_organizer_delete

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
def edit_participants_organizer_delete(request, slug, username):
    """ remove username as an organizer for the course """
    project = get_object_or_404(Project, slug=slug)
    profile = get_object_or_404(UserProfile, username=username)
    participation = get_object_or_404(Participation, project=project,
        user=profile.user, left_on__isnull=True)
    organizers = project.organizers()
    # check that this isn't the only organizer
    if len(organizers) == 1:
        messages.error(request, _('You cannot delete the only organizer'))
    elif request.method != 'POST':
        raise http.Http404
    else:
        participation.left_on = datetime.datetime.now()
        participation.save()
        participation = Participation(user=profile, project=project)
        participation.save()
        messages.success(request, _('The organizer in now only a participant.'))
    return http.HttpResponseRedirect(reverse('projects_edit_participants',
        kwargs=dict(slug=participation.project.slug)))
开发者ID:Acidburn0zzz,项目名称:lernanta,代码行数:22,代码来源:views.py

示例15: setUp

# 需要导入模块: from projects.models import Participation [as 别名]
# 或者: from projects.models.Participation import save [as 别名]
    def setUp(self):
        self.client = Client()
        self.locale = "en"
        django_user = User(username=self.test_username, email=self.test_email)
        self.user = create_profile(django_user)
        self.user.set_password(self.test_password)
        self.user.save()

        self.project = Project(
            name="Reply Project",
            short_description="This project is to test replies",
            long_description="No really, its good",
        )
        self.project.save()

        participation = Participation(project=self.project, user=self.user, organizing=True)
        participation.save()

        self.page = Page(
            author=self.user, project=self.project, title="task title", sub_header="Tagline", content="Content", index=2
        )
        self.page.save()
开发者ID:josmas,项目名称:lernanta,代码行数:24,代码来源:tests.py


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