mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Merge pull request #134 from c17r/user-templates
Smallest/Fastest/Easiest/Least Invasive way to get custom templates
This commit is contained in:
commit
e6719eedc1
8 changed files with 72 additions and 4 deletions
|
|
@ -31,6 +31,9 @@ class AvatarConf(AppConf):
|
|||
FACEBOOK_GET_ID = None
|
||||
CACHE_ENABLED = True
|
||||
RANDOMIZE_HASHES = False
|
||||
ADD_TEMPLATE = ''
|
||||
CHANGE_TEMPLATE = ''
|
||||
DELETE_TEMPLATE = ''
|
||||
|
||||
def configure_auto_generate_avatar_sizes(self, value):
|
||||
return value or getattr(settings, 'AVATAR_AUTO_GENERATE_SIZES',
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ def add(request, extra_context=None, next_override=None,
|
|||
'next': next_override or _get_next(request),
|
||||
}
|
||||
context.update(extra_context)
|
||||
return render(request, 'avatar/add.html', context)
|
||||
template_name = settings.AVATAR_ADD_TEMPLATE or 'avatar/add.html'
|
||||
return render(request, template_name, context)
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
@ -120,7 +121,8 @@ def change(request, extra_context=None, next_override=None,
|
|||
'next': next_override or _get_next(request)
|
||||
}
|
||||
context.update(extra_context)
|
||||
return render(request, 'avatar/change.html', context)
|
||||
template_name = settings.AVATAR_CHANGE_TEMPLATE or 'avatar/change.html'
|
||||
return render(request, template_name, context)
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
@ -155,8 +157,8 @@ def delete(request, extra_context=None, next_override=None, *args, **kwargs):
|
|||
'next': next_override or _get_next(request),
|
||||
}
|
||||
context.update(extra_context)
|
||||
|
||||
return render(request, 'avatar/confirm_delete.html', context)
|
||||
template_name = settings.AVATAR_DELETE_TEMPLATE or 'avatar/confirm_delete.html'
|
||||
return render(request, template_name, context)
|
||||
|
||||
|
||||
def render_primary(request, user=None, size=settings.AVATAR_DEFAULT_SIZE):
|
||||
|
|
|
|||
|
|
@ -170,6 +170,15 @@ AVATAR_STORAGE_DIR
|
|||
non-filesystem storage device, this will simply be appended to the beginning
|
||||
of the file name. Defaults to ``avatars``.
|
||||
|
||||
AVATAR_ADD_TEMPLATE
|
||||
Path to the Django template to use for adding a new avatar. Defaults to ``avatar/add.html``.
|
||||
|
||||
AVATAR_CHANGE_TEMPLATE
|
||||
Path to the Django template to use for changing a user's avatar. Defaults to ``avatar/change.html``.
|
||||
|
||||
AVATAR_DELETE_TEMPLATE
|
||||
Path to the Django template to use for confirming a delete of a user's avatar. Defaults to ``avatar/avatar/confirm_delete.html``.
|
||||
|
||||
Management Commands
|
||||
-------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import os
|
||||
import django
|
||||
|
||||
VERSION = django.VERSION
|
||||
SETTINGS_DIR = os.path.dirname(__file__)
|
||||
|
||||
DATABASE_ENGINE = 'sqlite3'
|
||||
|
||||
DATABASES = {
|
||||
|
|
@ -25,6 +29,20 @@ MIDDLEWARE_CLASSES = (
|
|||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
)
|
||||
|
||||
if VERSION[0] == 1 and VERSION[1] < 8:
|
||||
TEMPLATE_DIRS = (
|
||||
os.path.join(SETTINGS_DIR, 'templates'),
|
||||
)
|
||||
else:
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'APP_DIRS': True,
|
||||
'DIRS': [
|
||||
os.path.join(SETTINGS_DIR, 'templates')
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'tests.urls'
|
||||
|
||||
|
|
|
|||
1
tests/templates/alt/add.html
Normal file
1
tests/templates/alt/add.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTERNATE ADD TEMPLATE
|
||||
1
tests/templates/alt/change.html
Normal file
1
tests/templates/alt/change.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTERNATE CHANGE TEMPLATE
|
||||
1
tests/templates/alt/delete.html
Normal file
1
tests/templates/alt/delete.html
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTERNATE DELETE TEMPLATE
|
||||
|
|
@ -210,6 +210,39 @@ class AvatarTests(TestCase):
|
|||
self.assertIn('<img src="{}"'.format(avatar.avatar_url(100)), result)
|
||||
self.assertIn('alt="test" width="100" height="100" />', result)
|
||||
|
||||
def test_default_add_template(self):
|
||||
response = self.client.get('/avatar/add/')
|
||||
self.assertContains(response, 'Upload New Image')
|
||||
self.assertNotContains(response, 'ALTERNATE ADD TEMPLATE')
|
||||
|
||||
@override_settings(AVATAR_ADD_TEMPLATE='alt/add.html')
|
||||
def test_custom_add_template(self):
|
||||
response = self.client.get('/avatar/add/')
|
||||
self.assertNotContains(response, 'Upload New Image')
|
||||
self.assertContains(response, 'ALTERNATE ADD TEMPLATE')
|
||||
|
||||
def test_default_change_template(self):
|
||||
response = self.client.get('/avatar/change/')
|
||||
self.assertContains(response, 'Upload New Image')
|
||||
self.assertNotContains(response, 'ALTERNATE CHANGE TEMPLATE')
|
||||
|
||||
@override_settings(AVATAR_CHANGE_TEMPLATE='alt/change.html')
|
||||
def test_custom_change_template(self):
|
||||
response = self.client.get('/avatar/change/')
|
||||
self.assertNotContains(response, 'Upload New Image')
|
||||
self.assertContains(response, 'ALTERNATE CHANGE TEMPLATE')
|
||||
|
||||
def test_default_delete_template(self):
|
||||
response = self.client.get('/avatar/delete/')
|
||||
self.assertContains(response, 'like to delete.')
|
||||
self.assertNotContains(response, 'ALTERNATE DELETE TEMPLATE')
|
||||
|
||||
@override_settings(AVATAR_DELETE_TEMPLATE='alt/delete.html')
|
||||
def test_custom_delete_template(self):
|
||||
response = self.client.get('/avatar/delete/')
|
||||
self.assertNotContains(response, 'like to delete.')
|
||||
self.assertContains(response, 'ALTERNATE DELETE TEMPLATE')
|
||||
|
||||
# def testAvatarOrder
|
||||
# def testReplaceAvatarWhenMaxIsOne
|
||||
# def testHashFileName
|
||||
|
|
|
|||
Loading…
Reference in a new issue