diff --git a/hypha/apply/funds/models/mixins.py b/hypha/apply/funds/models/mixins.py index 2f1597fdd31237380671cb31024339ed9039381d..2780fe33f826d49bbb54f004f4aef62a63f72d6e 100644 --- a/hypha/apply/funds/models/mixins.py +++ b/hypha/apply/funds/models/mixins.py @@ -296,3 +296,16 @@ class AccessFormData: def output_first_group_text_answers(self): return mark_safe(''.join(self.render_first_group_text_answers())) + + def get_answer_from_label(self, label): + for field_id in self.question_text_field_ids: + if field_id not in self.named_blocks: + question_field = self.serialize(field_id) + if label.lower() in question_field['question'].lower(): + if isinstance(question_field['answer'], str): + answer = question_field['answer'] + else: + answer = ','.join(question_field['answer']) + if answer and not answer == 'N': + return answer + return None diff --git a/hypha/apply/projects/models.py b/hypha/apply/projects/models.py index 90d0b6c5b26f720af5c9ffe433205635322d4ef3..8fbb9793ba1479026e428f30e79723174545e4ed 100644 --- a/hypha/apply/projects/models.py +++ b/hypha/apply/projects/models.py @@ -431,12 +431,15 @@ class Project(BaseStreamForm, AccessFormData, models.Model): if hasattr(submission, 'project'): return submission.project + # See if there is a form field named "legal name", if not use user name. + legal_name = submission.get_answer_from_label('legal name') or submission.user.full_name + return Project.objects.create( submission=submission, title=submission.title, user=submission.user, contact_email=submission.user.email, - contact_legal_name=submission.user.full_name, + contact_legal_name=legal_name, contact_address=submission.form_data.get('address', ''), value=submission.form_data.get('value', 0), )