port to new django, AI automated
This commit is contained in:
@@ -3,7 +3,9 @@ from django.db.models import CharField
|
||||
from location_field import forms
|
||||
|
||||
|
||||
class BaseLocationField(object):
|
||||
class BaseLocationField:
|
||||
"""Base class for location fields."""
|
||||
|
||||
def __init__(self, based_field=None, zoom=2, default=None, *args, **kwargs):
|
||||
self._based_field = based_field
|
||||
self._zoom = zoom
|
||||
@@ -11,29 +13,31 @@ class BaseLocationField(object):
|
||||
self.default = default
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
return super(BaseLocationField, self).formfield(
|
||||
return super().formfield(
|
||||
form_class=self.formfield_class,
|
||||
based_field=self._based_field,
|
||||
zoom=self._zoom,
|
||||
default=self._default,
|
||||
**kwargs)
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
class PlainLocationField(BaseLocationField, CharField):
|
||||
"""A CharField that stores location data as 'latitude,longitude,zoom'."""
|
||||
|
||||
formfield_class = forms.PlainLocationField
|
||||
|
||||
def __init__(self, based_field=None, zoom=None,
|
||||
max_length=63, *args, **kwargs):
|
||||
|
||||
super(PlainLocationField, self).__init__(based_field=based_field,
|
||||
zoom=zoom, *args, **kwargs)
|
||||
|
||||
def __init__(self, based_field=None, zoom=None, max_length=63, *args, **kwargs):
|
||||
BaseLocationField.__init__(
|
||||
self, based_field=based_field, zoom=zoom, *args, **kwargs
|
||||
)
|
||||
CharField.__init__(self, max_length=max_length, *args, **kwargs)
|
||||
|
||||
|
||||
# south compatibility
|
||||
try:
|
||||
from south.modelsinspector import add_introspection_rules
|
||||
add_introspection_rules([], ["^location_field\.models\.PlainLocationField"])
|
||||
except:
|
||||
pass
|
||||
def deconstruct(self):
|
||||
"""Return enough information to recreate the field."""
|
||||
name, path, args, kwargs = super().deconstruct()
|
||||
if self._based_field is not None:
|
||||
kwargs["based_field"] = self._based_field
|
||||
if self._zoom is not None:
|
||||
kwargs["zoom"] = self._zoom
|
||||
return name, path, args, kwargs
|
||||
|
||||
Reference in New Issue
Block a user