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

exchange/utils: check whether commit_unless_managed is available on current django installation #30

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions exchange/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ def insert_many(objects, using="default"):
table = model._meta.db_table
column_names = ",".join(con.ops.quote_name(f.column) for f in fields)
placeholders = ",".join(("%s",) * len(fields))
con.cursor().executemany("insert into %s (%s) values (%s)"
% (table, column_names, placeholders), parameters)
transaction.commit_unless_managed(using=using)

from distutils.version import StrictVersion
from django import get_version
# see https://docs.djangoproject.com/en/1.9/internals/deprecation/#deprecation-removed-in-1-8
if StrictVersion(get_version()) >= StrictVersion('1.6.0'):
with transaction.atomic():
con.cursor().executemany("insert into %s (%s) values (%s)"
% (table, column_names, placeholders), parameters)
else:
con.cursor().executemany("insert into %s (%s) values (%s)"
% (table, column_names, placeholders), parameters)
transaction.commit_unless_managed(using=using)


def update_many(objects, fields=[], using="default"):
Expand Down Expand Up @@ -91,11 +100,23 @@ def update_many(objects, fields=[], using="default"):
table = meta.db_table
assignments = ",".join(("%s=%%s" % con.ops.quote_name(f.column))
for f in fields)
con.cursor().executemany("update %s set %s where %s=%%s"
% (table, assignments,
con.ops.quote_name(meta.pk.column)),
parameters)
transaction.commit_unless_managed(using=using)

from distutils.version import StrictVersion
from django import get_version
# see https://docs.djangoproject.com/en/1.9/internals/deprecation/#deprecation-removed-in-1-8
if StrictVersion(get_version()) >= StrictVersion('1.6.0'):
with transaction.atomic():
con.cursor().executemany("update %s set %s where %s=%%s"
% (table, assignments,
con.ops.quote_name(meta.pk.column)),
parameters)
else:
con.cursor().executemany("update %s set %s where %s=%%s"
% (table, assignments,
con.ops.quote_name(meta.pk.column)),
parameters)
transaction.commit_unless_managed(using=using)



def memoize(ttl=None):
Expand Down