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
def approve(self, approved_by): created_person, created_account = \ super(ProjectApplication, self).approve(approved_by) assert self.existing_person is not None person = self.existing_person 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.activate( approved_by) # Activate has implied call to save(). 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
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
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
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
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
def project_application_approve(request, token): """ Must manually set fairshare, disk and e-mail user. """ project_application = get_object_or_404(ProjectApplication, secret_token=token) if project_application.state in [ ProjectApplication.COMPLETE, ProjectApplication.ARCHIVED ]: messages.error(request, "This application has already been approved") return HttpResponseRedirect(request.META.get('HTTP_REFERER')) if project_application.state == ProjectApplication.DECLINED: messages.error(request, "This application was delined") return HttpResponseRedirect(request.META.get('HTTP_REFERER')) if project_application.state != ProjectApplication.WAITING_FOR_ADMIN: messages.error(request, "Only submitted applications can be approved") return HttpResponseRedirect(request.META.get('HTTP_REFERER')) # by default lookup requested associated project, unless admin looks up # different project associated = None if request.method == 'POST': post = request.POST.copy() if 'proj_try' in post.keys(): associated = post['proj_try'] initial = { 'proj_try': '', 'proj_title': project_application.title, 'proj_desc': project_application.summary, 'host': '', 'faculty': None, 'school': None } try: proj_try = Project.objects.get(pid=associated) initial['proj_try'] = proj_try.pid except Project.DoesNotExist: proj_try = None proj_ids = Project.objects.values_list('pid', flat=True) queryset = ProjectApplicationMember.objects.filter( project_application=project_application) # should only be one of supervisor and applicant supervisor = queryset.get(is_supervisor=True) applicant = queryset.get(is_applicant=True) # any other leaders leaders = queryset.filter(project_application=project_application, is_leader=True, is_supervisor=False, is_applicant=False) members = [supervisor] if applicant != supervisor: members.append(applicant) for leader in leaders: members.append(leader) # Institute must exist before Approval try: host = Institute.objects.get(name__exact=supervisor.institute) initial['host'] = host except Institute.DoesNotExist: messages.error(request, "Fix/Create the host institute before Approving") return HttpResponseRedirect(request.META.get('HTTP_REFERER')) # pass list to javascript inst_fac_sch = ProjectApplicationFaculty.objects.all() all_choices = {} for item in inst_fac_sch: all_choices.setdefault(item.institute.id, {}).setdefault(item.faculty, []).append(item.school) # Add data entered for supervisor inst = Institute.objects.get(name__iexact=supervisor.institute).id fac = supervisor.faculty sch = supervisor.department initial['faculty'] = fac initial['school'] = sch if ((inst not in all_choices) or (fac not in all_choices[inst]) or (sch not in all_choices[inst][fac])): all_choices.setdefault(inst, {}).setdefault(fac, []).append(sch) all_choices = json.dumps(all_choices) if request.method == 'POST': form = ProjectApplicationApproveForm(request.POST, initial=initial) if form.is_valid() and 'approve' in request: data = form.cleaned_data new_text = u'\nProject Application approved on: %s\n' % datetime.date.today( ).strftime('%d, %b %Y') new_text += u'Approved by %s' % request.user new_text += u'Application number: %s (%s)\n' % ( project_application.id, request.build_absolute_uri( reverse('view_project_application', args=[project_application.id]))) new_text += u'Supervisor: %s\n' % supervisor.get_full_name() new_text += u'Host: %s, %s, %s\n' % ( data['host'].name, data['faculty'], data['school']) proj_try_data = data['proj_try'].upper() try: project = Project.objects.get(pid=proj_try_data) created = False ## TODO: need to check institute hasn't changed ## Warn, confirm change of host!!! prev_leaders = ', '.join([ leader.get_full_name() for leader in project.leaders.all() ]) new_text += u'Previous Title: %s\n' % project.name new_text += u'Previous Leaders: %s\n' % prev_leaders new_text += u'Previous Host: %s\n' % project.institute new_text += u'Previous Description: %s\n\n' % project.description except (Project.DoesNotExist, Project.IntegrityError): project = Project(pid=proj_try_data, institute=data['host']) project.save() # add approving admin as leader of new project project.leaders.add(request.user) created = True project.additional_req = '%s%s' % (new_text, (project.additional_req or '')) project.name = data['proj_title'] project.description = data['proj_desc'] project.institute = data['host'] project.save() ProjectQuota.objects.get_or_create( project=project, machine_category=MachineCategory.objects.get_default()) project.activate(request.user) project.save() project_application.project = project project_application.host_institute = data[ 'host'].name ## save name for archiving project_application.host_faculty = data['faculty'] project_application.host_school = data['school'] project_application.state = ProjectApplication.COMPLETE project_application.save() # save faculty and school in case they are new ProjectApplicationFaculty.objects.get_or_create( institute=data['host'], faculty=data['faculty'], school=data['school']) log.add(project_application, 'Approved by %s' % request.user) messages.info(request, "%s approved" % project_application) return HttpResponseRedirect(reverse('project_application_list')) else: form = ProjectApplicationApproveForm(initial=initial) return render( request, 'project_application/admin_confirm_approve.html', { 'project_application': project_application, 'proj_try': proj_try, 'host': host, 'faculty': fac, 'school': sch, 'all_choices': all_choices, 'members': members, 'proj_ids': proj_ids, 'form': form }, )