Made some pep8 fixes

This commit is contained in:
Griatch 2018-10-22 23:32:12 +02:00
parent b414eadff2
commit e1431dca94
4 changed files with 113 additions and 103 deletions

View file

@ -5,12 +5,9 @@ from unittest import TestCase
from django.test import override_settings from django.test import override_settings
from evennia.accounts.accounts import AccountSessionHandler from evennia.accounts.accounts import AccountSessionHandler
from evennia.accounts.accounts import DefaultAccount from evennia.accounts.accounts import DefaultAccount
from evennia.server.session import Session
from evennia.utils import create from evennia.utils import create
from evennia.utils.test_resources import EvenniaTest from evennia.utils.test_resources import EvenniaTest
from django.conf import settings
class TestAccountSessionHandler(TestCase): class TestAccountSessionHandler(TestCase):
"Check AccountSessionHandler class" "Check AccountSessionHandler class"
@ -73,7 +70,7 @@ class TestDefaultAccount(TestCase):
self.account = create.create_account("TestAccount%s" % randint(100000, 999999), self.account = create.create_account("TestAccount%s" % randint(100000, 999999),
email="test@test.com", password="testpassword", typeclass=DefaultAccount) email="test@test.com", password="testpassword", typeclass=DefaultAccount)
self.assertTrue(self.account.web_get_detail_url()) self.assertTrue(self.account.web_get_detail_url())
def test_admin_url(self): def test_admin_url(self):
"Get object's URL for access via Admin pane" "Get object's URL for access via Admin pane"
self.account = create.create_account("TestAccount%s" % randint(100000, 999999), self.account = create.create_account("TestAccount%s" % randint(100000, 999999),
@ -211,17 +208,18 @@ class TestDefaultAccount(TestCase):
class TestAccountPuppetDeletion(EvenniaTest): class TestAccountPuppetDeletion(EvenniaTest):
@override_settings(MULTISESSION_MODE=2) @override_settings(MULTISESSION_MODE=2)
def test_puppet_deletion(self): def test_puppet_deletion(self):
# Check for existing chars # Check for existing chars
self.assertFalse(self.account.db._playable_characters, 'Account should not have any chars by default.') self.assertFalse(self.account.db._playable_characters, 'Account should not have any chars by default.')
# Add char1 to account's playable characters # Add char1 to account's playable characters
self.account.db._playable_characters.append(self.char1) self.account.db._playable_characters.append(self.char1)
self.assertTrue(self.account.db._playable_characters, 'Char was not added to account.') self.assertTrue(self.account.db._playable_characters, 'Char was not added to account.')
# See what happens when we delete char1. # See what happens when we delete char1.
self.char1.delete() self.char1.delete()
# Playable char list should be empty. # Playable char list should be empty.
self.assertFalse(self.account.db._playable_characters, 'Playable character list is not empty! %s' % self.account.db._playable_characters) self.assertFalse(self.account.db._playable_characters,
'Playable character list is not empty! %s' % self.account.db._playable_characters)

View file

@ -7,15 +7,11 @@ entities.
""" """
import time import time
import inflect import inflect
import re
from builtins import object from builtins import object
from future.utils import with_metaclass from future.utils import with_metaclass
from collections import defaultdict from collections import defaultdict
from django.conf import settings from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from django.utils.text import slugify
from evennia.typeclasses.models import TypeclassBase from evennia.typeclasses.models import TypeclassBase
from evennia.typeclasses.attributes import NickHandler from evennia.typeclasses.attributes import NickHandler
@ -218,7 +214,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
@property @property
def is_connected(self): def is_connected(self):
# we get an error for objects subscribed to channels without this # we get an error for objects subscribed to channels without this
if self.account: # seems sane to pass on the account if self.account: # seems sane to pass on the account
return self.account.is_connected return self.account.is_connected
else: else:
return False return False
@ -328,7 +324,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
# look at 'an egg'. # look at 'an egg'.
self.aliases.add(singular, category="plural_key") self.aliases.add(singular, category="plural_key")
return singular, plural return singular, plural
def search(self, searchdata, def search(self, searchdata,
global_search=False, global_search=False,
use_nicks=True, use_nicks=True,
@ -922,7 +918,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
self.account.db._playable_characters = [x for x in self.account.db._playable_characters if x != self] self.account.db._playable_characters = [x for x in self.account.db._playable_characters if x != self]
for session in self.sessions.all(): for session in self.sessions.all():
self.account.unpuppet_object(session) self.account.unpuppet_object(session)
self.account = None self.account = None
for script in _ScriptDB.objects.get_all_scripts_on_obj(self): for script in _ScriptDB.objects.get_all_scripts_on_obj(self):

View file

@ -1,11 +1,12 @@
from evennia.utils.test_resources import EvenniaTest from evennia.utils.test_resources import EvenniaTest
class DefaultObjectTest(EvenniaTest): class DefaultObjectTest(EvenniaTest):
def test_urls(self): def test_urls(self):
"Make sure objects are returning URLs" "Make sure objects are returning URLs"
self.assertTrue(self.char1.get_absolute_url()) self.assertTrue(self.char1.get_absolute_url())
self.assertTrue('admin' in self.char1.web_get_admin_url()) self.assertTrue('admin' in self.char1.web_get_admin_url())
self.assertTrue(self.room1.get_absolute_url()) self.assertTrue(self.room1.get_absolute_url())
self.assertTrue('admin' in self.room1.web_get_admin_url()) self.assertTrue('admin' in self.room1.web_get_admin_url())

View file

@ -740,131 +740,146 @@ class TypedObject(SharedMemoryModel):
# #
# Web/Django methods # Web/Django methods
# #
def web_get_admin_url(self): def web_get_admin_url(self):
""" """
Returns the URI path for the Django Admin page for this object. Returns the URI path for the Django Admin page for this object.
ex. Account#1 = '/admin/accounts/accountdb/1/change/' ex. Account#1 = '/admin/accounts/accountdb/1/change/'
Returns: Returns:
path (str): URI path to Django Admin page for object. path (str): URI path to Django Admin page for object.
""" """
content_type = ContentType.objects.get_for_model(self.__class__) content_type = ContentType.objects.get_for_model(self.__class__)
return reverse("admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(self.id,)) return reverse("admin:%s_%s_change" % (content_type.app_label,
content_type.model), args=(self.id,))
@classmethod @classmethod
def web_get_create_url(cls): def web_get_create_url(cls):
""" """
Returns the URI path for a View that allows users to create new Returns the URI path for a View that allows users to create new
instances of this object. instances of this object.
ex. Chargen = '/characters/create/' ex. Chargen = '/characters/create/'
For this to work, the developer must have defined a named view somewhere For this to work, the developer must have defined a named view somewhere
in urls.py that follows the format 'modelname-action', so in this case in urls.py that follows the format 'modelname-action', so in this case
a named view of 'character-create' would be referenced by this method. a named view of 'character-create' would be referenced by this method.
ex. ex.
url(r'characters/create/', ChargenView.as_view(), name='character-create') url(r'characters/create/', ChargenView.as_view(), name='character-create')
If no View has been created and defined in urls.py, returns an If no View has been created and defined in urls.py, returns an
HTML anchor. HTML anchor.
This method is naive and simply returns a path. Securing access to This method is naive and simply returns a path. Securing access to
the actual view and limiting who can create new objects is the the actual view and limiting who can create new objects is the
developer's responsibility. developer's responsibility.
Returns: Returns:
path (str): URI path to object creation page, if defined. path (str): URI path to object creation page, if defined.
""" """
try: return reverse('%s-create' % cls._meta.verbose_name.lower()) try:
except: return '#' return reverse('%s-create' % cls._meta.verbose_name.lower())
except:
return '#'
def web_get_detail_url(self): def web_get_detail_url(self):
""" """
Returns the URI path for a View that allows users to view details for Returns the URI path for a View that allows users to view details for
this object. this object.
ex. Oscar (Character) = '/characters/oscar/1/' ex. Oscar (Character) = '/characters/oscar/1/'
For this to work, the developer must have defined a named view somewhere
in urls.py that follows the format 'modelname-action', so in this case
a named view of 'character-detail' would be referenced by this method.
ex.
url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$', CharDetailView.as_view(), name='character-detail')
If no View has been created and defined in urls.py, returns an
HTML anchor.
This method is naive and simply returns a path. Securing access to
the actual view and limiting who can view this object is the developer's
responsibility.
Returns:
path (str): URI path to object detail page, if defined.
"""
try: return reverse('%s-detail' % self._meta.verbose_name.lower(), kwargs={'pk': self.pk, 'slug': slugify(self.name)})
except: return '#'
def web_get_update_url(self):
"""
Returns the URI path for a View that allows users to update this
object.
ex. Oscar (Character) = '/characters/oscar/1/change/'
For this to work, the developer must have defined a named view somewhere
in urls.py that follows the format 'modelname-action', so in this case
a named view of 'character-update' would be referenced by this method.
ex.
url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/change/$', CharUpdateView.as_view(), name='character-update')
If no View has been created and defined in urls.py, returns an
HTML anchor.
This method is naive and simply returns a path. Securing access to
the actual view and limiting who can modify objects is the developer's
responsibility.
Returns:
path (str): URI path to object update page, if defined.
"""
try: return reverse('%s-update' % self._meta.verbose_name.lower(), kwargs={'pk': self.pk, 'slug': slugify(self.name)})
except: return '#'
def web_get_delete_url(self):
"""
Returns the URI path for a View that allows users to delete this object.
ex. Oscar (Character) = '/characters/oscar/1/delete/'
For this to work, the developer must have defined a named view somewhere For this to work, the developer must have defined a named view somewhere
in urls.py that follows the format 'modelname-action', so in this case in urls.py that follows the format 'modelname-action', so in this case
a named view of 'character-detail' would be referenced by this method. a named view of 'character-detail' would be referenced by this method.
ex. ex.
url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/delete/$', CharDeleteView.as_view(), name='character-delete') url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$',
CharDetailView.as_view(), name='character-detail')
If no View has been created and defined in urls.py, returns an If no View has been created and defined in urls.py, returns an
HTML anchor. HTML anchor.
This method is naive and simply returns a path. Securing access to This method is naive and simply returns a path. Securing access to
the actual view and limiting who can delete this object is the developer's the actual view and limiting who can view this object is the developer's
responsibility. responsibility.
Returns:
path (str): URI path to object detail page, if defined.
"""
try:
return reverse('%s-detail' % self._meta.verbose_name.lower(),
kwargs={'pk': self.pk, 'slug': slugify(self.name)})
except:
return '#'
def web_get_update_url(self):
"""
Returns the URI path for a View that allows users to update this
object.
ex. Oscar (Character) = '/characters/oscar/1/change/'
For this to work, the developer must have defined a named view somewhere
in urls.py that follows the format 'modelname-action', so in this case
a named view of 'character-update' would be referenced by this method.
ex.
url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/change/$',
CharUpdateView.as_view(), name='character-update')
If no View has been created and defined in urls.py, returns an
HTML anchor.
This method is naive and simply returns a path. Securing access to
the actual view and limiting who can modify objects is the developer's
responsibility.
Returns:
path (str): URI path to object update page, if defined.
"""
try:
return reverse('%s-update' % self._meta.verbose_name.lower(),
kwargs={'pk': self.pk, 'slug': slugify(self.name)})
except:
return '#'
def web_get_delete_url(self):
"""
Returns the URI path for a View that allows users to delete this object.
ex. Oscar (Character) = '/characters/oscar/1/delete/'
For this to work, the developer must have defined a named view somewhere
in urls.py that follows the format 'modelname-action', so in this case
a named view of 'character-detail' would be referenced by this method.
ex.
url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/delete/$',
CharDeleteView.as_view(), name='character-delete')
If no View has been created and defined in urls.py, returns an
HTML anchor.
This method is naive and simply returns a path. Securing access to
the actual view and limiting who can delete this object is the developer's
responsibility.
Returns: Returns:
path (str): URI path to object deletion page, if defined. path (str): URI path to object deletion page, if defined.
""" """
try: return reverse('%s-delete' % self._meta.verbose_name.lower(), kwargs={'pk': self.pk, 'slug': slugify(self.name)}) try:
except: return '#' return reverse('%s-delete' % self._meta.verbose_name.lower(),
kwargs={'pk': self.pk, 'slug': slugify(self.name)})
except:
return '#'
# Used by Django Sites/Admin # Used by Django Sites/Admin
get_absolute_url = web_get_detail_url get_absolute_url = web_get_detail_url