Skip to content

Commit

Permalink
call stored procedure from submit view, fix #253
Browse files Browse the repository at this point in the history
  • Loading branch information
Matias authored and mandrade2 committed Jun 16, 2020
1 parent 1224d34 commit 8297471
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pootle/apps/pootle_store/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
from .unit.search import DBSearchBackend
from .unit.timeline import Timeline
from .util import find_altsrcs
from django.db import connection
import datetime


# The amount of TM results that will be provided
Expand Down Expand Up @@ -598,6 +600,11 @@ def submit(request, unit):
for field, old_value, new_value in form.updated_fields:
if field == SubmissionFields.TARGET and suggestion:
old_value = str(suggestion.target_f)

if current_time.microsecond > 0:
current_time = current_time + datetime.timedelta(seconds=1)
current_time = current_time.replace(microsecond=0)

sub = Submission(
creation_time=current_time,
translation_project=translation_project,
Expand All @@ -611,7 +618,27 @@ def submit(request, unit):
similarity=form.cleaned_data["similarity"],
mt_similarity=form.cleaned_data["mt_similarity"],
)
sub.save()

cursor = connection.cursor()
try:
result = cursor.callproc('insert_unique_submission', [
current_time.strftime("%Y-%m-%d %H:%M:%S"),
field,
request.user.id,
SubmissionTypes.NORMAL,
unit.id,
unit.store.id,
translation_project.id,
old_value,
new_value,
form.cleaned_data["similarity"],
form.cleaned_data["mt_similarity"]
])

res = cursor.fetchall()

finally:
cursor.close()

# Update current unit instance's attributes
# important to set these attributes after saving Submission
Expand Down

0 comments on commit 8297471

Please sign in to comment.