def form_valid(self, form): user = form.save(commit=False) user.created_by = self.request.user.username or 'System' user.save() if current_org and current_org.is_real(): user.related_user_orgs.add(current_org.id) post_user_create.send(self.__class__, user=user) return super().form_valid(form)
def role_display(self): if not current_org.is_real(): return [self.role] roles = [] if self in current_org.get_org_admins(): roles.append('org_admin') if self in current_org.get_org_auditors(): roles.append('org_auditor') if self in current_org.get_org_users(): roles.append('org_user') return roles
def perform_create(self, serializer): # 重写save的逻辑, username 用email users = serializer.save() users.username = serializer.data['email'] users.save() if isinstance(users, User): users = [users] if current_org and current_org.is_real(): current_org.users.add(*users) self.send_created_signal(users)
def perform_destroy(self, instance): if current_org.is_real(): instance.delete() else: return super().perform_destroy(instance)