Skip to content

Commit

Permalink
Merge pull request #1279 from SG-phimeca/neighbors_no_exec
Browse files Browse the repository at this point in the history
Replace exec by setattr in neighbors
  • Loading branch information
justinmayer authored Jul 7, 2020
2 parents f191788 + 377b855 commit 4181b14
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions neighbors/neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ def get_translation(article, prefered_language):

def set_neighbors(articles, next_name, prev_name):
for nxt, cur, prv in iter3(articles):
exec("cur.{} = nxt".format(next_name))
exec("cur.{} = prv".format(prev_name))
setattr(cur, next_name, nxt)
setattr(cur, prev_name, prv)

for translation in cur.translations:
exec(
"translation.{} = get_translation(nxt, translation.lang)"
.format(next_name))
exec(
"translation.{} = get_translation(prv, translation.lang)"
.format(prev_name))

setattr(translation, next_name,
get_translation(nxt, translation.lang))
setattr(translation, prev_name,
get_translation(prv, translation.lang))

def neighbors(generator):
set_neighbors(generator.articles, 'next_article', 'prev_article')
Expand Down

0 comments on commit 4181b14

Please sign in to comment.