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: 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.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() 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, 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 add_user_to_project(person, project): for pc in project.projectquota_set.all(): if not person.has_account(pc.machine_category): Account.create(person, project, pc.machine_category) project.group.members.add(person)
def add_user_to_project(person, project): if not person.has_account(): Account.create(person, project) project.group.members.add(person)
def add_edit_account(request, username=None, account_id=None): username_error = False if username is None: # Edit account = get_object_or_404(Account, pk=account_id) person = account.person username = account.username else: # Add person = get_object_or_404(Person, username=username) account = None if request.method == "POST": form = AccountForm(request.POST) if form.is_valid(): data = form.cleaned_data if account: # Edit account.machine_category = data["machine_category"] account.default_project = data["default_project"] account.save() messages.success(request, "User account for '%s' changed succesfully" % account.person) return HttpResponseRedirect(person.get_absolute_url()) else: # add try: project = data["default_project"] except: project = None machine_category = data["machine_category"] try: Account.objects.get( username__exact=username, machine_category=machine_category, date_deleted__isnull=True ) except Account.DoesNotExist: account = Account.create(person, project, machine_category) send_confirm_password_email(account.person) messages.success(request, "User account for '%s' created succesfully" % account.person) return HttpResponseRedirect(person.get_absolute_url()) username_error = True else: form = AccountForm() from django import forms form.initial["username"] = username if account: # Fill form with initial form.fields["default_project"] = forms.ModelChoiceField(queryset=person.projects.all()) form.initial = account.__dict__ form.initial["default_project"] = form.initial["default_project_id"] form.initial["machine_category"] = form.initial["machine_category_id"] return render_to_response( "machines/account_form.html", {"form": form, "person": person, "account": account, "username_error": username_error}, context_instance=RequestContext(request), )