from webapp.models import Signup, SignupForm from django.utils import timezone from webapp.utils import month_from_now ALL_QUESTION_TYPES = [ {"id": "-naY2R1-h", "name": "Nimi", "type": "text", "options": []}, {"id": "5t1oN2Qev", "name": "Testi", "type": "info", "options": "teskstii"}, {"id": "MYaaAiOiU", "name": "Email", "type": "email", "options": []}, { "id": "Wb5tmyvki", "name": "Radio", "type": "radiobutton", "options": ["Yes", "no", "maybe"], }, { "id": "U41Zp9x0L", "name": "Checkbox", "type": "checkbox", "options": ["A", "B", "C"], }, {"id": "TnDqrvXKf", "name": "Numero", "type": "integer", "options": ["1", "100"]}, ] ALL_QUESTION_TYPES_ANSWER = { "-naY2R1-h": "Testi", "MYaaAiOiU": "test-spam@sahkoinsinoorikilta.fi", "Wb5tmyvki": "maybe", "U41Zp9x0L": ["B", "C"], "TnDqrvXKf": 5, } ALL_QUESTIONS_SCHEMA = { "type": "object", "required": ["-naY2R1-h", "MYaaAiOiU", "Wb5tmyvki", "U41Zp9x0L", "TnDqrvXKf"], "properties": { "-naY2R1-h": {"type": "string"}, "MYaaAiOiU": { "type": "string", "format": "email", "pattern": "^[a-zA-Z0-9.!#$%&\u2019*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$", }, "TnDqrvXKf": { "type": "number", "title": "Numero (1 -- 100)", "maximum": 100, "minimum": 1, "multipleOf": 1, }, "U41Zp9x0L": { "type": "array", "items": {"type": "string", "pattern": "^A$|^B$|^C$"}, "maxItems": 3, "uniqueItems": True, }, "Wb5tmyvki": {"type": "string", "pattern": "^Yes$|^no$|^maybe$"}, }, "minProperties": 5, } TEXT_SCHEMA = { "type": "object", "required": ["-naY2R1-h"], "properties": {"-naY2R1-h": ALL_QUESTIONS_SCHEMA["properties"]["-naY2R1-h"]}, "minProperties": 1, } RADIO_SCHEMA = { "type": "object", "required": ["Wb5tmyvki"], "properties": {"Wb5tmyvki": ALL_QUESTIONS_SCHEMA["properties"]["Wb5tmyvki"]}, "minProperties": 1, } CBOX_SCHEMA = { "type": "object", "required": ["U41Zp9x0L"], "properties": {"U41Zp9x0L": ALL_QUESTIONS_SCHEMA["properties"]["U41Zp9x0L"]}, "minProperties": 1, } def createSignupForm( name="Form1", start_time=timezone.now(), end_time=month_from_now(), questions=ALL_QUESTION_TYPES, schema=ALL_QUESTIONS_SCHEMA, visible=True, quota=1, ): return SignupForm.objects.create( title=name, start_time=start_time, end_time=end_time, questions=questions, visible=visible, schema=schema, quota=quota, ) def createSignupObject(list_name, form, answer): return Signup.objects.create(list_name=list_name, signupForm=form, answer=answer) def createSignupRequest(list_name, form_id, answer): return {"list_name": list_name, "signupForm_id": form_id, "answer": answer}