def __init__(self, group, user): self._group = group self._user = user if user: self._member = Member.get_unique(group=group, user=user) else: self._member = None
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 get_member(self): member = Member.get_unique(group=self.get_group(), user=self.get_user()) if not member: message = "searched by user %s." % self.get_user().username raise EntityNotFoundError(Member, message) return member