示例#1
0
文件: tests.py 项目: JiaFeiX/lernanta
 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()
示例#2
0
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))
示例#3
0
 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()
示例#4
0
文件: tests.py 项目: mkcode/lernanta
    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()
示例#5
0
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())
示例#6
0
    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()
示例#7
0
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,
        'is_challenge': (project.category == project.CHALLENGE),
    }, context_instance=RequestContext(request))
示例#8
0
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())
示例#9
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))
示例#10
0
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))
示例#11
0
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']
            organizing = form.cleaned_data['organizer']
            participation = Participation(project=project, user=user, organizing=organizing)
            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().order_by('joined_on'),
        'participants_tab': True,
    }, context_instance=RequestContext(request))
示例#12
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))
示例#13
0
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),
    )
示例#14
0
文件: views.py 项目: vtamara/lernanta
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))
示例#15
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)
    )
示例#16
0
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))
示例#17
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))
示例#18
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))
示例#19
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)
    )
示例#20
0
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))
示例#21
0
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))
示例#22
0
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))
    )
示例#23
0
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)))
示例#24
0
文件: views.py 项目: vtamara/lernanta
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))
示例#25
0
 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()
示例#26
0
文件: models.py 项目: Inkbug/lernanta
 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()
示例#27
0
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)))
示例#28
0
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)))
示例#29
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)
    )
示例#30
0
文件: tests.py 项目: josmas/lernanta
    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()
示例#31
0
def accept_sign_up(request, slug, comment_id):
    page = get_object_or_404(Page, project__slug=slug, slug='sign-up')
    project = page.project
    user = request.user.get_profile()
    answer = page.comments.get(pk=comment_id)
    if answer.reply_to or answer.author == project.created_by or request.method != 'POST':
        return HttpResponseForbidden()
    try:
        participation = answer.participation
        return HttpResponseForbidden()
    except Participation.DoesNotExist:
        pass
    try:
        participation = project.participants().get(user=answer.author)
        if participation.sign_up:
            participation.left_on = datetime.datetime.now()
            participation.save()
            raise Participation.DoesNotExist
        else:
            participation.sign_up = answer
    except Participation.DoesNotExist:
        participation = Participation(project= project, user=answer.author, sign_up=answer)
    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",
            {})
    accept_comment = PageComment(content=accept_content, author=user,
        page=page, reply_to=answer, abs_reply_to=answer)
    accept_comment.save()
    messages.success(request, _('Participant added!'))
    return HttpResponseRedirect(answer.get_absolute_url())
示例#32
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))
示例#33
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))
示例#34
0
def import_from_old_site(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.ImportProjectForm(school, request.POST)
        if form.is_valid():
            course = form.cleaned_data['course']
            project = Project(name=course['name'],
                short_description= course['short_description'],
                long_description=course['long_description'],
                school=course['school'], imported_from=course['slug'])
            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
            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_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()
            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()
            messages.success(request, _('The study group has been imported.'))
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            messages.error(request,
                _("There was a problem importing the study group."))
    else:
        form = project_forms.ImportProjectForm(school)
    return render_to_response('projects/project_import.html', {
        'form': form, 'import_tab': True, 'school': school,
    }, context_instance=RequestContext(request))
示例#35
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))
示例#36
0
def import_from_old_site(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.ImportProjectForm(school, request.POST)
        if form.is_valid():
            course = form.cleaned_data['course']
            project = Project(name=course['name'],
                short_description= course['short_description'],
                long_description=course['long_description'],
                school=course['school'], imported_from=course['slug'])
            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
            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_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()
            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()
            messages.success(request, _('The study group has been imported.'))
            return http.HttpResponseRedirect(reverse('projects_show', kwargs={
                'slug': project.slug,
            }))
        else:
            messages.error(request,
                _("There was a problem importing the study group."))
    else:
        form = project_forms.ImportProjectForm(school)
    return render_to_response('projects/project_import.html', {
        'form': form, 'import_tab': True, 'school': school,
    }, context_instance=RequestContext(request))