# Path: www/maposmatic/models.py
# class MapRenderingJobManager(models.Manager):
# class MapRenderingJob(models.Model):
#     def to_render(self):
#     def queue_size(self):
#     def get_random_with_thumbnail(self):
#     def get_by_filename(self, name):
#     def __str__(self):
#     def maptitle_computized(self):
#     def files_prefix(self):
#     def start_rendering(self):
#     def end_rendering(self, resultmsg):
#     def rendering_time_gt_1min(self):
#     def __is_ok(self):              return self.resultmsg == 'ok'
#     def is_waiting(self):           return self.status == 0
#     def is_rendering(self):         return self.status == 1
#     def needs_waiting(self):        return self.status  < 2
#     def is_done(self):              return self.status == 2
#     def is_done_ok(self):           return self.is_done() and self.__is_ok()
#     def is_done_failed(self):       return self.is_done() and not self.__is_ok()
#     def is_obsolete(self):          return self.status == 3
#     def is_obsolete_ok(self):       return self.is_obsolete() and self.__is_ok()
#     def is_obsolete_failed(self):   return self.is_obsolete() and not self.__is_ok()
#     def is_cancelled(self):         return self.status == 4
#     def can_recreate(self):
#     def get_map_fileurl(self, format):
#     def get_map_filepath(self, format):
#     def output_files(self):
#     def has_output_files(self):
#     def remove_all_files(self):
#     def cancel(self):
#     def get_thumbnail(self):
#     def current_position_in_queue(self):
#     def rendering_estimated_start_time(self):
#     def get_absolute_url(self):
# SPACE_REDUCE = re.compile(r"\s+")
# NONASCII_REMOVE = re.compile(r"[^A-Za-z0-9]+")
#     STATUS_LIST = (
#         (0, 'Submitted'),
#         (1, 'In progress'),
#         (2, 'Done'),
#         (3, 'Done w/o files'),
#         (4, 'Cancelled'),
#         )
#     NONCE_SIZE = 16
# 
# Path: www/maposmatic/widgets.py
# class AreaWidget(forms.TextInput):
# class AreaField(forms.MultiValueField):
#     def render(self, name, value, attrs=None):
#     def value_from_datadict(self, data, files, name):
#     def clean(self, value):
#     def compress(self, data_list):


from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from www.maposmatic import models, widgets
import time
import ocitysmap
import www.settings

            # Don't try to instanciate a bounding box with empty coordinates
            if self._errors:
                return cleaned_data

            lat_upper_left = cleaned_data.get("lat_upper_left")
            lon_upper_left = cleaned_data.get("lon_upper_left")
            lat_bottom_right = cleaned_data.get("lat_bottom_right")
            lon_bottom_right = cleaned_data.get("lon_bottom_right")

            boundingbox = ocitysmap.coords.BoundingBox(
                lat_upper_left, lon_upper_left,
                lat_bottom_right, lon_bottom_right)
            (metric_size_lat, metric_size_long) = boundingbox.spheric_sizes()
            if (metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS
                or metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS):
                msg = _(u"Bounding Box too large")
                self._errors['bbox'] = forms.util.ErrorList([msg])

        return cleaned_data

    def _check_osm_id(self, osm_id):
        """Make sure that the supplied OSM Id is valid and can be accepted for
        rendering (bounding box not too large, etc.). Raise an exception in
        case of error."""
        bbox_wkt, area_wkt = self._ocitysmap.get_geographic_info(osm_id)
        bbox = ocitysmap.coords.BoundingBox.parse_wkt(bbox_wkt)
        (metric_size_lat, metric_size_long) = bbox.spheric_sizes()
        if metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS or \
                metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS:

# Path: www/maposmatic/models.py
# class MapRenderingJobManager(models.Manager):
# class MapRenderingJob(models.Model):
#     def to_render(self):
#     def queue_size(self):
#     def get_random_with_thumbnail(self):
#     def get_by_filename(self, name):
#     def __str__(self):
#     def maptitle_computized(self):
#     def files_prefix(self):
#     def start_rendering(self):
#     def end_rendering(self, resultmsg):
#     def rendering_time_gt_1min(self):
#     def __is_ok(self):              return self.resultmsg == 'ok'
#     def is_waiting(self):           return self.status == 0
#     def is_rendering(self):         return self.status == 1
#     def needs_waiting(self):        return self.status  < 2
#     def is_done(self):              return self.status == 2
#     def is_done_ok(self):           return self.is_done() and self.__is_ok()
#     def is_done_failed(self):       return self.is_done() and not self.__is_ok()
#     def is_obsolete(self):          return self.status == 3
#     def is_obsolete_ok(self):       return self.is_obsolete() and self.__is_ok()
#     def is_obsolete_failed(self):   return self.is_obsolete() and not self.__is_ok()
#     def is_cancelled(self):         return self.status == 4
#     def can_recreate(self):
#     def get_map_fileurl(self, format):
#     def get_map_filepath(self, format):
#     def output_files(self):
#     def has_output_files(self):
#     def remove_all_files(self):
#     def cancel(self):
#     def get_thumbnail(self):
#     def current_position_in_queue(self):
#     def rendering_estimated_start_time(self):
#     def get_absolute_url(self):
# SPACE_REDUCE = re.compile(r"\s+")
# NONASCII_REMOVE = re.compile(r"[^A-Za-z0-9]+")
#     STATUS_LIST = (
#         (0, 'Submitted'),
#         (1, 'In progress'),
#         (2, 'Done'),
#         (3, 'Done w/o files'),
#         (4, 'Cancelled'),
#         )
#     NONCE_SIZE = 16
# 
# Path: www/maposmatic/widgets.py
# class AreaWidget(forms.TextInput):
# class AreaField(forms.MultiValueField):
#     def render(self, name, value, attrs=None):
#     def value_from_datadict(self, data, files, name):
#     def clean(self, value):
#     def compress(self, data_list):


# Path: www/maposmatic/forms.py
from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from www.maposmatic import models, widgets
import time
import ocitysmap
import www.settings


            # Don't try to instanciate a bounding box with empty coordinates
            if self._errors:
                return cleaned_data

            lat_upper_left = cleaned_data.get("lat_upper_left")
            lon_upper_left = cleaned_data.get("lon_upper_left")
            lat_bottom_right = cleaned_data.get("lat_bottom_right")
            lon_bottom_right = cleaned_data.get("lon_bottom_right")

            boundingbox = ocitysmap.coords.BoundingBox(
                lat_upper_left, lon_upper_left,
                lat_bottom_right, lon_bottom_right)
            (metric_size_lat, metric_size_long) = boundingbox.spheric_sizes()
            if (metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS
                or metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS):
                msg = _(u"Bounding Box too large")
                self._errors['bbox'] = forms.util.ErrorList([msg])

        return cleaned_data

    def _check_osm_id(self, osm_id):
        """Make sure that the supplied OSM Id is valid and can be accepted for
        rendering (bounding box not too large, etc.). Raise an exception in
        case of error."""
        bbox_wkt, area_wkt = self._ocitysmap.get_geographic_info(osm_id)
        bbox = ocitysmap.coords.BoundingBox.parse_wkt(bbox_wkt)
        (metric_size_lat, metric_size_long) = bbox.spheric_sizes()
        if metric_size_lat > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS or \
                metric_size_long > www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS:

            raise ValueError("Area too large")