mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-19 06:54:20 +01:00
Fix some glitches with removing values
This commit is contained in:
@@ -30,7 +30,12 @@ def SettingsForm(*args, **kwargs):
|
|||||||
|
|
||||||
for field in new_fields:
|
for field in new_fields:
|
||||||
form_field = getattr(self, f"fields[{field.id}]")
|
form_field = getattr(self, f"fields[{field.id}]")
|
||||||
form_field.data = user_fields.get(field.id, "")
|
initial = user_fields.get(field.id, "")
|
||||||
|
form_field.data = initial
|
||||||
|
if form_field.render_kw:
|
||||||
|
form_field.render_kw["initial"] = initial
|
||||||
|
else:
|
||||||
|
form_field.render_kw = {"data-initial": initial}
|
||||||
entry = (field.name, form_field)
|
entry = (field.name, form_field)
|
||||||
fields.append(entry)
|
fields.append(entry)
|
||||||
return fields
|
return fields
|
||||||
|
|||||||
@@ -70,7 +70,12 @@ def UserEditForm(*args, **kwargs):
|
|||||||
|
|
||||||
for field in new_fields:
|
for field in new_fields:
|
||||||
form_field = getattr(self, f"fields[{field.id}]")
|
form_field = getattr(self, f"fields[{field.id}]")
|
||||||
form_field.data = user_fields.get(field.id, "")
|
initial = user_fields.get(field.id, "")
|
||||||
|
form_field.data = initial
|
||||||
|
if form_field.render_kw:
|
||||||
|
form_field.render_kw["initial"] = initial
|
||||||
|
else:
|
||||||
|
form_field.render_kw = {"data-initial": initial}
|
||||||
entry = (field.name, form_field)
|
entry = (field.name, form_field)
|
||||||
fields.append(entry)
|
fields.append(entry)
|
||||||
return fields
|
return fields
|
||||||
|
|||||||
@@ -199,6 +199,9 @@ class UserSchema(ma.ModelSchema):
|
|||||||
user_id = data.get("id")
|
user_id = data.get("id")
|
||||||
if user_id:
|
if user_id:
|
||||||
target_user = Users.query.filter_by(id=data["id"]).first()
|
target_user = Users.query.filter_by(id=data["id"]).first()
|
||||||
|
else:
|
||||||
|
target_user = current_user
|
||||||
|
|
||||||
provided_ids = []
|
provided_ids = []
|
||||||
for f in fields:
|
for f in fields:
|
||||||
f.pop("id", None)
|
f.pop("id", None)
|
||||||
@@ -213,21 +216,18 @@ class UserSchema(ma.ModelSchema):
|
|||||||
).first()
|
).first()
|
||||||
if entry:
|
if entry:
|
||||||
f["id"] = entry.id
|
f["id"] = entry.id
|
||||||
|
provided_ids.append(entry.id)
|
||||||
|
|
||||||
# Extremely dirty hack to prevent deleting previously provided data.
|
# Extremely dirty hack to prevent deleting previously provided data.
|
||||||
# This needs a better soln.
|
# This needs a better soln.
|
||||||
entries = (
|
entries = (
|
||||||
FieldEntries.query.options(load_only("id"))
|
FieldEntries.query.options(load_only("id"))
|
||||||
.filter_by(user_id=current_user.id)
|
.filter_by(user_id=target_user.id)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
print(entries)
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.id not in provided_ids:
|
if entry.id not in provided_ids:
|
||||||
fields.append({"id": entry.id})
|
fields.append({"id": entry.id})
|
||||||
else:
|
|
||||||
# Marshmallow automatically links the fields to newly created users
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
provided_ids = []
|
provided_ids = []
|
||||||
for f in fields:
|
for f in fields:
|
||||||
@@ -259,7 +259,6 @@ class UserSchema(ma.ModelSchema):
|
|||||||
.filter_by(user_id=current_user.id)
|
.filter_by(user_id=current_user.id)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
print(entries)
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.id not in provided_ids:
|
if entry.id not in provided_ids:
|
||||||
fields.append({"id": entry.id})
|
fields.append({"id": entry.id})
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -26,7 +26,7 @@ $.fn.serializeJSON = function(omit_nulls) {
|
|||||||
if (x.value !== null && x.value !== "") {
|
if (x.value !== null && x.value !== "") {
|
||||||
params[x.name] = x.value;
|
params[x.name] = x.value;
|
||||||
} else {
|
} else {
|
||||||
let input = form.find(`:input[name=${x.name}]`);
|
let input = form.find(`:input[name='${x.name}']`);
|
||||||
if (input.data("initial") !== input.val()) {
|
if (input.data("initial") !== input.val()) {
|
||||||
params[x.name] = x.value;
|
params[x.name] = x.value;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user