11from dataclasses import asdict
22from enum import Enum
33from typing import Annotated , Union , Optional
4+ from participants .models import Participant
45
56from privacy_policy .record import record_privacy_policy_acceptance
67import strawberry
@@ -42,11 +43,13 @@ class _GrantErrors:
4243 notes : list [str ] = strawberry .field (default_factory = list )
4344 travelling_from : list [str ] = strawberry .field (default_factory = list )
4445 non_field_errors : list [str ] = strawberry .field (default_factory = list )
45- website : list [str ] = strawberry .field (default_factory = list )
46- twitter_handle : list [str ] = strawberry .field (default_factory = list )
47- github_handle : list [str ] = strawberry .field (default_factory = list )
48- linkedin_url : list [str ] = strawberry .field (default_factory = list )
49- mastodon_handle : list [str ] = strawberry .field (default_factory = list )
46+ participant_bio : list [str ] = strawberry .field (default_factory = list )
47+ participant_website : list [str ] = strawberry .field (default_factory = list )
48+ participant_twitter_handle : list [str ] = strawberry .field (default_factory = list )
49+ participant_instagram_handle : list [str ] = strawberry .field (default_factory = list )
50+ participant_linkedin_url : list [str ] = strawberry .field (default_factory = list )
51+ participant_facebook_url : list [str ] = strawberry .field (default_factory = list )
52+ participant_mastodon_handle : list [str ] = strawberry .field (default_factory = list )
5053
5154 errors : _GrantErrors = None
5255
@@ -113,11 +116,14 @@ class SendGrantInput(BaseGrantInput):
113116 why : str
114117 notes : str
115118 travelling_from : str
116- website : str
117- twitter_handle : str
118- github_handle : str
119- linkedin_url : str
120- mastodon_handle : str
119+
120+ participant_bio : str
121+ participant_website : str
122+ participant_twitter_handle : str
123+ participant_instagram_handle : str
124+ participant_linkedin_url : str
125+ participant_facebook_url : str
126+ participant_mastodon_handle : str
121127
122128 def validate (self , conference : Conference , user : User ) -> GrantErrors | None :
123129 errors = super ().validate (conference = conference , user = user )
@@ -147,11 +153,14 @@ class UpdateGrantInput(BaseGrantInput):
147153 why : str
148154 notes : str
149155 travelling_from : str
150- website : str
151- twitter_handle : str
152- github_handle : str
153- linkedin_url : str
154- mastodon_handle : str
156+
157+ participant_bio : str
158+ participant_website : str
159+ participant_twitter_handle : str
160+ participant_instagram_handle : str
161+ participant_linkedin_url : str
162+ participant_facebook_url : str
163+ participant_mastodon_handle : str
155164
156165 def validate (self , conference : Conference , user : User ) -> GrantErrors | None :
157166 return super ().validate (conference = conference , user = user ).if_has_errors
@@ -205,9 +214,23 @@ def send_grant(self, info: Info, input: SendGrantInput) -> SendGrantResult:
205214 with transaction .atomic ():
206215 instance = GrantModel .objects .create (
207216 ** {
208- ** asdict (input ),
209217 "user_id" : request .user .id ,
210218 "conference" : conference ,
219+ "name" : input .name ,
220+ "full_name" : input .full_name ,
221+ "age_group" : input .age_group ,
222+ "gender" : input .gender ,
223+ "occupation" : input .occupation ,
224+ "grant_type" : input .grant_type ,
225+ "python_usage" : input .python_usage ,
226+ "been_to_other_events" : input .been_to_other_events ,
227+ "community_contribution" : input .community_contribution ,
228+ "needs_funds_for_travel" : input .needs_funds_for_travel ,
229+ "need_visa" : input .need_visa ,
230+ "need_accommodation" : input .need_accommodation ,
231+ "why" : input .why ,
232+ "notes" : input .notes ,
233+ "travelling_from" : input .travelling_from ,
211234 }
212235 )
213236
@@ -217,6 +240,20 @@ def send_grant(self, info: Info, input: SendGrantInput) -> SendGrantResult:
217240 "grant" ,
218241 )
219242
243+ Participant .objects .update_or_create (
244+ user_id = request .user .id ,
245+ conference = instance .conference ,
246+ defaults = {
247+ "bio" : input .participant_bio ,
248+ "website" : input .participant_website ,
249+ "twitter_handle" : input .participant_twitter_handle ,
250+ "instagram_handle" : input .participant_instagram_handle ,
251+ "linkedin_url" : input .participant_linkedin_url ,
252+ "facebook_url" : input .participant_facebook_url ,
253+ "mastodon_handle" : input .participant_mastodon_handle ,
254+ },
255+ )
256+
220257 # hack because we return django models
221258 instance .__strawberry_definition__ = Grant .__strawberry_definition__
222259 return instance
@@ -239,6 +276,20 @@ def update_grant(self, info: Info, input: UpdateGrantInput) -> UpdateGrantResult
239276 setattr (instance , attr , value )
240277 instance .save ()
241278
279+ Participant .objects .update_or_create (
280+ user_id = request .user .id ,
281+ conference = instance .conference ,
282+ defaults = {
283+ "bio" : input .participant_bio ,
284+ "website" : input .participant_website ,
285+ "twitter_handle" : input .participant_twitter_handle ,
286+ "instagram_handle" : input .participant_instagram_handle ,
287+ "linkedin_url" : input .participant_linkedin_url ,
288+ "facebook_url" : input .participant_facebook_url ,
289+ "mastodon_handle" : input .participant_mastodon_handle ,
290+ },
291+ )
292+
242293 instance .__strawberry_definition__ = Grant .__strawberry_definition__
243294 return instance
244295
0 commit comments