class VenturesRoles(Ventures, Base): template_name = 'ui/ventures-roles.html' def __init__(self, *args, **kwargs): super(VenturesRoles, self).__init__(*args, **kwargs) self.form = None def post(self, *args, **kwargs): self.set_venture() has_perm = self.request.user.get_profile().has_perm if not has_perm( Perm.edit_ventures_roles, self.venture if self.venture and self.venture != '*' else None): messages.error(self.request, "No permission to edit that role.") else: self.form = RolePropertyForm(self.request.POST) if self.form.is_valid(): self.form.save() messages.success(self.request, "Property created.") return HttpResponseRedirect(self.request.path) else: messages.error(self.request, "Correct the errors.") return self.get(*args, **kwargs) def get(self, *args, **kwargs): self.set_venture() role_id = self.kwargs.get('role') if role_id: self.role = get_object_or_404(VentureRole, id=role_id) else: self.role = None if self.form is None: if self.role: self.form = RolePropertyForm(initial={'role': role_id}) else: self.form = RolePropertyForm( initial={'venture': self.venture.id}) return super(VenturesRoles, self).get(*args, **kwargs) def get_context_data(self, **kwargs): ret = super(VenturesRoles, self).get_context_data(**kwargs) has_perm = self.request.user.get_profile().has_perm ret.update({ 'items': (self.venture.venturerole_set.all() if self.venture and self.venture != '*' else []), 'role': self.role, 'venture': self.venture, 'form': self.form, 'editable': has_perm( Perm.edit_ventures_roles, self.venture if self.venture and self.venture != '*' else None), }) return ret
def get(self, *args, **kwargs): role_id = self.kwargs.get('role') if role_id: self.role = get_object_or_404(VentureRole, id=role_id) else: self.role = None if self.form is None: self.form = RolePropertyForm(initial={'role': role_id}) return super(VenturesRoles, self).get(*args, **kwargs)
def get(self, *args, **kwargs): self.set_venture() role_id = self.kwargs.get('role') if role_id: self.role = get_object_or_404(VentureRole, id=role_id) else: self.role = None if self.form is None: if self.role: self.form = RolePropertyForm(initial={'role': role_id}) else: self.form = RolePropertyForm(initial={'venture': self.venture.id}) return super(VenturesRoles, self).get(*args, **kwargs)
class VenturesRoles(Ventures, Base): template_name = 'ui/ventures-roles.html' def __init__(self, *args, **kwargs): super(VenturesRoles, self).__init__(*args, **kwargs) self.form = None def post(self, *args, **kwargs): self.set_venture() has_perm = self.request.user.get_profile().has_perm if not has_perm(Perm.edit_ventures_roles, self.venture if self.venture and self.venture != '*' else None): messages.error(self.request, "No permission to edit that role.") else: self.form = RolePropertyForm(self.request.POST) if self.form.is_valid(): self.form.save() messages.success(self.request, "Property created.") return HttpResponseRedirect(self.request.path) else: messages.error(self.request, "Correct the errors.") return self.get(*args, **kwargs) def get(self, *args, **kwargs): self.set_venture() role_id = self.kwargs.get('role') if role_id: self.role = get_object_or_404(VentureRole, id=role_id) else: self.role = None if self.form is None: if self.role: self.form = RolePropertyForm(initial={'role': role_id}) else: self.form = RolePropertyForm( initial={'venture': self.venture.id}) return super(VenturesRoles, self).get(*args, **kwargs) def get_context_data(self, **kwargs): ret = super(VenturesRoles, self).get_context_data(**kwargs) has_perm = self.request.user.get_profile().has_perm ret.update({ 'items': (self.venture.venturerole_set.all() if self.venture and self.venture != '*' else []), 'role': self.role, 'venture': self.venture, 'form': self.form, 'editable': has_perm(Perm.edit_ventures_roles, self.venture if self.venture and self.venture != '*' else None), }) return ret
def post(self, *args, **kwargs): self.set_venture() has_perm = self.request.user.get_profile().has_perm if not has_perm(Perm.edit_ventures_roles, self.venture if self.venture and self.venture != '*' else None): messages.error(self.request, "No permission to edit that role.") else: self.form = RolePropertyForm(self.request.POST) if self.form.is_valid(): self.form.save() messages.success(self.request, "Property created.") return HttpResponseRedirect(self.request.path) else: messages.error(self.request, "Correct the errors.") return self.get(*args, **kwargs)
def get(self, *args, **kwargs): role_id = self.kwargs.get("role") if role_id: self.role = get_object_or_404(VentureRole, id=role_id) else: self.role = None if self.form is None: self.form = RolePropertyForm(initial={"role": role_id}) return super(VenturesRoles, self).get(*args, **kwargs)