prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add requirement about projection units : should be meters
  http://gis.stackexchange.com/questions/85955/how-can-i-obtain-the-unit-of-a-projection-srid
  
  
  </issue>
  <code>
  [start of geotrek/common/__init__.py]
  1 """
  2 
  3     Geotrek startup script.
  4 
  5     This is executed only once at startup.
  6 
  7 """
  8 from south.signals import post_migrate
  9 from django.conf import settings
  10 from django.db.models.signals import post_syncdb
  11 
  12 from mapentity.helpers import api_bbox
  13 
  14 from geotrek.common.utils.postgresql import load_sql_files
  15 
  16 
  17 """
  18     http://djangosnippets.org/snippets/2311/
  19     Ensure South will update our custom SQL during a call to `migrate`.
  20 """
  21 
  22 def run_initial_sql_post_migrate(sender, **kwargs):
  23     app_label = kwargs.get('app')
  24     load_sql_files(app_label)
  25 
  26 
  27 def run_initial_sql_post_syncdb(sender, **kwargs):
  28     app = kwargs.get('app')
  29     models_module = app.__name__
  30     app_label = models_module.rsplit('.')[-2]
  31     load_sql_files(app_label)
  32 
  33 
  34 if settings.TEST and not settings.SOUTH_TESTS_MIGRATE:
  35     post_syncdb.connect(run_initial_sql_post_syncdb, dispatch_uid="geotrek.core.sqlautoload")
  36     # During tests, the signal is received twice unfortunately
  37     # https://code.djangoproject.com/ticket/17977
  38 else:
  39     post_migrate.connect(run_initial_sql_post_migrate, dispatch_uid="geotrek.core.sqlautoload")
  40 
  41 
  42 """
  43     Computed client-side setting.
  44 """
  45 settings.LEAFLET_CONFIG['SPATIAL_EXTENT'] = api_bbox(settings.SPATIAL_EXTENT, buffer=0.5)
  46
  [end of geotrek/common/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/geotrek/common/__init__.py b/geotrek/common/__init__.py
  --- a/geotrek/common/__init__.py
  +++ b/geotrek/common/__init__.py
  @@ -5,9 +5,11 @@
       This is executed only once at startup.
   
   """
  -from south.signals import post_migrate
  +from south.signals import pre_migrate, post_migrate
   from django.conf import settings
  -from django.db.models.signals import post_syncdb
  +from django.db import connection
  +from django.db.models.signals import pre_syncdb, post_syncdb
  +from django.core.exceptions import ImproperlyConfigured
   
   from mapentity.helpers import api_bbox
   
  @@ -31,11 +33,26 @@
       load_sql_files(app_label)
   
   
  +def check_srid_has_meter_unit(sender, **kwargs):
  +    if not hasattr(check_srid_has_meter_unit, '_checked'):
  +        cursor = connection.cursor()
  +        cursor.execute("""
  +            SELECT * FROM spatial_ref_sys
  +            WHERE srtext ILIKE '%%meter%%' AND srid=%s;""", [settings.SRID])
  +        results = cursor.fetchall()
  +        if len(results) == 0:
  +            err_msg = 'Unit of SRID EPSG:%s is not meter.' % settings.SRID
  +            raise ImproperlyConfigured(err_msg)
  +    check_srid_has_meter_unit._checked = True
  +
  +
   if settings.TEST and not settings.SOUTH_TESTS_MIGRATE:
  +    pre_syncdb.connect(check_srid_has_meter_unit, dispatch_uid="geotrek.core.checksrid")
       post_syncdb.connect(run_initial_sql_post_syncdb, dispatch_uid="geotrek.core.sqlautoload")
       # During tests, the signal is received twice unfortunately
       # https://code.djangoproject.com/ticket/17977
   else:
  +    pre_migrate.connect(check_srid_has_meter_unit, dispatch_uid="geotrek.core.checksrid")
       post_migrate.connect(run_initial_sql_post_migrate, dispatch_uid="geotrek.core.sqlautoload")
  
verification_info: {"golden_diff": "diff --git a/geotrek/common/__init__.py b/geotrek/common/__init__.py\n--- a/geotrek/common/__init__.py\n+++ b/geotrek/common/__init__.py\n@@ -5,9 +5,11 @@\n     This is executed only once at startup.\n \n \"\"\"\n-from south.signals import post_migrate\n+from south.signals import pre_migrate, post_migrate\n from django.conf import settings\n-from django.db.models.signals import post_syncdb\n+from django.db import connection\n+from django.db.models.signals import pre_syncdb, post_syncdb\n+from django.core.exceptions import ImproperlyConfigured\n \n from mapentity.helpers import api_bbox\n \n@@ -31,11 +33,26 @@\n     load_sql_files(app_label)\n \n \n+def check_srid_has_meter_unit(sender, **kwargs):\n+    if not hasattr(check_srid_has_meter_unit, '_checked'):\n+        cursor = connection.cursor()\n+        cursor.execute(\"\"\"\n+            SELECT * FROM spatial_ref_sys\n+            WHERE srtext ILIKE '%%meter%%' AND srid=%s;\"\"\", [settings.SRID])\n+        results = cursor.fetchall()\n+        if len(results) == 0:\n+            err_msg = 'Unit of SRID EPSG:%s is not meter.' % settings.SRID\n+            raise ImproperlyConfigured(err_msg)\n+    check_srid_has_meter_unit._checked = True\n+\n+\n if settings.TEST and not settings.SOUTH_TESTS_MIGRATE:\n+    pre_syncdb.connect(check_srid_has_meter_unit, dispatch_uid=\"geotrek.core.checksrid\")\n     post_syncdb.connect(run_initial_sql_post_syncdb, dispatch_uid=\"geotrek.core.sqlautoload\")\n     # During tests, the signal is received twice unfortunately\n     # https://code.djangoproject.com/ticket/17977\n else:\n+    pre_migrate.connect(check_srid_has_meter_unit, dispatch_uid=\"geotrek.core.checksrid\")\n     post_migrate.connect(run_initial_sql_post_migrate, dispatch_uid=\"geotrek.core.sqlautoload\")\n", "issue": "Add requirement about projection units : should be meters\nhttp://gis.stackexchange.com/questions/85955/how-can-i-obtain-the-unit-of-a-projection-srid\n\n", "before_files": [{"content": "\"\"\"\n\n    Geotrek startup script.\n\n    This is executed only once at startup.\n\n\"\"\"\nfrom south.signals import post_migrate\nfrom django.conf import settings\nfrom django.db.models.signals import post_syncdb\n\nfrom mapentity.helpers import api_bbox\n\nfrom geotrek.common.utils.postgresql import load_sql_files\n\n\n\"\"\"\n    http://djangosnippets.org/snippets/2311/\n    Ensure South will update our custom SQL during a call to `migrate`.\n\"\"\"\n\ndef run_initial_sql_post_migrate(sender, **kwargs):\n    app_label = kwargs.get('app')\n    load_sql_files(app_label)\n\n\ndef run_initial_sql_post_syncdb(sender, **kwargs):\n    app = kwargs.get('app')\n    models_module = app.__name__\n    app_label = models_module.rsplit('.')[-2]\n    load_sql_files(app_label)\n\n\nif settings.TEST and not settings.SOUTH_TESTS_MIGRATE:\n    post_syncdb.connect(run_initial_sql_post_syncdb, dispatch_uid=\"geotrek.core.sqlautoload\")\n    # During tests, the signal is received twice unfortunately\n    # https://code.djangoproject.com/ticket/17977\nelse:\n    post_migrate.connect(run_initial_sql_post_migrate, dispatch_uid=\"geotrek.core.sqlautoload\")\n\n\n\"\"\"\n    Computed client-side setting.\n\"\"\"\nsettings.LEAFLET_CONFIG['SPATIAL_EXTENT'] = api_bbox(settings.SPATIAL_EXTENT, buffer=0.5)\n", "path": "geotrek/common/__init__.py"}]}