1
- from django .contrib .contenttypes .generic import GenericForeignKey
1
+ from __future__ import unicode_literals
2
+
3
+ from django .contrib .contenttypes .fields import GenericForeignKey
2
4
from django .core .exceptions import ValidationError
3
5
from django .core .urlresolvers import reverse , resolve , NoReverseMatch , Resolver404
4
6
from django .db import models
5
7
from django .utils .translation import ugettext_lazy as _ , ugettext
8
+ # django/py3
9
+ from django .utils .encoding import python_2_unicode_compatible
6
10
7
- import settings
11
+ from urlmapper import settings
8
12
9
13
10
14
def _get_key_choices ():
@@ -16,7 +20,8 @@ def _get_key_choices():
16
20
)
17
21
if not keys :
18
22
return [('' , ugettext ("There are no defined keys" ))]
19
- return zip (keys , keys )
23
+
24
+ return list (zip (keys , keys ))
20
25
21
26
22
27
def _get_content_type_choices ():
@@ -38,6 +43,7 @@ def get_queryset(self):
38
43
return queryset .exclude (key__in = settings .URLMAPPER_FUNCTIONS .keys ())
39
44
40
45
46
+ @python_2_unicode_compatible
41
47
class URLMap (models .Model ):
42
48
"""
43
49
Map a key to a URL in the database. This could be a straight-up URL, an
@@ -91,7 +97,7 @@ class URLMap(models.Model):
91
97
objects = URLMapVisibleMananger ()
92
98
_objects = models .Manager ()
93
99
94
- def __unicode__ (self ):
100
+ def __str__ (self ):
95
101
return u"{key} --> {url}" .format (
96
102
key = self .key ,
97
103
url = self .get_url ()
@@ -223,6 +229,7 @@ def get_url(self):
223
229
if self .view_name :
224
230
return self ._get_view_url (raise_exception = False )
225
231
return ''
232
+
226
233
get_url .short_description = _ ('URL' )
227
234
228
235
def mapping_type (self ):
@@ -232,6 +239,7 @@ def mapping_type(self):
232
239
return _ ("Object" )
233
240
if self .view_name :
234
241
return _ ("View" )
242
+
235
243
mapping_type .short_description = _ ("Mapping type" )
236
244
237
245
class Meta :
0 commit comments