Esempio n. 1
0
 def approve(self, approved_by):
     created_person, created_account = \
         super(ProjectApplication, self).approve(approved_by)
     assert self.applicant is not None
     assert self.content_type.model == "person"
     person = self.applicant
     if self.project is None:
         assert self.institute is not None
         from karaage.projects.utils import get_new_pid
         project = Project(
             pid=self.pid or get_new_pid(self.institute),
             name=self.name,
             description=self.description,
             institute=self.institute,
             additional_req=self.additional_req,
             start_date=datetime.datetime.today(),
             end_date=datetime.datetime.today()
             + datetime.timedelta(days=365),
             )
         project.save()
         for mc in self.machine_categories.all():
             project.projectquota_set.create(machine_category=mc)
         project.activate(approved_by)
         self.project = project
         self.save()
     if self.make_leader:
         self.project.leaders.add(person)
     if self.needs_account:
         for pc in self.project.projectquota_set.all():
             if not person.has_account(pc.machine_category):
                 Account.create(person, self.project, pc.machine_category)
                 created_account = True
     self.project.group.members.add(person)
     return created_person, created_account
Esempio n. 2
0
 def approve(self, approved_by):
     created_person, created_account = \
         super(ProjectApplication, self).approve(approved_by)
     assert self.applicant is not None
     assert self.content_type.model == "person"
     person = self.applicant
     if self.project is None:
         assert self.institute is not None
         from karaage.projects.utils import get_new_pid
         project = Project(
             pid=self.pid or get_new_pid(self.institute),
             name=self.name,
             description=self.description,
             institute=self.institute,
             additional_req=self.additional_req,
             start_date=datetime.datetime.today(),
             end_date=datetime.datetime.today() +
             datetime.timedelta(days=365),
         )
         project.save()
         project.activate(approved_by)
         self.project = project
         self.save()
     if self.make_leader:
         self.project.leaders.add(person)
     if self.needs_account:
         if not person.has_account():
             log.add(self.application_ptr, 'Created account.')
             Account.create(person, self.project)
             created_account = True
         else:
             log.change(self.application_ptr, 'Account already exists')
     self.project.group.members.add(person)
     return created_person, created_account
Esempio n. 3
0
 def approve(self, approved_by):
     created_person, created_account = \
         super(ProjectApplication, self).approve(approved_by)
     assert self.applicant is not None
     assert self.content_type.model == "person"
     person = self.applicant
     if self.project is None:
         assert self.institute is not None
         from karaage.projects.utils import get_new_pid
         project = Project(
             pid=self.pid or get_new_pid(self.institute),
             name=self.name,
             description=self.description,
             institute=self.institute,
             additional_req=self.additional_req,
             start_date=datetime.datetime.today(),
             end_date=datetime.datetime.today()
             + datetime.timedelta(days=365),
         )
         project.save()
         for mc in self.machine_categories.all():
             project.projectquota_set.create(machine_category=mc)
         project.activate(approved_by)
         self.project = project
         self.save()
     if self.make_leader:
         self.project.add_update_project_members(
             person, is_project_leader=True,
         )
     if self.needs_account:
         found_pc = False
         for pc in self.project.projectquota_set.all():
             found_pc = True
             if not person.has_account(pc.machine_category):
                 log.add(
                     self.application_ptr,
                     'Created account on machine category %s'
                     % pc.machine_category)
                 Account.create(person, self.project, pc.machine_category)
                 created_account = True
             else:
                 log.change(
                     self.application_ptr,
                     'Account on machine category %s already exists'
                     % pc.machine_category)
         if not found_pc:
             log.change(
                 self.application_ptr,
                 'No project quotas found; no accounts created '
                 'despite being requested')
     self.project.group.members.add(person)
     return created_person, created_account
Esempio n. 4
0
 def approve(self, approved_by):
     created_person, created_account = \
         super(ProjectApplication, self).approve(approved_by)
     assert self.applicant is not None
     assert self.content_type.model == "person"
     person = self.applicant
     if self.project is None:
         assert self.institute is not None
         from karaage.projects.utils import get_new_pid
         project = Project(
             pid=self.pid or get_new_pid(self.institute),
             name=self.name,
             description=self.description,
             institute=self.institute,
             additional_req=self.additional_req,
             start_date=datetime.datetime.today(),
             end_date=datetime.datetime.today() +
             datetime.timedelta(days=365),
         )
         project.save()
         for mc in self.machine_categories.all():
             project.projectquota_set.create(machine_category=mc)
         project.activate(approved_by)
         self.project = project
         self.save()
     if self.make_leader:
         self.project.leaders.add(person)
     if self.needs_account:
         found_pc = False
         for pc in self.project.projectquota_set.all():
             found_pc = True
             if not person.has_account(pc.machine_category):
                 log.add(
                     self.application_ptr,
                     'Created account on machine category %s' %
                     pc.machine_category)
                 Account.create(person, self.project, pc.machine_category)
                 created_account = True
             else:
                 log.change(
                     self.application_ptr,
                     'Account on machine category %s already exists' %
                     pc.machine_category)
         if not found_pc:
             log.change(
                 self.application_ptr,
                 'No project quotas found; no accounts created '
                 'despite being requested')
     self.project.group.members.add(person)
     return created_person, created_account
Esempio n. 5
0
def add_edit_project(request, project_id=None):

    if project_id is None:
        project = None
        old_pid = None
        flag = 1
    else:
        project = get_object_or_404(Project, id=project_id)
        old_pid = project.pid
        flag = 2

    if util.is_admin(request):
        # JH add initial pid
        initial_pid = cutil.getDefaultProjectPid()
        form = ProjectForm(instance=project,
                           data=request.POST or None,
                           pid_initial=initial_pid)
    else:
        if not project.can_edit(request):
            return HttpResponseForbidden('<h1>Access Denied</h1>')
        form = UserProjectForm(instance=project, data=request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change.
                project.pid = old_pid
            elif not project.pid:
                # if project was being created, did the user give a project_id
                # we should use? If not, then we have to generate one
                # ourselves.
                project.pid = get_new_pid(project.institute)
            project.save()
            approved_by = request.user
            project.activate(approved_by)
            form.save_m2m()
            if flag == 1:
                messages.success(request,
                                 "Project '%s' created succesfully" % project)
            else:
                messages.success(request,
                                 "Project '%s' edited succesfully" % project)

            return HttpResponseRedirect(project.get_absolute_url())

    return render_to_response('karaage/projects/project_form.html',
                              locals(),
                              context_instance=RequestContext(request))
Esempio n. 6
0
def add_edit_project(request, project_id=None):

    if project_id is None:
        project = None
        old_pid = None
        flag = 1
    else:
        project = get_object_or_404(Project, id=project_id)
        old_pid = project.pid
        flag = 2

    if util.is_admin(request):
# JH add initial pid
        initial_pid = cutil.getDefaultProjectPid()
        form = ProjectForm(instance=project, data=request.POST or None, pid_initial = initial_pid)
    else:
        if not project.can_edit(request):
            return HttpResponseForbidden('<h1>Access Denied</h1>')
        form = UserProjectForm(instance=project, data=request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change.
                project.pid = old_pid
            elif not project.pid:
                # if project was being created, did the user give a project_id
                # we should use? If not, then we have to generate one
                # ourselves.
                project.pid = get_new_pid(project.institute)
            project.save()
            approved_by = request.user
            project.activate(approved_by)
            form.save_m2m()
            if flag == 1:
                messages.success(
                    request, "Project '%s' created succesfully" % project)
            else:
                messages.success(
                    request, "Project '%s' edited succesfully" % project)

            return HttpResponseRedirect(project.get_absolute_url())

    return render_to_response(
        'karaage/projects/project_form.html',
        locals(),
        context_instance=RequestContext(request))
Esempio n. 7
0
 def approve(self, approved_by):
     created_person, created_account = \
         super(ProjectApplication, self).approve(approved_by)
     assert self.applicant is not None
     assert self.content_type.model == "person"
     person = self.applicant
     if self.project is None:
         assert self.institute is not None
         from karaage.projects.utils import get_new_pid
         project = Project(
             pid=self.pid or get_new_pid(self.institute),
             name=self.name,
             description=self.description,
             institute=self.institute,
             additional_req=self.additional_req,
             start_date=datetime.datetime.today(),
             end_date=datetime.datetime.today() +
             datetime.timedelta(days=365),
         )
         project.save()
         project.activate(approved_by)
         self.project = project
         self.save()
     if self.make_leader:
         self.project.leaders.add(person)
     if self.needs_account:
         if not person.has_account():
             log.add(
                 self.application_ptr,
                 'Created account.'
             )
             Account.create(person, self.project)
             created_account = True
         else:
             log.change(
                 self.application_ptr,
                 'Account already exists'
             )
     self.project.group.members.add(person)
     return created_person, created_account
Esempio n. 8
0
def add_edit_project(request, project_id=None):

    if project_id is None:
        project = None
        flag = 1
    else:
        project = get_object_or_404(Project, pid=project_id)
        flag = 2

    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)

        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change, so we
                # should always use the value supplied on the URL.
                project.pid = project_id
            elif not project.pid:
                # if project was being created, did the user give a project_id
                # we should use? If not, then we have to generate one
                # ourselves.
                project.pid = get_new_pid(project.institute)
            project.save()
            approved_by = request.user
            project.activate(approved_by)
            form.save_m2m()
            if flag == 1:
                messages.success(request, "Project '%s' created succesfully" % project)
                log(None, project, 1, 'Created')
            else:
                messages.success(request, "Project '%s' edited succesfully" % project)
                log(None, project, 2, 'Edited')

            return HttpResponseRedirect(project.get_absolute_url())
    else:
        form = ProjectForm(instance=project)

    return render_to_response('projects/project_form.html', locals(), context_instance=RequestContext(request))
Esempio n. 9
0
 def approve(self, pid=None):
     person = super(ProjectApplication, self).approve()
     from karaage.projects.utils import add_user_to_project, get_new_pid
     project = Project(
         pid=pid or get_new_pid(self.institute),
         name=self.name,
         description=self.description,
         institute=self.institute,
         additional_req=self.additional_req,
         start_date=datetime.datetime.today(),
         end_date=datetime.datetime.today() + datetime.timedelta(days=365),
         )
     project.machine_category = MachineCategory.objects.get_default()
     project.save()
     project.leaders.add(person)
     for mc in self.machine_categories.all():
         project.machine_categories.add(mc)
     project.activate()
     if self.needs_account:
         add_user_to_project(person, project)
     self.project = project
     self.save()
     return project
Esempio n. 10
0
def add_edit_project(request, project_id=None):

    kwargs={}

    if project_id is None:
        project = None
        flag = 1
    else:
        kwargs['instance'] = project = get_object_or_404(Project, pid=project_id)
        kwargs['initial'] = {
            'leaders': list(project.leaders.values_list('pk', flat=True)),
        }
        flag = 2

    if request.method == 'POST':
        kwargs['data'] = request.POST

    if util.is_admin(request):
        form = ProjectForm(**kwargs)
    else:
        if not project.can_edit(request):
            return HttpResponseForbidden('<h1>Access Denied</h1>')
        form = UserProjectForm(**kwargs)

    if request.method == 'POST':
        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change, so we
                # should always use the value supplied on the URL.
                project.pid = project_id
            elif not project.pid:
                # if project was being created, did the user give a project_id
                # we should use? If not, then we have to generate one
                # ourselves.
                project.pid = get_new_pid(project.institute)
            project.save()
            approved_by = request.user
            project.activate(approved_by)
            project.projectmembership_set.filter(
                is_project_leader=True,
            ).exclude(
                person__in=form.cleaned_data['leaders'],
            ).update(
                is_project_leader=False,
            )
            project.add_update_project_members(
                is_project_leader=True,
                *form.cleaned_data['leaders']
            )
            form.save_m2m()
            if flag == 1:
                messages.success(
                    request, "Project '%s' created succesfully" % project)
            else:
                messages.success(
                    request, "Project '%s' edited succesfully" % project)

            return HttpResponseRedirect(project.get_absolute_url())

    return render_to_response(
        'karaage/projects/project_form.html',
        locals(),
        context_instance=RequestContext(request))