Beispiel #1
0
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))
Beispiel #2
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"]
            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_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)
    )
Beispiel #3
0
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))
Beispiel #4
0
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))
Beispiel #5
0
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))
Beispiel #6
0
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"]
            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", {}
                )
            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)
    )
Beispiel #7
0
def create(request):
    user = request.user.get_profile()
    if request.method == 'POST':
        form = project_forms.ProjectForm(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)
            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_show', kwargs={
                    'slug': project.slug,
                }))
        else:
            msg = _("Problem creating the study group, course, ...")
            messages.error(request, msg)
    else:
        form = project_forms.ProjectForm()
    return render_to_response('projects/project_edit_summary.html', {
        'form': form,
        'new_tab': True,
    },
                              context_instance=RequestContext(request))
Beispiel #8
0
def create(request):
    user = request.user.get_profile()
    if request.method == 'POST':
        form = project_forms.ProjectForm(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",
                {'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_show', kwargs={
                'slug': project.slug,
            }))
        else:
            msg = _("Problem creating the study group, course, ...")
            messages.error(request, msg)
    else:
        form = project_forms.ProjectForm()
    return render_to_response('projects/project_edit_summary.html', {
        'form': form, 'new_tab': True,
    }, context_instance=RequestContext(request))
Beispiel #9
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))