Skip to content

Commit

Permalink
Merge pull request #871 from PopAdi/pep8-code-indent
Browse files Browse the repository at this point in the history
pep8 code indentation: core folder
  • Loading branch information
iulianR committed Mar 8, 2016
2 parents ae7dff3 + d52297d commit b2a8b98
Show file tree
Hide file tree
Showing 39 changed files with 254 additions and 176 deletions.
4 changes: 2 additions & 2 deletions wouso/core/__init__.py
@@ -1,16 +1,15 @@
import warnings, logging, sys
from functools import wraps

from django.contrib import messages
from django.contrib.auth import logout
from django.contrib.auth.signals import user_logged_in
from django.shortcuts import redirect
from django.utils.translation import ugettext as _

from wouso.core.config.models import BoolSetting

logger = logging.getLogger('core')


def deprecated(message):
""" Mark function as deprecated.
Expand All @@ -27,6 +26,7 @@ def wrapper(*args, **kwargs):
return wrapper
return decorator


def block_if_not_staff(sender, user, request, **kwargs):
only_staff = not BoolSetting.get('login').get_value()
if only_staff and not user.is_staff:
Expand Down
5 changes: 3 additions & 2 deletions wouso/core/common.py
@@ -1,6 +1,7 @@
from django.core.cache import cache
import sys


class App:
""" Interface extended by Game and by Top and Qproposal Activity"""

Expand Down Expand Up @@ -78,7 +79,7 @@ def management_task(cls, datetime=lambda: datetime.now(), stdout=sys.stdout):
"""
pass

management_task = None # Disable it by default
management_task = None # Disable it by default


class Item(object):
Expand Down Expand Up @@ -167,4 +168,4 @@ def get(cls, part):
return obj

def __str__(self):
return str(getattr(self, self.CACHE_PART))
return str(getattr(self, self.CACHE_PART))
1 change: 1 addition & 0 deletions wouso/core/config/admin.py
@@ -1,6 +1,7 @@
from django.contrib import admin
from models import Setting


class SettingAdmin(admin.ModelAdmin):
list_display = ('name', 'value')

Expand Down
5 changes: 3 additions & 2 deletions wouso/core/config/tests.py
Expand Up @@ -2,12 +2,13 @@
from django.core.cache import cache
from models import Setting, BoolSetting, HTMLSetting, ChoicesSetting


class TestSettings(TestCase):
def setUp(self):
cache.clear()

def test_setting_type(self):
a = BoolSetting.get('test-name') # automatically created
a = BoolSetting.get('test-name') # automatically created

self.assertTrue(a)
self.assertIsInstance(a, Setting)
Expand Down Expand Up @@ -48,4 +49,4 @@ def test_setting_unicode(self):
self.assertEqual(a.__unicode__(), 'test')

a.set_value('e')
self.assertEqual(a.get_value(), 'e')
self.assertEqual(a.get_value(), 'e')
4 changes: 3 additions & 1 deletion wouso/core/decorators.py
Expand Up @@ -4,6 +4,7 @@
import inspect
import logging


def staff_required(function=None, login_url=None):
"""
Require current user to be logged in, have a profile, and be in staff group.
Expand All @@ -16,6 +17,7 @@ def staff_required(function=None, login_url=None):
return actual_decorator(function)
return actual_decorator


def api_enabled_required(function=None):

def _dec(function):
Expand All @@ -40,7 +42,7 @@ def _view(request, *args, **kwargs):
def _get_cache_key(function, *args, **kwargs):
params = inspect.getargspec(function)[0]
cache_key = 'F-%s-' % function.__name__
for i,param_name in enumerate(params):
for i, param_name in enumerate(params):
if i < len(args):
value = args[i]
else:
Expand Down
1 change: 1 addition & 0 deletions wouso/core/game/__init__.py
@@ -1,6 +1,7 @@
from django.db.models import get_models
from models import Game


def get_games():
"""Get a list of available games. This needs to be updated each time
a game is added."""
Expand Down
3 changes: 2 additions & 1 deletion wouso/core/game/management/commands/wousocron.py
Expand Up @@ -3,6 +3,7 @@
from wouso.core.game import get_games
from wouso.core.config.models import Setting


class Command(BaseCommand):
help = 'Wouso repetitive tasks (cron)'

Expand All @@ -26,4 +27,4 @@ def handle(self, *args, **options):

now = datetime.now()
Setting.get('wousocron_lastrun').set_value('%s' % now)
self.stdout.write('Finished at: %s\n' % now)
self.stdout.write('Finished at: %s\n' % now)
70 changes: 35 additions & 35 deletions wouso/core/game/management/commands/wousoctl.py
Expand Up @@ -22,47 +22,47 @@ class Command(BaseCommand):
help = 'Wouso management tasks'
option_list = DumpdataCommand.option_list + (
make_option('--check-setup',
action='store_true',
dest='check_setup',
default=False,
help='Check the current instance for scoring, artifacts and other running requirements.'
),
action='store_true',
dest='check_setup',
default=False,
help='Check the current instance for scoring, artifacts and other running requirements.'
),
make_option('--setup',
action='store_true',
dest='setup',
default=False,
help='Setup the current instance, including a syncdb.'
),
action='store_true',
dest='setup',
default=False,
help='Setup the current instance, including a syncdb.'
),
make_option('--noinput',
action='store_true',
dest='noinput',
default=False,
help='Don\'t ask for input'
),
action='store_true',
dest='noinput',
default=False,
help='Don\'t ask for input'
),
make_option('--load',
action='store',
dest='load',
default=False,
help='Load game configuration.'
),
action='store',
dest='load',
default=False,
help='Load game configuration.'
),
make_option('--save',
action='store',
dest='save',
default=False,
help='Save game configuration to a file.'
),
action='store',
dest='save',
default=False,
help='Save game configuration to a file.'
),
make_option('--reset',
action='store_true',
dest='reset',
default=False,
help='Reset scoring and artifacts'
),
action='store_true',
dest='reset',
default=False,
help='Reset scoring and artifacts'
),
make_option('--update-display',
action='store_true',
dest='updatedisplay',
default=False,
help='Update display names according to config'
),
action='store_true',
dest='updatedisplay',
default=False,
help='Update display names according to config'
),
)

def handle(self, *args, **options):
Expand Down
2 changes: 2 additions & 0 deletions wouso/core/game/tests.py
Expand Up @@ -2,10 +2,12 @@
from django.test import TestCase
from models import Game


class TestGame(Game):
class Meta:
proxy = True


class TestGameModule(TestCase):
def test_game_instance(self):
gi = TestGame.get_instance()
Expand Down
3 changes: 2 additions & 1 deletion wouso/core/god/god.py
Expand Up @@ -118,7 +118,8 @@ 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
6 changes: 0 additions & 6 deletions wouso/core/god/tests.py
@@ -1,13 +1,10 @@
import unittest

from django.contrib.auth.models import User
from django.test import TestCase

from wouso.core.config.models import IntegerListSetting
from wouso.core.magic.models import NoArtifactLevel
from wouso.core.user.models import PlayerGroup, Race
from wouso.games.challenge.models import ChallengeGame

from . import get_god


Expand Down Expand Up @@ -67,7 +64,6 @@ def test_users_are_elligible_for_challenge(self):
self.player.save()
self.assertTrue(god.user_is_eligible(self.player, ChallengeGame))


def test_user_can_interact_with_users(self):
user2 = User.objects.create(username='testgod2')
player2 = user2.get_profile()
Expand All @@ -76,7 +72,6 @@ def test_user_can_interact_with_users(self):

self.assertTrue(god.user_can_interact_with(self.player, player2))


@unittest.expectedFailure
def test_user_can_interact_with_unaffiliated(self):
user2 = User.objects.create(username='testgod2')
Expand All @@ -87,4 +82,3 @@ def test_user_can_interact_with_unaffiliated(self):
god = get_god()

self.assertFalse(god.user_can_interact_with(self.player, player2))

1 change: 1 addition & 0 deletions wouso/core/magic/admin.py
@@ -1,6 +1,7 @@
from django.contrib import admin
from models import Artifact, ArtifactGroup, Spell


class SpellAdmin(admin.ModelAdmin):
list_display = ('name', 'title', 'type', 'percents', 'price', 'level_required', 'available', 'mass')
admin.site.register(Artifact)
Expand Down
8 changes: 5 additions & 3 deletions wouso/core/magic/default_setup.py
@@ -1,5 +1,6 @@
import sys
sys.path.append('..');sys.path.append('.')
sys.path.append('..')
sys.path.append('.')

from django.core.management import setup_environ
import settings
Expand All @@ -9,6 +10,7 @@
from wouso.core.magic.models import *
from wouso.core.user.models import Player


if __name__ == '__main__':
print 'Setting up the Artifacts...',

Expand All @@ -23,8 +25,8 @@
# Create a default group
default_group, new = ArtifactGroup.objects.get_or_create(name='Default')
for i in range(7):
name='level-%d' % (i + 1)
title='Level %d' % (i + 1)
name = 'level-%d' % (i + 1)
title = 'Level %d' % (i + 1)
for g in (default_group, ca, cb, cc):
Artifact.objects.get_or_create(
name=name,
Expand Down
12 changes: 9 additions & 3 deletions wouso/core/magic/manager.py
Expand Up @@ -6,8 +6,14 @@
from wouso.core.god import God
from wouso.core.magic.models import PlayerSpellDue, PlayerSpellAmount, PlayerArtifactAmount

class MagicException(Exception): pass
class InsufficientAmount(MagicException): pass

class MagicException(Exception):
pass


class InsufficientAmount(MagicException):
pass


class MagicManager(object):
def __init__(self, player):
Expand Down Expand Up @@ -41,7 +47,7 @@ def spell_amounts(self):

def filter_players_by_spell(self, players, spell):
if spell.type == 's':
return [ self.player ]
return [self.player]
elif spell.type == 'n':
try:
players.remove(self.player)
Expand Down
19 changes: 10 additions & 9 deletions wouso/core/magic/models.py
Expand Up @@ -20,8 +20,8 @@ class Meta:
abstract = True

name = models.CharField(max_length=100)
title = models.CharField(max_length=100) # Maturator
description = models.TextField(max_length=2000, null=True, blank=True) # Extended description
title = models.CharField(max_length=100) # Maturator
description = models.TextField(max_length=2000, null=True, blank=True) # Extended description
image = models.ImageField(upload_to=settings.MEDIA_ARTIFACTS_DIR, blank=True, null=True)

percents = models.IntegerField(default=100)
Expand All @@ -34,7 +34,7 @@ def path(self):
return os.path.join(settings.MEDIA_ARTIFACTS_URL, os.path.basename(str(self.image)))

if hasattr(self, 'group'):
return ("%s-%s" % (self.group if self.group else 'default', self.name)).lower()
return ("%s-%s" % (self.group if self.group else 'default', self.name)).lower()

return self.name.lower()

Expand All @@ -48,6 +48,7 @@ class ArtifactGroup(CachedItem, models.Model):
def __unicode__(self):
return self.name


class Artifact(CachedItem, Modifier):
""" The generic artifact model. This should contain the name (identifier) and group,
but also personalization such as: image (icon) and title
Expand Down Expand Up @@ -86,12 +87,12 @@ class Spell(Modifier):
TYPES = (('o', 'neutral'), ('p', 'positive'), ('n', 'negative'), ('s', 'self'))

type = models.CharField(max_length=1, choices=TYPES, default='o')
due_days = models.IntegerField(default=5) # How many days may the spell be active
mass = models.BooleanField(default=False) # Apply spell on many players at once
due_days = models.IntegerField(default=5) # How many days may the spell be active
mass = models.BooleanField(default=False) # Apply spell on many players at once

price = models.FloatField(default=10) # Spell price in gold.
level_required = models.IntegerField(default=0) # Level required for buying this spell
available = models.BooleanField(default=True) # Spell can be bought in Bazaar
price = models.FloatField(default=10) # Spell price in gold.
level_required = models.IntegerField(default=0) # Level required for buying this spell
available = models.BooleanField(default=True) # Spell can be bought in Bazaar

@property
def group(self):
Expand Down Expand Up @@ -229,7 +230,7 @@ class Meta:
source = models.ForeignKey('user.Player', related_name='spell_source')
due = models.DateTimeField()

seen = models.BooleanField(default=False, blank=True) # if the target have seen it
seen = models.BooleanField(default=False, blank=True) # if the target have seen it

@staticmethod
def get_expired(date):
Expand Down
1 change: 0 additions & 1 deletion wouso/core/magic/templatetags/__init__.py
@@ -1 +0,0 @@

0 comments on commit b2a8b98

Please sign in to comment.