Esempio n. 1
0
def userAdd(request, project_id):
    try:
        project = Project.objects.get(id__exact=project_id)
    except:
        raise Http404

    if request.method == "POST":
        form = NewUserForm(request.POST)
        if form.data['new_users'] != '':
            for username in re.split('[;,]+', form.data['new_users']):

                if (Membership.objects.filter(
                        user__username__exact=username).filter(
                            project__exact=project_id).count() == 0):

                    m = Membership(
                        user=MossaicUser.objects.get(username__exact=username),
                        project=Project.objects.get(id__exact=project_id))
                    m.save()

        return HttpResponseRedirect("/projects/%s/users" % project_id)
    else:
        form = NewUserForm()
        context = RequestContext(request, {
            'project': project,
            'form': form,
            'request': request,
        })
        return render_to_response('projectUserAdd.html',
                                  context,
                                  context_instance=RequestContext(request))
Esempio n. 2
0
def userAdd(request,project_id):
	try:
		project=Project.objects.get(id__exact=project_id)
	except:
		raise Http404
	
	if request.method=="POST":
		form = NewUserForm(request.POST)
		if form.data['new_users'] != '':
			for username in re.split('[;,]+',form.data['new_users']):
			
				if (Membership.objects.filter(user__username__exact=username).
				filter(project__exact=project_id).count() == 0):
				
					m=Membership(
						user=MossaicUser.objects.get(username__exact=username),
						project=Project.objects.get(id__exact=project_id)
					)
					m.save()
		
		return HttpResponseRedirect("/projects/%s/users" % project_id )
	else:
		form = NewUserForm()
		context = RequestContext(request,{
			'project': project,
			'form': form,
			'request': request,
		})
		return render_to_response('projectUserAdd.html',context,context_instance=RequestContext(request))
Esempio n. 3
0
def add_user_to_project(user, project):
    # Add the user to the project members.
    new_member = Membership(user=user, project=project, confirmed=True)
    new_member.save()

    # Notify the member about being added.
    Membership.new_member_added.send(
        sender="Projects", membership_id=new_member.id)
Esempio n. 4
0
def request_invite(request, project_id):
    project = Project.objects.get(pk=project_id)

    try:
        # Check to see if the user already exists as a member.
        Membership.objects.get(
            user=request.user, project=project)

        context = {
            'title': 'Cannot complete the request invite.',
            'message': 'We failed to make a request invite on your behalf '
            + 'because you either have already sent an invite request or are a '
            + 'current member.'
        }
        return APIUtilities._api_failure(context)

    except Membership.DoesNotExist:
        if project.visibility != 'public':
            new_membership = Membership(
                user=request.user, project=project, confirmed=False)
            new_membership.save()

            # Create a notification for the admins about this request.
            Membership.new_invite_request.send(
                sender="Projects", membership_id=new_membership.id, request=request)
        else:
            new_membership = Membership(
                user=request.user, project=project, confirmed=True)
            new_membership.save()

            # Create a notification for the admins about this membership.
            Membership.new_member.send(
                sender="Projects", membership_id=new_membership.id, request=request)

        return APIUtilities._api_success()
Esempio n. 5
0
def new_project(request):
    if not request.user.is_authenticated():
        return redirect('/login/?source=%s' % request.path)

    # If a form submission was made
    if request.method == "POST":
        from forms import ProjectForm

        new_project_form = ProjectForm(request.POST, request.user)

        if new_project_form.is_valid():
            try:
                # Try creating a new project with the form inputs
                new_project = new_project_form.save()

                # Add the creator to the project members.
                project_creator = Membership(
                    user=request.user, project=new_project, confirmed=True)
                project_creator.save()

                # Create a new root collection for the project
                from django.template.defaultfilters import slugify
                title = request.POST.get('title')

                from oer.models import Collection
                root_collection = Collection(
                    title=title + "_root",
                    host=new_project,
                    visibility=request.POST.get('visibility'),
                    slug=slugify(title),
                    creator=request.user
                )
                root_collection.save()
                new_project.collection = root_collection

                new_project.save()

                # Set default cover pic if not uploaded by user
                if not new_project.cover_pic:
                    _set_cover_picture(new_project, new_project_form)


                # Add a default category in the project.
                group_category = GroupCategory(
                    parent=new_project,
                    title='General',
                    slug='general'
                )
                group_category.save()

                Project.project_created.send(
                    sender="Project", project=new_project, creator=request.user)

                return redirect(
                    'projects:project_home', project_slug=new_project.slug)

            except:
                print "Could not create new project"

        else:
            print new_project_form.errors
            print "The form had errors"

    context = {
        'title': _(settings.STRINGS['projects']['NEW_PROJECT_TITLE'])
    }
    return render(request, 'new-project.html', context)