예제 #1
0
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']
            #CS - too much logic in view
            project = Project(name=base_project.name,
                category=base_project.category,
                other=base_project.other,
                other_description=base_project.other_description,
                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
            base_sign_up = base_project.sign_up.get()
            sign_up = Signup(public=base_sign_up.public,
                between_participants=base_sign_up.between_participants,
                author_id=user.id, project_id=project.id)
            sign_up.save()
            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_create_tasks', 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))
예제 #2
0
def clone(request):
    user = request.user.get_profile()
    if 'school' in request.GET:
        try:
            school = School.objects.get(slug=request.GET['school'])
        except School.DoesNotExist:
            return http.HttpResponseRedirect(reverse('projects_clone'))
    else:
        school = None
    if request.method == 'POST':
        form = project_forms.CloneProjectForm(school, request.POST)
        if form.is_valid():
            base_project = form.cleaned_data['project']
            project = Project(name=base_project.name,
                short_description=base_project.short_description,
                long_description=base_project.long_description,
                school=base_project.school, clone_of=base_project)
            project.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 = 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()
            messages.success(request, _('The study group has been cloned.'))
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            messages.error(request,
                _("There was a problem cloning the study group."))
    else:
        form = project_forms.CloneProjectForm(school)
    return render_to_response('projects/project_clone.html', {
        'form': form, 'clone_tab': True, 'school': school,
    }, context_instance=RequestContext(request))