def adduser(request, slug): project = get_object_or_404(Project, slug=slug) owner = project.owner members = project.projectmember_set.all() user = request.user if user in [member.user for member in members]: #this thing here member = members.get(user=user) level = member.level if request.POST: form = AddUserForm(request.POST) if form.is_valid(): #create new ProjectMember object bound to User (by email) #and to project (by current project) cd = form.cleaned_data email, level = cd['email'], cd['level'] user = User.objects.get(email=email) new_member = ProjectMember( project=project, user=user, level=level, ) new_member.save() #redirect to project detailed page return HttpResponseRedirect( reverse('project-detail', args=[project.slug])) else: form = AddUserForm() return render_to_response('adduser.html', locals(), context_instance=RequestContext(request))
def adduser(request, slug): project = get_object_or_404(Project, slug=slug) owner = project.owner members = project.projectmember_set.all() user = request.user if user in [member.user for member in members]: #this thing here member = members.get(user=user) level = member.level if request.POST: form = AddUserForm(request.POST) if form.is_valid(): #create new ProjectMember object bound to User (by email) #and to project (by current project) cd = form.cleaned_data email, level = cd['email'], cd['level'] user = User.objects.get(email=email) new_member = ProjectMember( project = project, user = user, level = level, ) new_member.save() #redirect to project detailed page return HttpResponseRedirect(reverse('project-detail', args=[project.slug])) else: form = AddUserForm() return render_to_response('adduser.html', locals(), context_instance=RequestContext(request))
def importer_save(import_data, user): dict = pickle.loads(import_data.complete_data.file.read()) for project in dict['projects']: # Can't try project.save() and catch IntegrityError is name/slug is # not unique. So do manual lookup instead. However, only do this when # project has not been saved before. if not project.id: if Project.objects.filter(name=project.name): project.name += '%s' % datetime.now().microsecond if Project.objects.filter(slug=project.slug): project.slug += '%s' % datetime.now().microsecond project.save() # in case project is being created, it needs to be saved before a user # can be aplied. If project allready exist and have the user, nothing # will happen doing add(user). if enviroment == 'pinax': if not project.user_is_member(user): project_member = ProjectMember(project=project, user=user) project.members.add(project_member) project_member.save() else: project.members.add(user) project.save() for task in dict['tasks']: task.group = task.group task.save() for tslice in dict['slices']: tslice.task = tslice.task tslice.save() import_data.delete()
def create(request, form_class=ProjectForm, template_name="projects/create.html"): project_form = form_class(request.POST or None) admin_organizations = Organization.getOrganizationsForUser( request.user ) # The user can create projects in organizations the user is an admin in. if project_form.is_valid(): project = project_form.save(commit=False) project.creator = request.user org_id = request.POST.get("organization", "none") organization = None if org_id != "none": organization = Organization.objects.filter(id=org_id)[0] creationAllowed = True if organization: creationAllowed = org_project_limit.increaseAllowed(organization=organization) else: creationAllowed = personal_project_limit.increaseAllowed(user=request.user) if creationAllowed: project.save() if organization != None: if ( organization in admin_organizations ): # make sure the specified organization is in the list of admin orgs, if not silently ignore it. addProjectToOrganization(project, organization) # We better make the user a member of their own project. project_member = ProjectMember(project=project, user=request.user) project.members.add(project_member) project_member.save() # And lets make the default backlog iteration with no start/end dates. default_iteration = Iteration(name="Backlog", detail="", default_iteration=True, project=project) project.iterations.add(default_iteration) default_iteration.save() request.user.message_set.create(message="Project Created") # Finished successfully creating a project, send the user to that page. return HttpResponseRedirect(project.get_absolute_url()) else: return HttpResponseRedirect(reverse("usage")) # If they got here from the organziation page, there will be an org get-param set stating what organization it was from. # we need that here so it's pre-selected in the form. organization = None if request.GET.get("org", "") != "": organization = Organization.objects.filter(id=request.GET.get("org", ""))[0] return render_to_response( template_name, {"project_form": project_form, "admin_organizations": admin_organizations, "organization": organization}, context_instance=RequestContext(request), )
def save(self, user): new_member = User.objects.get(username__exact=self.cleaned_data['recipient']) project_member = ProjectMember(project=self.project, user=new_member) project_member.save() self.project.members.add(project_member) if notification: notification.send(self.project.member_users.all(), "projects_new_member", {"new_member": new_member, "project": self.project}) notification.send([new_member], "projects_added_as_member", {"adder": user, "project": self.project}) user.message_set.create(message="added %s to project" % new_member)
def project(request, group_slug=None, form_class=ProjectUpdateForm, adduser_form_class=AddUserForm, template_name="projects/project.html"): project = get_object_or_404(Project, slug=group_slug) if not request.user.is_authenticated(): is_member = False else: is_member = project.user_is_member(request.user) action = request.POST.get("action") if request.user == project.creator and action == "update": project_form = form_class(request.POST, instance=project) if project_form.is_valid(): project = project_form.save() else: project_form = form_class(instance=project) if request.user == project.creator and action == "add": adduser_form = adduser_form_class(request.POST, project=project) if adduser_form.is_valid(): adduser_form.save(request.user) adduser_form = adduser_form_class(project=project) # clear form else: adduser_form = adduser_form_class(project=project) if action == "join": if not is_member: project_member = ProjectMember(project=project, user=request.user) project.members.add(project_member) project_member.save() request.user.message_set.create( message=_("You have joined the project %(project_name)s") % {"project_name": project.name}) is_member = True if notification: pass # @@@ no notification on joining yet else: request.user.message_set.create( message=_("You have already joined project %(project_name)s") % {"project_name": project.name}) if action == "leave": if is_member: project_member = ProjectMember.objects.get(project=project, user=request.user) project_member.delete() request.user.message_set.create(message="You have left the project %(project_name)s" % {"project_name": project.name}) is_member = False if notification: pass # @@@ no notification on departure yet else: request.user.message_set.create( message=_("You are not a member of project %(project_name)s") % {"project_name": project.name}) return render_to_response(template_name, { "project_form": project_form, "adduser_form": adduser_form, "project": project, "group": project, # @@@ this should be the only context var for the project "is_member": is_member, }, context_instance=RequestContext(request))
def create(request, form_class=ProjectForm, template_name="projects/create.html"): project_form = form_class(request.POST or None) admin_organizations = Organization.getOrganizationsForUser( request.user ) # The user can create projects in organizations the user is an admin in. if project_form.is_valid(): project = project_form.save(commit=False) project.creator = request.user org_id = request.POST.get("organization","none") organization = None if org_id != "none": organization = Organization.objects.filter( id=org_id )[0] creationAllowed = True if organization: creationAllowed = org_project_limit.increaseAllowed(organization=organization) else: creationAllowed = personal_project_limit.increaseAllowed(user=request.user) if creationAllowed: project.save() if organization != None: if organization in admin_organizations: # make sure the specified organization is in the list of admin orgs, if not silently ignore it. addProjectToOrganization(project, organization) # We better make the user a member of their own project. project_member = ProjectMember(project=project, user=request.user) project.members.add(project_member) project_member.save() # And lets make the default backlog iteration with no start/end dates. default_iteration = Iteration( name='Backlog', detail='', default_iteration=True, project=project) project.iterations.add(default_iteration) default_iteration.save() request.user.message_set.create(message="Project Created") # Finished successfully creating a project, send the user to that page. return HttpResponseRedirect(project.get_absolute_url()) else: return HttpResponseRedirect( reverse("usage") ) # If they got here from the organziation page, there will be an org get-param set stating what organization it was from. # we need that here so it's pre-selected in the form. organization = None if request.GET.get("org","") != "": organization = Organization.objects.filter(id=request.GET.get("org",""))[0] return render_to_response(template_name, { "project_form": project_form, "admin_organizations":admin_organizations, "organization":organization }, context_instance=RequestContext(request))
def save(self, user): new_member = User.objects.get(username__exact=self.cleaned_data["recipient"]) project_member = ProjectMember(project=self.project, user=new_member) project_member.save() self.project.members.add(project_member) if notification: notification.send(self.project.member_users.all(), "projects_new_member", { "new_member": new_member, "project": self.project }) notification.send([new_member], "projects_added_as_member", { "adder": user, "project": self.project }) return project_member
def create(request, form_class=ProjectForm, template_name="projects/create.html"): project_form = form_class(request.POST or None) if project_form.is_valid(): project = project_form.save(commit=False) project.creator = request.user project.save() project_member = ProjectMember(project=project, user=request.user) project.members.add(project_member) project_member.save() if notification: # @@@ might be worth having a shortcut for sending to all users notification.send(User.objects.all(), "projects_new_project", {"project": project}, queue=True) return HttpResponseRedirect(project.get_absolute_url()) return render_to_response(template_name, { "project_form": project_form, }, context_instance=RequestContext(request))
def create(request, form_class=ProjectForm, template_name="projects/create.html", parent_slug=None, bridge=None): parent_type = "" body_class = "projects" if bridge: try: parent = bridge.get_group(parent_slug) parent_type = parent._meta.verbose_name.title() body_class = parent._meta.verbose_name except ObjectDoesNotExist: raise Http404 else: parent = None #import pdb; pdb.set_trace() if parent: parent_base = bridge.group_base_template() else: parent_base = None if not request.user.is_authenticated(): is_member = False else: if parent: is_member = parent.user_is_member(request.user) else: is_member = True project_form = form_class(request.user, parent, request.POST or None) if project_form.is_valid(): #import pdb; pdb.set_trace() project = project_form.save(commit=False) project.creator = request.user project.group = parent project.save() project_member = ProjectMember(project=project, user=request.user) project.members.add(project_member) project_member.save() if notification: if parent: notify_list = parent.member_queryset() else: notify_list = User.objects.all() # @@@ notify_list = notify_list.exclude(id__exact=request.user.id) notification.send(notify_list, "projects_new_project", {"project": project}, queue=True) if parent: redirect_to = bridge.reverse("project_list", parent, "projects") else: redirect_to = reverse("project_list") return HttpResponseRedirect(redirect_to) #return HttpResponseRedirect(project.get_absolute_url()) return render_to_response(template_name, { "project_form": project_form, "parent": parent, "parent_type": parent_type, "is_member": is_member, "parent_base": parent_base, "body_class": body_class, }, context_instance=RequestContext(request))