diff --git a/evennia/accounts/tests.py b/evennia/accounts/tests.py index d60db0fce5..084e8a6a66 100644 --- a/evennia/accounts/tests.py +++ b/evennia/accounts/tests.py @@ -5,12 +5,9 @@ from unittest import TestCase from django.test import override_settings from evennia.accounts.accounts import AccountSessionHandler from evennia.accounts.accounts import DefaultAccount -from evennia.server.session import Session from evennia.utils import create from evennia.utils.test_resources import EvenniaTest -from django.conf import settings - class TestAccountSessionHandler(TestCase): "Check AccountSessionHandler class" @@ -73,7 +70,7 @@ class TestDefaultAccount(TestCase): self.account = create.create_account("TestAccount%s" % randint(100000, 999999), email="test@test.com", password="testpassword", typeclass=DefaultAccount) self.assertTrue(self.account.web_get_detail_url()) - + def test_admin_url(self): "Get object's URL for access via Admin pane" self.account = create.create_account("TestAccount%s" % randint(100000, 999999), @@ -211,17 +208,18 @@ class TestDefaultAccount(TestCase): class TestAccountPuppetDeletion(EvenniaTest): - + @override_settings(MULTISESSION_MODE=2) def test_puppet_deletion(self): # Check for existing chars self.assertFalse(self.account.db._playable_characters, 'Account should not have any chars by default.') - + # Add char1 to account's playable characters self.account.db._playable_characters.append(self.char1) self.assertTrue(self.account.db._playable_characters, 'Char was not added to account.') - + # See what happens when we delete char1. self.char1.delete() # 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) \ No newline at end of file + self.assertFalse(self.account.db._playable_characters, + 'Playable character list is not empty! %s' % self.account.db._playable_characters) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 7e1a13722e..919da40a7c 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -7,15 +7,11 @@ entities. """ import time import inflect -import re from builtins import object from future.utils import with_metaclass from collections import defaultdict 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.attributes import NickHandler @@ -218,7 +214,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): @property def is_connected(self): # 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 else: return False @@ -328,7 +324,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): # look at 'an egg'. self.aliases.add(singular, category="plural_key") return singular, plural - + def search(self, searchdata, global_search=False, 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] for session in self.sessions.all(): self.account.unpuppet_object(session) - + self.account = None for script in _ScriptDB.objects.get_all_scripts_on_obj(self): diff --git a/evennia/objects/tests.py b/evennia/objects/tests.py index 824007f287..2c014cbe77 100644 --- a/evennia/objects/tests.py +++ b/evennia/objects/tests.py @@ -1,11 +1,12 @@ from evennia.utils.test_resources import EvenniaTest + class DefaultObjectTest(EvenniaTest): - + def test_urls(self): "Make sure objects are returning URLs" self.assertTrue(self.char1.get_absolute_url()) self.assertTrue('admin' in self.char1.web_get_admin_url()) - + self.assertTrue(self.room1.get_absolute_url()) - self.assertTrue('admin' in self.room1.web_get_admin_url()) \ No newline at end of file + self.assertTrue('admin' in self.room1.web_get_admin_url()) diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index d549efb8ff..61dddc0c80 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -740,131 +740,146 @@ class TypedObject(SharedMemoryModel): # # Web/Django methods # - + def web_get_admin_url(self): """ Returns the URI path for the Django Admin page for this object. - + ex. Account#1 = '/admin/accounts/accountdb/1/change/' - + Returns: path (str): URI path to Django Admin page for object. - + """ 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 def web_get_create_url(cls): """ Returns the URI path for a View that allows users to create new instances of this object. - + ex. Chargen = '/characters/create/' - + 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-create' would be referenced by this method. - + ex. url(r'characters/create/', ChargenView.as_view(), name='character-create') - + 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 create new objects is the + the actual view and limiting who can create new objects is the developer's responsibility. - + Returns: path (str): URI path to object creation page, if defined. - + """ - try: return reverse('%s-create' % cls._meta.verbose_name.lower()) - except: return '#' - + try: + return reverse('%s-create' % cls._meta.verbose_name.lower()) + except: + return '#' + 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. - + 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[\w\d\-]+)/(?P[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[\w\d\-]+)/(?P[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[\w\d\-]+)/(?P[0-9]+)/delete/$', CharDeleteView.as_view(), name='character-delete') - + url(r'characters/(?P[\w\d\-]+)/(?P[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 delete this object is the developer's + 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[\w\d\-]+)/(?P[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[\w\d\-]+)/(?P[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: 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)}) - except: return '#' - + try: + return reverse('%s-delete' % self._meta.verbose_name.lower(), + kwargs={'pk': self.pk, 'slug': slugify(self.name)}) + except: + return '#' + # Used by Django Sites/Admin - get_absolute_url = web_get_detail_url \ No newline at end of file + get_absolute_url = web_get_detail_url