-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 11 commits
10e3e8e
cdbdd6c
5142d34
46edfd3
6f6f69e
6f718de
ce50e8a
7ef43e3
98d904e
412ae3c
8165fea
3872934
524aeba
a697b20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"]: | ||
field_id = field_data.get("field_id", "") | ||
value = field_data.get("value", "") | ||
if field_id in fields: | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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à. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(), | ||
|
@@ -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) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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