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

Update coding style in Python files (#724) #918

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions wouso/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import warnings, logging, sys
import logging
import sys
import warnings
from functools import wraps
from django.contrib import messages
from django.contrib.auth import logout
Expand Down Expand Up @@ -33,5 +35,6 @@ def block_if_not_staff(sender, user, request, **kwargs):
messages.error(request, _('Only staff members can log in'))
logout(request)

if not 'test' in sys.argv:

if 'test' not in sys.argv:
user_logged_in.connect(block_if_not_staff)
1 change: 1 addition & 0 deletions wouso/core/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
class SettingAdmin(admin.ModelAdmin):
list_display = ('name', 'value')


admin.site.register(Setting, SettingAdmin)
8 changes: 4 additions & 4 deletions wouso/core/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ def set_value(self, v):
self.save()

def get_value(self):
l = []
return_list = []
for n in self.value.split():
try:
l.append(int(n))
return_list.append(int(n))
except ValueError:
l.append(0)
return l
return_list.append(0)
return return_list

def form(self):
return ''
Expand Down
2 changes: 1 addition & 1 deletion wouso/core/god/god.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_all_modifiers(self):
'curse', # prevent cast of positive spells, or cure and dispell
'immunity', # prevent cast of any spells, or cure and dispell
'top-disguise', # allow showing another number of points in top
]
]

for g in get_games():
ms.extend(g.get_modifiers())
Expand Down
2 changes: 2 additions & 0 deletions wouso/core/magic/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class SpellAdmin(admin.ModelAdmin):
list_display = ('name', 'title', 'type', 'percents', 'price', 'level_required', 'available', 'mass')


admin.site.register(Artifact)
admin.site.register(ArtifactGroup)
admin.site.register(Spell, SpellAdmin)
4 changes: 2 additions & 2 deletions wouso/core/magic/default_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

print "done"
# Assure each user has a level
#level = Artifact.get_level_1()
#for u in Player.objects.all():
# level = Artifact.get_level_1()
# for u in Player.objects.all():
# if u.level is None:
# u.level = level
# u.save()
Expand Down
2 changes: 2 additions & 0 deletions wouso/core/magic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Artifact(CachedItem, Modifier):
but also personalization such as: image (icon) and title
"""
CACHE_PART = 'full_name'

class Meta:
unique_together = ('name', 'group', 'percents')

Expand Down Expand Up @@ -266,4 +267,5 @@ def management_task(cls, datetime=lambda: datetime.now(), stdout=sys.stdout):
signals.postExpire.send(sender=None, psdue=s)
s.delete()


register_header_link('bazaar', Bazaar.get_header_link)
2 changes: 1 addition & 1 deletion wouso/core/magic/templatetags/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def spell_due(psd):
html = artifact(psd)

return '<span class="artifact-container" title="%s until %s">%s<span class="sup">*</span></span>' % \
(psd.spell.title, psd.due, html)
(psd.spell.title, psd.due, html)


@register.simple_tag
Expand Down
8 changes: 4 additions & 4 deletions wouso/core/magic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ def test_cast_spell(self):
v = []
for i in range(0, 7):
player = self._get_player(i + 2)
player.points = 10-i
player.points = 10 - i
player.save()
v.append(player)

v[3].magic.add_spell(spell2)
neigh = v[3].get_neighbours_from_top(2)
neigh = v[3].magic.filter_players_by_spell(neigh, spell2)
v[3].magic.mass_cast(spell2, neigh, datetime.now()+timedelta(days=1))
v[3].magic.mass_cast(spell2, neigh, datetime.now() + timedelta(days=1))

for i in [1, 2, 4, 5]:
self.assertTrue(v[i].magic.is_spelled)
self.assertTrue(v[3].magic.is_spelled)

v[6].magic.cast_spell(spell1, v[0], datetime.now()+timedelta(days=1))
v[6].magic.cast_spell(spell1, v[0], datetime.now() + timedelta(days=1))
self.assertFalse(v[6].magic.is_spelled)

v[0].magic.add_spell(spell1)
v[6].magic.cast_spell(spell1, v[0], datetime.now()+timedelta(days=1))
v[6].magic.cast_spell(spell1, v[0], datetime.now() + timedelta(days=1))
self.assertTrue(v[6].magic.is_spelled)


Expand Down
1 change: 1 addition & 0 deletions wouso/core/qpool/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class QuestionAdmin(admin.ModelAdmin):
class Questions2(admin.ModelAdmin):
list_display = ('text')


admin.site.register(models.Question, QuestionAdmin)
admin.site.register(models.Tag)
admin.site.register(models.Category)
Expand Down
5 changes: 3 additions & 2 deletions wouso/core/scoring/sm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class InvalidScoreCall(Exception):


def fib(n):
return int(round((PHI**n - (1-PHI)**n) / 5**0.5))
return int(round((PHI**n - (1 - PHI)**n) / 5**0.5))


# Setup
Expand Down Expand Up @@ -110,7 +110,7 @@ def calculate_expression(expression, formula=None, **params):
result = 0
ret[coin] = result
except Exception as e:
#logging.exception(e)
# logging.exception(e)
raise FormulaParsingError(formula)
return ret

Expand Down Expand Up @@ -304,4 +304,5 @@ def first_login_check(sender, **kwargs):
except InvalidFormula:
logging.error('Formula start points is missing')


signals.addActivity.connect(first_login_check)
6 changes: 3 additions & 3 deletions wouso/core/scoring/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
self.coin = Coin.add('_test')

def tearDown(self):
#self.user.delete()
# self.user.delete()
self.game.delete()
self.coin.delete()

Expand Down Expand Up @@ -142,7 +142,7 @@ def test_update_points_level_upgrade_back(self):
player.points = level_up_points - 1
player.save()
update_points(player, None)
#Upgrade player's level back
# Upgrade player's level back
player.points = level_up_points + 1
player.save()
update_points(player, None)
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_first_login_points(self):
self.assertEqual(player.points, 0)

# this won't work, since the activity is sent in our custom view
#self.client.login(username=player.user.username, password='test')
# self.client.login(username=player.user.username, password='test')
# using this instead
signals.addActivity.send(sender=None, user_from=player, action="login", game=None, public=False)

Expand Down
10 changes: 5 additions & 5 deletions wouso/core/security/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Report(models.Model):
)

user_from = models.ForeignKey(Player, related_name="user_reporting")
user_to = models.ForeignKey(Player, related_name="user_reported")
dibs = models.ForeignKey(Player, related_name="dibs", null=True, blank=True)
user_to = models.ForeignKey(Player, related_name="user_reported")
dibs = models.ForeignKey(Player, related_name="dibs", null=True, blank=True)
timestamp = models.DateTimeField()
status = models.CharField(max_length=1, choices=STATUS, default='R')
text = models.CharField(max_length=250)
extra = models.CharField(max_length=250, blank=True)
status = models.CharField(max_length=1, choices=STATUS, default='R')
text = models.CharField(max_length=250)
extra = models.CharField(max_length=250, blank=True)

def set_dibs(self, user_dibs):
self.dibs = user_dibs.get_extension(Player)
Expand Down
3 changes: 2 additions & 1 deletion wouso/core/security/sec.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Security(App):
@classmethod
def penalise(cls, player, formula, external_id=None):
coins = Coin.get('penalty')
if not coins is None:
if coins is not None:
score(user=player, game=None, formula=formula, external_id=external_id)

@classmethod
Expand All @@ -93,4 +93,5 @@ def activity_handler(cls, sender, **kwargs):
def do_security_check(sender, **kwargs):
Security.activity_handler(sender, **kwargs)


signals.addActivity.connect(do_security_check)
6 changes: 3 additions & 3 deletions wouso/core/security/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
scoring.setup_scoring()

def test_rule_challenge_was_set_up(self):
#run a challenge
# run a challenge
Challenge.WARRANTY = False
chall = Challenge.create(user_from=self.chall_user,
user_to=self.chall_user2, ignore_questions=True)
Expand All @@ -29,7 +29,7 @@ def test_rule_challenge_was_set_up(self):
chall.user_to.save()
chall.played()

#test penalty points
#20 is the default formula value for a chall-was-set-up
# test penalty points
# 20 is the default formula value for a chall-was-set-up
self.assertEqual(20,
scoring.History.user_coins(self.user2.player_related.get())['penalty'])
17 changes: 9 additions & 8 deletions wouso/core/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ def get_neighbours_from_top(self, count, user_race=None, spell_type=None):
else:
allUsers = [user for user in allUsers if user.race.name != user_race.name]

if len(allUsers) <= 2*count+1:
if len(allUsers) <= 2 * count + 1:
return allUsers

start = max(pos-count, 0)
start = max(pos - count, 0)
if pos + count >= len(allUsers):
start = len(allUsers)-2*count-1
start = len(allUsers) - 2 * count - 1

players = allUsers[start:start+2*count+1]
players = allUsers[start:start + 2 * count + 1]
return players

def get_division(self, count):
Expand Down Expand Up @@ -248,7 +248,7 @@ def _avatar(self):
return avatar

# special:
#@cached_method
# @cached_method
def get_extension(self, cls):
if self.__class__ is cls:
return self
Expand Down Expand Up @@ -318,9 +318,9 @@ def _race_name(self):
def save(self, **kwargs):
""" Clear cache for extensions
"""
#for k, v in self.EXTENSIONS.iteritems():
# drop_cache(self.get_extension, self, v)
#drop_cache(self.get_extension, self, self.__class__)
# for k, v in self.EXTENSIONS.iteritems():
# drop_cache(self.get_extension, self, v)
# drop_cache(self.get_extension, self, self.__class__)
drop_cache(self._race_name, self)
drop_cache(self._group, self)
update_display_name(self, save=False)
Expand Down Expand Up @@ -359,6 +359,7 @@ def user_post_save(sender, instance, **kwargs):
profile.save()
update_display_name(profile)


models.signals.post_save.connect(user_post_save, User)


Expand Down
8 changes: 4 additions & 4 deletions wouso/core/user/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def test_player_neighbours(self):
player.save()
v.append(player)

#check neighbours for first player in top
# check neighbours for first player in top
players = v[0].get_neighbours_from_top(2)
self.assertEqual(len(players), 5)
for i in range(0, 5):
self.assertEqual(players[i], v[i])

#check neighbours for middle player in top
# check neighbours for middle player in top
players = v[3].get_neighbours_from_top(2)
self.assertEqual(len(players), 5)
for i in range(0, 5):
self.assertEqual(players[i], v[i + 1])

#check neighbours for last player in top
# check neighbours for last player in top
players = v[6].get_neighbours_from_top(2)
self.assertEqual(len(players), 5)
for i in range(0, 5):
Expand Down Expand Up @@ -100,5 +100,5 @@ def test_nickname_update(self):

player.nickname = 'altc3va'
player.save()
#self.assertEqual(unicode(player), player.nickname)
# self.assertEqual(unicode(player), player.nickname)
self.assertEqual(player.full_name, player.nickname)
2 changes: 2 additions & 0 deletions wouso/games/challenge/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.contrib import admin
from wouso.games.challenge.models import Challenge, ChallengeUser, Participant


class ChallengeUserAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'last_launched')


admin.site.register(Challenge)
admin.site.register(Participant)
admin.site.register(ChallengeUser, ChallengeUserAdmin)
2 changes: 1 addition & 1 deletion wouso/games/challenge/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def read(self, request, challenge_id, action='play'):
'questions': dict(
[(q.id, {'text': q, 'answers': dict([(a.id, a) for a in q.answers])}) for q in
challenge.questions.all()]),
}
}

if action == 'refuse':
if challenge.user_to.user == challuser and challenge.is_launched():
Expand Down
5 changes: 3 additions & 2 deletions wouso/games/challenge/cpanel_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf.urls import patterns, url
from django.conf.urls import patterns, url

urlpatterns = patterns('wouso.games.challenge.cpanel_views',
urlpatterns = patterns(
'wouso.games.challenge.cpanel_views',
url(r'^$', 'list_challenges', name='list_challenges'),
)
4 changes: 3 additions & 1 deletion wouso/games/challenge/cpanel_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from wouso.core.decorators import staff_required
from wouso.games.challenge.models import Challenge


class ListChallenges(ListView):
model = Challenge
paginate_by = 50
context_object_name = 'challenges'
template_name = 'challenge/cpanel/list_challenges.html'

def get_queryset(self):
return self.model.objects.all().order_by('-date')


list_challenges = staff_required(ListChallenges.as_view())
9 changes: 5 additions & 4 deletions wouso/games/challenge/forms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django import forms


class ChallengeForm(forms.Form):
def __init__(self, challenge, data=None):
super(ChallengeForm, self).__init__(data)

for q in challenge.questions.all():
field = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, label=q)
field.choices = [(a.id, a) for a in q.shuffled_answers]
self.fields['answer_{id}'.format(id = q.id)] = field
self.fields['answer_{id}'.format(id=q.id)] = field
self.data = data

def get_response(self):
Expand All @@ -21,8 +22,8 @@ def get_response(self):
adding an empty list to dic in this case"""
for field in self.visible_fields():
id = int(field.html_name[len('answer_'):])
if not id in res:

if id not in res:
res[id] = []
return res

Expand All @@ -41,4 +42,4 @@ def get_results_in_order(self, results):
for field in self.visible_fields():
id = int(field.html_name[len('answer_'):])
v.append(results[id])
return v
return v
Loading