Skip to content

Commit

Permalink
Merge pull request #21221 from frappe/mergify/bp/version-14-hotfix/pr…
Browse files Browse the repository at this point in the history
…-21220

fix: handle multiple webform for same doctype (backport #21220)
  • Loading branch information
shariquerik committed Jun 3, 2023
2 parents d22658f + 5243143 commit d2c8297
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
31 changes: 25 additions & 6 deletions frappe/website/doctype/web_form/web_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"allow_incomplete",
"section_break_2",
"max_attachment_size",
"section_break_xzqr",
"condition",
"column_break_tjgl",
"condition_description",
"section_break_3",
"list_setting_message",
"show_list",
Expand Down Expand Up @@ -279,10 +283,6 @@
"fieldtype": "Tab Break",
"label": "Form"
},
{
"fieldname": "column_break_1",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_1",
"fieldtype": "Section Break"
Expand All @@ -297,7 +297,6 @@
"fieldtype": "Column Break"
},
{
"collapsible": 1,
"fieldname": "section_break_2",
"fieldtype": "Section Break"
},
Expand Down Expand Up @@ -374,13 +373,33 @@
"fieldname": "anonymous",
"fieldtype": "Check",
"label": "Anonymous"
},
{
"fieldname": "condition",
"fieldtype": "Code",
"label": "Condition",
"max_height": "150px"
},
{
"fieldname": "section_break_xzqr",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_tjgl",
"fieldtype": "Column Break"
},
{
"fieldname": "condition_description",
"fieldtype": "HTML",
"label": "Condition Description",
"options": "<p>Multiple webforms can be created for a single doctype. Write a condition specific to this webform to display correct record after submission.</p><p>For Example:</p>\n<p>If you create a separate webform every year to capture feedback from employees add a \n field named year in doctype and add a condition <b>doc.year==\"2023\"</b></p>\n"
}
],
"has_web_view": 1,
"icon": "icon-edit",
"is_published_field": "published",
"links": [],
"modified": "2023-04-20 17:24:42.657731",
"modified": "2023-06-03 19:18:56.760479",
"modified_by": "Administrator",
"module": "Website",
"name": "Web Form",
Expand Down
14 changes: 10 additions & 4 deletions frappe/website/doctype/web_form/web_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ def get_context(self, context):
and not frappe.form_dict.name
and not frappe.form_dict.is_list
):
name = frappe.db.get_value(self.doc_type, {"owner": frappe.session.user}, "name")
if name:
context.in_view_mode = True
frappe.redirect(f"/{self.route}/{name}")
names = frappe.db.get_values(self.doc_type, {"owner": frappe.session.user}, pluck="name")
for name in names:
if self.condition:
doc = frappe.get_doc(self.doc_type, name)
if frappe.safe_eval(self.condition, None, {"doc": doc.as_dict()}):
context.in_view_mode = True
frappe.redirect(f"/{self.route}/{name}")
else:
context.in_view_mode = True
frappe.redirect(f"/{self.route}/{name}")

# Show new form when
# - User is Guest
Expand Down

0 comments on commit d2c8297

Please sign in to comment.