Skip to content

Commit

Permalink
Al 2317 python 3 upgrade (#2)
Browse files Browse the repository at this point in the history
* ALIMS Python 3 compatibility.
  • Loading branch information
KrzysztofBebenekArdigen authored Sep 22, 2020
1 parent e772585 commit a1969a2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"tw2.core>=2.0b2",
"tw2.jquery",
"tw2.jqplugins.ui>=2.0b7",
"tw2.sqla",
"six",
],
extras_require = {
Expand Down
8 changes: 4 additions & 4 deletions tw2/jqplugins/jqgrid/samples/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __unicode__(self):

def populateDB(sess):
if Person.query.count() > 0:
print "Not populating DB. Already stuff in there."
print("Not populating DB. Already stuff in there.")
return

firsts = ["Sally", "Suzie", "Sandy",
Expand Down Expand Up @@ -126,7 +126,7 @@ def populateDB(sess):
benalis = Person.query.filter_by(last_name='Ben Ali').all()
dictators = qaddafis + mubaraks + benalis

print "populating dictators friends"
print("populating dictators friends")
for p1 in dictators:
for p2 in dictators:
if p1 == p2 or p1 in p2.friends:
Expand All @@ -135,7 +135,7 @@ def populateDB(sess):
p1.friends.append(p2)
p2.friends.append(p1)

print "populating everyone else's friends"
print("populating everyone else's friends")
for p1 in Person.query.all():
for p2 in Person.query.all():
if p1 == p2 or p1 in p2.friends:
Expand All @@ -144,7 +144,7 @@ def populateDB(sess):
p1.friends.append(p2)
p2.friends.append(p1)

print "done populating DB"
print("done populating DB")

populateDB(session)
transaction.commit()
5 changes: 3 additions & 2 deletions tw2/jqplugins/jqgrid/widgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tw2.jqplugins.ui.base as tw2_jq_ui

from tw2.jqplugins.jqgrid import base
from six.moves import map

_pager_defaults = {
'enableSearch': True,
Expand Down Expand Up @@ -58,5 +59,5 @@ def prepare(self):
self._prmDel = encoder.encode(self.prmDel)
self._prmSearch = encoder.encode(self.prmSearch)
self._prmView = encoder.encode(self.prmView)
self._custom_pager_buttons = map(encoder.encode,
self.custom_pager_buttons)
self._custom_pager_buttons = list(map(encoder.encode,
self.custom_pager_buttons))
20 changes: 12 additions & 8 deletions tw2/jqplugins/jqgrid/widgets/sqla.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import tw2.core
import tw2.core.util
from tw2.core.resources import encoder
Expand All @@ -18,6 +16,12 @@
import math
import transaction

from past.builtins import cmp
from six import text_type
from six.moves import filter
from six.moves import map
from functools import reduce

COUNT_PREFIX = '__count_'


Expand Down Expand Up @@ -145,9 +149,9 @@ def massage(entry, prop):
if prop.uselist:
data = len(data)
else:
data = unicode(data)
data = text_type(data)
elif is_relation(prop) and not prop.uselist:
data = unicode(data)
data = text_type(data)

if isinstance(data, (datetime.datetime, datetime.date)):
data = data.strftime(cls.datetime_format)
Expand Down Expand Up @@ -244,7 +248,7 @@ def _build_sorted_query(cls, kw):

subquery_lookup = cls._get_subquery_lookup()
query_args, subqueries = {}, {}
for attribute, l in subquery_lookup.iteritems():
for attribute, l in subquery_lookup.items():
subquery = session.query(
dotted_getattr(l['cls'], l['local']),
sqlalchemy.sql.func.count('*').label(attribute)
Expand All @@ -259,9 +263,9 @@ def _build_sorted_query(cls, kw):
query_args[attribute] = getattr(subquery.c, attribute)
subqueries[attribute] = subquery

query = session.query(cls.entity, *query_args.values())
query = session.query(cls.entity, *list(query_args.values()))

for attribute, l in subquery_lookup.iteritems():
for attribute, l in subquery_lookup.items():
query = query.outerjoin((
subqueries[attribute],
getattr(cls.entity, l['remote']) ==
Expand Down Expand Up @@ -408,7 +412,7 @@ def _request_query(cls, req):
kw.update(req.params)

# Cast things to integers
kw['page'], kw['rows'] = map(int, [kw['page'], kw['rows']])
kw['page'], kw['rows'] = list(map(int, [kw['page'], kw['rows']]))

base = cls._build_sorted_query(kw)

Expand Down

0 comments on commit a1969a2

Please sign in to comment.