def create_instance(self, csv_row): # Ignore all emails that are not in the supported domain. email = csv_row[0].lower() if not email.endswith("@" + self._EMAIL_DOMAIN): return None # Ignore all members that already exist. group = self.cleaned_data["group"] user = users.get_user(email) if Member.get_unique(group=group, user=user) is not None: return None # Create a new Member instance. if csv_row[2] == "manager" or csv_row[2] == "owner": role = Member.MODERATOR else: role = Member.MEMBER join_date = datetime.date(int(csv_row[6]), int(csv_row[7]), int(csv_row[8])) return Member.create( user=user, group=group, role=role, join_date=join_date, is_approved=True )
def create(self, user, group): if not self.is_valid(): raise InvalidFormError(self.errors) instance = Member.create(user=user, group=group, **self.cleaned_data) instance.save() return instance