Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# if not new:
# credit_form.self_credit.data = str(100 - sum_credit)
if credit_form.validate_on_submit():
try:
sum_credit = int(credit_form.self_credit.data)
logger.info(sum_credit)
for source_submission in source_submissions:
s_field = get_s_field(source_submission)
sum_credit += int(getattr(credit_form, s_field).data)
if sum_credit != 100:
return redirect_to_credit(
submission_hash,
'Error: The total credit should add up to 100'
)
except Exception as e:
return redirect_to_credit(submission_hash, 'Error: {}'.format(e))
for source_submission in source_submissions:
s_field = get_s_field(source_submission)
similarity = int(getattr(credit_form, s_field).data) / 100.
submission_similarity = \
(SubmissionSimilarity.query
.filter_by(
type='target_credit',
user=flask_login.current_user,
source_submission=source_submission,
target_submission=submission)
.all())
# if submission_similarity is not empty, we need to
# add zero to cancel previous credits explicitly
if similarity > 0 or submission_similarity:
add_submission_similarity(
db.session,
sum_credit += submission_credit
credit_form.name_credits.append(
(s_field, str(submission_credit), source_submission.link)
)
# This doesnt work, not sure why
# if not new:
# credit_form.self_credit.data = str(100 - sum_credit)
if credit_form.validate_on_submit():
try:
sum_credit = int(credit_form.self_credit.data)
logger.info(sum_credit)
for source_submission in source_submissions:
s_field = get_s_field(source_submission)
sum_credit += int(getattr(credit_form, s_field).data)
if sum_credit != 100:
return redirect_to_credit(
submission_hash,
'Error: The total credit should add up to 100'
)
except Exception as e:
return redirect_to_credit(submission_hash, 'Error: {}'.format(e))
for source_submission in source_submissions:
s_field = get_s_field(source_submission)
similarity = int(getattr(credit_form, s_field).data) / 100.
submission_similarity = \
(SubmissionSimilarity.query
.filter_by(
type='target_credit',
user=flask_login.current_user,
source_submission=source_submission,
target_submission=submission)
.all())