def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) config = Configuration.get_solo().registration_form or [] config = sorted( [field for field in config if field['position'] is not None], key=lambda field: field['position']) profiles = { profile.related_model.__name__: profile.related_model for profile in Member._meta.related_objects if isinstance(profile, OneToOneRel) and profile.name.startswith('profile_') } for field in config: self.build_field(field, profiles) if 'member__number' in self.fields: self.fields['member__number'].initial = get_next_member_number()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) config = Configuration.get_solo().registration_form or [] config = sorted( (field for field in config if field["position"] is not None), key=lambda field: field["position"], ) profiles = { profile.related_model.__name__: profile.related_model for profile in Member._meta.related_objects if isinstance(profile, OneToOneRel) and profile.name.startswith("profile_") } for field in config: self.build_field(field, profiles) if field.get("name", "") == "member__name": self.build_field({"name": "member__direct_address_name"}, []) self.build_field({"name": "member__order_name"}, []) if "member__number" in self.fields: self.fields["member__number"].initial = get_next_member_number()
def test_next_member_number_without_member(): assert get_next_member_number() == 1
def test_next_member_number(member): assert get_next_member_number() == Member.objects.count() + 1