Skip to content

Commit 5c25689

Browse files
authored
Merge pull request #8909 from norbusan/merge-to-master
Merge to master
2 parents 92cb8a9 + 79da19c commit 5c25689

15 files changed

+145
-11
lines changed

app/api/custom_forms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def query(self, view_kwargs):
5757
:return:
5858
"""
5959
query_ = self.session.query(CustomForms)
60-
query_ = event_query(query_, view_kwargs)
60+
if view_kwargs.get('form_id'):
61+
events = safe_query_kwargs(Event, view_kwargs, 'event_id')
62+
query_ = self.session.query(CustomForms).filter_by(event_id=events.id)
63+
query_ = query_.filter_by(form_id=view_kwargs.get('form_id'))
64+
else:
65+
query_ = event_query(query_, view_kwargs)
6166
return query_
6267

6368
view_kwargs = True

app/api/helpers/custom_forms.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.api.helpers.errors import UnprocessableEntityError
66
from app.api.schema.base import TrimmedEmail
77
from app.models.custom_form import CustomForms
8+
from app.models.ticket import Ticket
89

910

1011
def object_as_dict(obj):
@@ -33,11 +34,18 @@ def get_schema(form_fields):
3334

3435

3536
def validate_custom_form_constraints(form, obj, excluded):
36-
form_fields = CustomForms.query.filter_by(
37-
form=form,
38-
event_id=obj.event_id,
39-
is_included=True,
40-
).all()
37+
"""
38+
The validate custom form constraints.
39+
"""
40+
conditions = {
41+
'form': form,
42+
'event_id': obj.event_id,
43+
'is_included': True,
44+
}
45+
if hasattr(obj, 'ticket_id'):
46+
ticket = Ticket.query.filter_by(id=obj.ticket_id).first()
47+
conditions.update({'form_id': ticket.form_id})
48+
form_fields = CustomForms.query.filter_by(**conditions).all()
4149
required_form_fields = filter(lambda field: field.is_required, form_fields)
4250
missing_required_fields = []
4351
for field in required_form_fields:
@@ -72,7 +80,12 @@ def validate_custom_form_constraints(form, obj, excluded):
7280
return data if data else None
7381

7482

75-
def validate_custom_form_constraints_request(form, schema, obj, data, excluded=[]):
83+
def validate_custom_form_constraints_request(form, schema, obj, data, excluded=None):
84+
"""
85+
The validate custom form constraints request.
86+
"""
87+
if excluded is None:
88+
excluded = []
7689
new_obj = type(obj)(**object_as_dict(obj))
7790
relationship_fields = get_relationships(schema)
7891
for key, value in data.items():

app/api/helpers/static.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@
549549
'USD',
550550
]
551551

552-
AGE_GROUP_CHOICES = ['19 or less', '20 to 29', '30 to 39', '40 to 49', '50 or above']
552+
AGE_GROUP_CHOICES = ['Under 18', '18-24', '25-34', '35-44', '45-54', '55-64', '65-74', '75-84', '85+', 'I prefer not '
553+
'to say']
553554

554555
GENDER_CHOICES = [
555556
'Male',

app/api/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,8 @@
16571657
'custom_form_list',
16581658
'/events/<int:event_id>/custom-forms',
16591659
'/events/<event_identifier>/custom-forms',
1660+
'/events/<int:event_id>/custom-forms/<string:form_id>',
1661+
'/events/<event_identifier>/custom-forms/<string:form_id>',
16601662
)
16611663
api.route(
16621664
CustomFormDetail,

app/api/schema/attendees.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def validate_json(self, data, original_data):
5959
age_group = fields.Str(
6060
validate=validate.OneOf(choices=AGE_GROUP_CHOICES), allow_none=True
6161
)
62+
home_wiki = fields.Str(allow_none=True)
6263
birth_date = fields.DateTime(allow_none=True)
6364

6465
ticket_id = fields.Str(allow_none=True)
@@ -70,6 +71,8 @@ def validate_json(self, data, original_data):
7071
is_checked_out = fields.Boolean()
7172
pdf_url = fields.Url(dump_only=True)
7273
complex_field_values = CustomFormValueField(allow_none=True)
74+
language_form_1 = fields.Str(allow_none=True)
75+
language_form_2 = fields.Str(allow_none=True)
7376
event = Relationship(
7477
self_view='v1.attendee_event',
7578
self_view_kwargs={'id': '<id>'},

app/api/schema/custom_forms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Meta:
5252
is_included = fields.Boolean(default=False)
5353
is_public = fields.Boolean(default=False)
5454
position = fields.Integer(allow_none=True, default=0)
55-
is_complex = fields.Boolean(dump_only=True)
55+
is_complex = fields.Boolean(dump_only=True, default=False)
5656
is_fixed = fields.Boolean(default=False)
5757
event = Relationship(
5858
self_view='v1.custom_form_event',
@@ -62,3 +62,6 @@ class Meta:
6262
schema='EventSchemaPublic',
6363
type_='event',
6464
)
65+
form_id = fields.Str(allow_none=True)
66+
min = fields.Integer(allow_none=True, default=0)
67+
max = fields.Integer(allow_none=True, default=10)

app/api/schema/tickets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def validate_discount_code(self, data, original_data):
127127
max_order = fields.Integer(validate=lambda n: n >= 0, allow_none=True)
128128
is_checkin_restricted = fields.Boolean(default=True)
129129
auto_checkin_enabled = fields.Boolean(default=False)
130+
form_id = fields.Str(allow_none=True)
130131
event = Relationship(
131132
self_view='v1.ticket_event',
132133
self_view_kwargs={'id': '<id>'},

app/models/custom_form.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@
6161
"github": {"include": 1, "require": 0},
6262
"gender": {"include": 0, "require": 0},
6363
"age_group": {"include": 0, "require": 0},
64+
"home_wiki": {"include": 0, "require": 0},
6465
"accept_video_recording": {"include": 0, "require": 0},
66+
"language_form_1": {"include": 0, "require": 0},
67+
"language_form_2": {"include": 0, "require": 0},
6568
}
6669

6770
session_form_str = json.dumps(SESSION_FORM, separators=(',', ':'))
@@ -146,6 +149,9 @@
146149
"acceptVideoRecording": "Photo & video & text consent",
147150
"acceptShareDetails": "Partner contact consent",
148151
"acceptReceiveEmails": "Email consent",
152+
"language_form_1": "What is your native language, or what language are you most fluent in?",
153+
"language_form_2": "Are you fluent in any other of the following languages?",
154+
"home_wiki": "What is your home wiki"
149155
},
150156
}
151157

@@ -161,7 +167,7 @@ class TYPE:
161167
__tablename__ = 'custom_forms'
162168
__table_args__ = (
163169
UniqueConstraint(
164-
'event_id', 'field_identifier', 'form', name='custom_form_identifier'
170+
'event_id', 'field_identifier', 'form', 'form_id', name='custom_form_identifier'
165171
),
166172
)
167173
id = db.Column(db.Integer, primary_key=True)
@@ -178,6 +184,9 @@ class TYPE:
178184
is_complex = db.Column(db.Boolean, nullable=False, default=False)
179185
event_id = db.Column(db.Integer, db.ForeignKey('events.id', ondelete='CASCADE'))
180186
custom_form_options = db.relationship('CustomFormOptions', backref="custom_form")
187+
form_id = db.Column(db.String)
188+
min = db.Column(db.Integer, default=0, nullable=True)
189+
max = db.Column(db.Integer, default=10, nullable=True)
181190

182191
@property
183192
def identifier(self):

app/models/ticket.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Ticket(SoftDeletionModel):
7676
discount_codes = db.relationship(
7777
'DiscountCode', secondary=discount_codes_tickets, backref="tickets"
7878
)
79+
form_id = db.Column(db.String)
7980

8081
def has_order_tickets(self):
8182
"""Returns True if ticket has already placed orders.

app/models/ticket_holder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TicketHolder(SoftDeletionModel):
4444
accept_share_details: bool = db.Column(db.Boolean)
4545
accept_receive_emails: bool = db.Column(db.Boolean)
4646
age_group: str = db.Column(db.String)
47+
home_wiki: str = db.Column(db.String)
4748
birth_date: datetime = db.Column(db.DateTime(timezone=True))
4849
pdf_url: str = db.Column(db.String)
4950
ticket_id: int = db.Column(
@@ -64,6 +65,8 @@ class TicketHolder(SoftDeletionModel):
6465
db.DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow
6566
)
6667
complex_field_values: str = db.Column(db.JSON)
68+
language_form_1: str = db.Column(db.JSON)
69+
language_form_2: str = db.Column(db.JSON)
6770
user = db.relationship(
6871
'User',
6972
foreign_keys=[email],

0 commit comments

Comments
 (0)