Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for limit submit and unique field in store data option #58

Closed
wants to merge 14 commits into from
29 changes: 28 additions & 1 deletion src/collective/volto/formsupport/datamanager/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def add(self, data):
record = Record()
fields_labels = {}
fields_order = []
for field_data in data:
for field_data in data["form_data"]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ma, c'era un bug?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no no, è solo perché ho aggiunto più campi al json con i dati

field_id = field_data.get("field_id", "")
value = field_data.get("value", "")
if field_id in fields:
Expand All @@ -96,12 +96,32 @@ def add(self, data):
record.attrs["fields_order"] = fields_order
record.attrs["date"] = datetime.now()
record.attrs["block_id"] = self.block_id

keys = [
(x["field_id"], x["label"]) for x in form_fields if x.get("unique", False)
]
if keys:
saved_data = self.soup.data.values()
for saved_record in saved_data:
unique = False
for key in keys:
if (
record.attrs.storage[key[0]]
!= saved_record.attrs.storage[key[0]]
):
unique = True
break

if not unique:
raise ValueError(f" {', '.join([x[1] for x in keys])}")

return self.soup.add(record)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunque, se capisco bene, guardi i campi che arrivano nel form e cerchi nei dati salvati finchè non vedi che c'è un unicità.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esatto, avrei voluto usare modi più veloci, ma dato che l'unicità dei campi può cambiare tramite il form va tutto fatto al volo


def length(self):
return len([x for x in self.soup.data.values()])

def search(self, query=None):
records = []
mamico marked this conversation as resolved.
Show resolved Hide resolved
if not query:
records = sorted(
self.soup.data.values(),
Expand All @@ -110,6 +130,13 @@ def search(self, query=None):
)
return records

def count(self, query=None):
records = []
if not query:
records = self.soup.data.values()

return len(records)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, questo ti ritorna il numero di entry. non capisco come lo colleghi al form... mi pare che così cerchi in tutto il soup

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onestamente avevo anche io quel dubbio, ma mi sono basato sulla search per farlo, e la search funziona

Copy link
Contributor

@mamico mamico Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eikichi18 IMHO this is a bug. Try adding 2 forms, each with limit 2, add one record to each, try adding a second record. Does this work?

def delete(self, id):
record = self.soup.get(id)
del self.soup[record]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-06-07 00:42+0000\n"
"POT-Creation-Date: 2024-06-25 10:15+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -21,6 +21,10 @@ msgstr ""
msgid "Email confirmation code"
msgstr ""

#: ../browser/send_mail_template_table.pt:18
msgid "Field"
msgstr ""

#: ../captcha/recaptcha.py:12
msgid "Google ReCaptcha"
msgstr ""
Expand Down Expand Up @@ -55,6 +59,10 @@ msgstr ""
msgid "OTP is wrong"
msgstr ""

#: ../browser/templates/email_confirm_view.pt:17
msgid "Simple Transactional Email"
msgstr ""

#: ../captcha/hcaptcha.py:56
#: ../captcha/norobots.py:65
#: ../captcha/recaptcha.py:54
Expand Down Expand Up @@ -85,6 +93,10 @@ msgstr ""
msgid "Uninstalls the collective.volto.formsupport add-on."
msgstr ""

#: ../browser/send_mail_template_table.pt:23
msgid "Value"
msgstr ""

#: ../configure.zcml:34
msgid "Volto: Form support"
msgstr ""
Expand All @@ -98,17 +110,17 @@ msgid "Your code to validate the email address:"
msgstr ""

#. Default: "Attachments too big. You uploaded ${uploaded_str}, but limit is ${max} MB. Try to compress files."
#: ../restapi/services/submit_form/post.py:215
#: ../restapi/services/submit_form/post.py:234
msgid "attachments_too_big"
msgstr ""

#. Default: "Block with @type \"form\" and id \"$block\" not found in this context: $context"
#: ../restapi/services/submit_form/post.py:130
#: ../restapi/services/submit_form/post.py:149
msgid "block_form_not_found_label"
msgstr ""

#. Default: "Empty form data."
#: ../restapi/services/submit_form/post.py:156
#: ../restapi/services/submit_form/post.py:175
msgid "empty_form_data"
msgstr ""

Expand All @@ -118,22 +130,27 @@ msgid "honeypot_error"
msgstr ""

#. Default: "Unable to send confirm email. Please retry later or contact site administrator."
#: ../restapi/services/submit_form/post.py:76
#: ../restapi/services/submit_form/post.py:82
msgid "mail_send_exception"
msgstr ""

#. Default: "You need to set at least one form action between \"send\" and \"store\"."
#: ../restapi/services/submit_form/post.py:145
#: ../restapi/services/submit_form/post.py:164
msgid "missing_action"
msgstr ""

#. Default: "Missing block_id"
#: ../restapi/services/submit_form/post.py:123
#: ../restapi/services/submit_form/post.py:142
msgid "missing_blockid_label"
msgstr ""

#. Default: "A new form has been submitted from <a href=\"${url}\">${url}</a>"
#: ../browser/send_mail_template.pt:22
#. Default: "Unable to save data. Value not unique: '${fields}'"
#: ../restapi/services/submit_form/post.py:96
msgid "save_data_exception"
msgstr ""

#. Default: "A new form has been submitted from <a href=\"${DYNAMIC_CONTENT}\">${url}</a>"
#: ../browser/send_mail_template.pt:24
msgid "send_mail_text"
msgstr ""

Expand All @@ -143,15 +160,15 @@ msgid "send_mail_text_table"
msgstr ""

#. Default: "Missing required field: subject or from."
#: ../restapi/services/submit_form/post.py:322
#: ../restapi/services/submit_form/post.py:341
msgid "send_required_field_missing"
msgstr ""

#. Default: "Email not valid in \"${field}\" field."
#: ../restapi/services/submit_form/post.py:187
#: ../restapi/services/submit_form/post.py:206
msgid "wrong_email"
msgstr ""

#: ../restapi/services/submit_form/post.py:246
#: ../restapi/services/submit_form/post.py:265
msgid "{email}'s OTP is wrong"
msgstr ""
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-06-07 00:42+0000\n"
"POT-Creation-Date: 2024-06-25 10:15+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -18,6 +18,10 @@ msgstr ""
msgid "Email confirmation code"
msgstr ""

#: ../browser/send_mail_template_table.pt:18
msgid "Field"
msgstr ""

#: ../captcha/recaptcha.py:12
msgid "Google ReCaptcha"
msgstr ""
Expand Down Expand Up @@ -52,6 +56,10 @@ msgstr ""
msgid "OTP is wrong"
msgstr ""

#: ../browser/templates/email_confirm_view.pt:17
msgid "Simple Transactional Email"
msgstr ""

#: ../captcha/hcaptcha.py:56
#: ../captcha/norobots.py:65
#: ../captcha/recaptcha.py:54
Expand Down Expand Up @@ -82,6 +90,10 @@ msgstr ""
msgid "Uninstalls the collective.volto.formsupport add-on."
msgstr ""

#: ../browser/send_mail_template_table.pt:23
msgid "Value"
msgstr ""

#: ../configure.zcml:34
msgid "Volto: Form support"
msgstr ""
Expand All @@ -95,17 +107,17 @@ msgid "Your code to validate the email address:"
msgstr ""

#. Default: "Attachments too big. You uploaded ${uploaded_str}, but limit is ${max} MB. Try to compress files."
#: ../restapi/services/submit_form/post.py:215
#: ../restapi/services/submit_form/post.py:234
msgid "attachments_too_big"
msgstr "Anhang ist zu groß (${uploaded_str}). Die Größe darf ${max} MB nicht überschreiten. Versuchen Sie Dateien zu komprimieren."

#. Default: "Block with @type \"form\" and id \"$block\" not found in this context: $context"
#: ../restapi/services/submit_form/post.py:130
#: ../restapi/services/submit_form/post.py:149
msgid "block_form_not_found_label"
msgstr "Kein Formular-Block mit der ID \"$block\" in diesem Kontext gefunden: $context"

#. Default: "Empty form data."
#: ../restapi/services/submit_form/post.py:156
#: ../restapi/services/submit_form/post.py:175
msgid "empty_form_data"
msgstr "Leere Formulardaten."

Expand All @@ -114,23 +126,30 @@ msgstr "Leere Formulardaten."
msgid "honeypot_error"
msgstr "Formular konnte nicht abgeschickt werden."

#. Default: "Unable to send confirm email. Please retry later or contact site administator."
#: ../restapi/services/submit_form/post.py:76
#. Default: "Unable to send confirm email. Please retry later or contact site administrator."
#: ../restapi/services/submit_form/post.py:82
#, fuzzy
msgid "mail_send_exception"
msgstr "Die Bestätigungsmail konnte nicht versandt werden. Bitte versuchen Sie es später erneut oder kontaktieren Sie die Seitenadministration."

#. Default: "You need to set at least one form action between \"send\" and \"store\"."
#: ../restapi/services/submit_form/post.py:145
#: ../restapi/services/submit_form/post.py:164
msgid "missing_action"
msgstr "Es muss mindestens eine Formular-Aktion gesetzt werden (\"E-Mail an Empfänger senden\" und/oder \"Kompilierte Daten speichern\")."

#. Default: "Missing block_id"
#: ../restapi/services/submit_form/post.py:123
#: ../restapi/services/submit_form/post.py:142
msgid "missing_blockid_label"
msgstr "Fehlende block_id"

#. Default: "A new form has been submitted from <a href=\"${url}\">${url}</a>"
#: ../browser/send_mail_template.pt:22
#. Default: "Unable to save data. Value not unique: '${fields}'"
#: ../restapi/services/submit_form/post.py:96
msgid "save_data_exception"
msgstr ""

#. Default: "A new form has been submitted from <a href=\"${DYNAMIC_CONTENT}\">${url}</a>"
#: ../browser/send_mail_template.pt:24
#, fuzzy
msgid "send_mail_text"
msgstr "Auf der Seite ${url} wurde ein neues Formular eingereicht:"

Expand All @@ -140,15 +159,15 @@ msgid "send_mail_text_table"
msgstr ""

#. Default: "Missing required field: subject or from."
#: ../restapi/services/submit_form/post.py:322
#: ../restapi/services/submit_form/post.py:341
msgid "send_required_field_missing"
msgstr "Erforderliches Feld fehlt: Betreff oder Absender"

#. Default: "Email not valid in \"${field}\" field."
#: ../restapi/services/submit_form/post.py:187
#: ../restapi/services/submit_form/post.py:206
msgid "wrong_email"
msgstr ""

#: ../restapi/services/submit_form/post.py:246
#: ../restapi/services/submit_form/post.py:265
msgid "{email}'s OTP is wrong"
msgstr ""
Loading