# coding: utf-8

from south.signals import post_migrate, pre_migrate

from new_django_project._lib.db import load_customized_sql

pre_migrate.connect(load_customized_sql(name='pre_migrate'), weak=False)
post_migrate.connect(load_customized_sql(name='post_migrate'), weak=False)
Beispiel #2
0
    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")
"""
    Computed client-side setting.
"""
settings.LEAFLET_CONFIG['SPATIAL_EXTENT'] = api_bbox(
    settings.SPATIAL_EXTENT, buffer=settings.VIEWPORT_MARGIN)
Beispiel #3
0
def base_content_pre_save_handler(sender, instance, **kwargs):
    if isinstance(instance, BaseContent) and not instance.id:
        calculate_class_name(instance)


def update_permission_handler(sender, instance, created, **kwargs):
    if Base in instance.__class__.mro():
        instance.populate_workflow_status()


signals.pre_save.connect(base_content_pre_save_handler)
signals.post_save.connect(update_permission_handler)
signals.post_save.connect(notify_status_changes)

pre_migrate.connect(pre_migrate_handler)
post_migrate.connect(post_migrate_handler)

max_file_size = getattr(settings, 'MERENGUE_MAX_FILE_SIZE', None)
max_image_size = getattr(settings, 'MERENGUE_MAX_IMAGE_SIZE', None)

if max_file_size or max_image_size:
    from django.forms.fields import FileField, ImageField, Field

    class MerengueFileField(Field):

        def clean(self, data):
            max_size = getattr(self, 'merengue_max_file_size', None)
            if data and max_size and len(data) > max_size:
                raise ValidationError(_('File to large. Max size restricted to %s bytes') % max_size)
            return super(MerengueFileField, self).clean(data)
Beispiel #4
0
    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")


"""
    Computed client-side setting.
"""
settings.LEAFLET_CONFIG['SPATIAL_EXTENT'] = api_bbox(settings.SPATIAL_EXTENT, buffer=0.5)
Beispiel #5
0
def setup_handlers():
    ran_migration.connect(callback_ran_migration)
    pre_migrate.connect(callback_pre_migrate)
    post_migrate.connect(callback_post_migrate)