<s> from __future__ import unicode_literals <EOL> from decimal import Decimal <EOL> from django import VERSION as DJANGO_VERSION <EOL> from django . core . exceptions import ValidationError <EOL> from django . db import models <EOL> from django . utils . six import with_metaclass <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . forms import LatLongField as FormLatLongField <EOL> if DJANGO_VERSION < ( <NUM_LIT:1> , <NUM_LIT:8> ) : <EOL> DjangoModelFieldBase = with_metaclass ( models . SubfieldBase , models . Field ) <EOL> else : <EOL> DjangoModelFieldBase = models . Field <EOL> class LatLong ( object ) : <EOL> def __init__ ( self , latitude = <NUM_LIT:0.0> , longitude = <NUM_LIT:0.0> ) : <EOL> self . latitude = Decimal ( latitude ) <EOL> self . longitude = Decimal ( longitude ) <EOL> @ staticmethod <EOL> def _equals_to_the_cent ( a , b ) : <EOL> return round ( a , <NUM_LIT:6> ) == round ( b , <NUM_LIT:6> ) <EOL> @ staticmethod <EOL> def _no_equals_to_the_cent ( a , b ) : <EOL> return round ( a , <NUM_LIT:6> ) != round ( b , <NUM_LIT:6> ) <EOL> @ property <EOL> def format_latitude ( self ) : <EOL> return '<STR_LIT>' . format ( self . latitude ) <EOL> @ property <EOL> def format_longitude ( self ) : <EOL> return '<STR_LIT>' . format ( self . longitude ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . __class__ . __name__ , self . latitude , self . longitude ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . latitude , self . longitude ) <EOL> def __eq__ ( self , other ) : <EOL> return isinstance ( other , LatLong ) and ( self . _equals_to_the_cent ( self . latitude , other . latitude ) and <EOL> self . _equals_to_the_cent ( self . longitude , other . longitude ) ) <EOL> def __ne__ ( self , other ) : <EOL> return isinstance ( other , LatLong ) and ( self . _no_equals_to_the_cent ( self . latitude , other . latitude ) or <EOL> self . _no_equals_to_the_cent ( self . longitude , other . longitude ) ) <EOL> class LatLongField ( DjangoModelFieldBase ) : <EOL> description = _ ( '<STR_LIT>' ) <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:max_length>' ] = <NUM_LIT> <EOL> super ( LatLongField , self ) . __init__ ( * args , ** kwargs ) <EOL> def get_internal_type ( self ) : <EOL> return '<STR_LIT>' <EOL> def to_python ( self , value ) : <EOL> if value is None : <EOL> return None <EOL> elif not value : <EOL> return LatLong ( ) <EOL> elif isinstance ( value , LatLong ) : <EOL> return value <EOL> else : <EOL> args = value . split ( '<STR_LIT:;>' ) <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> raise ValidationError ( <EOL> self . error_messages [ '<STR_LIT>' ] , code = '<STR_LIT>' , params = { '<STR_LIT:value>' : value } , <EOL> ) <EOL> return LatLong ( * args ) <EOL> def get_db_prep_value ( self , value , connection , prepared = False ) : <EOL> value = super ( LatLongField , self ) . get_prep_value ( value ) <EOL> if value is None : <EOL> return None <EOL> value = self . to_python ( value ) <EOL> return str ( value ) <EOL> def from_db_value ( self , value , expression , connection , context ) : <EOL> return self . to_python ( value ) <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { <EOL> '<STR_LIT>' : FormLatLongField , <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return super ( LatLongField , self ) . formfield ( ** defaults ) <EOL> try : <EOL> from south . modelsinspector import add_introspection_rules <EOL> add_introspection_rules ( [ ] , [ '<STR_LIT>' ] ) <EOL> except ImportError : <EOL> pass </s>
