<commit_before>from django.conf import settings
from django.contrib import admin, messages
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.gis.admin import GeoModelAdmin
from django.contrib.gis.forms import OSMWidget
from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from services.models import Provider, Service, ServiceArea, SelectionCriterion, ProviderType, \
    ServiceType, JiraUpdateRecord
from services.utils import validation_error_as_text


class ProviderAdmin(admin.ModelAdmin):
    list_display = ['name_en', 'name_ar', 'name_fr', 'type']


class ProviderTypeAdmin(admin.ModelAdmin):
    list_display = ['name_en', 'name_ar', 'name_fr']


class ServiceTypeAdmin(admin.ModelAdmin):
    list_display = ['number',
                    'name_en', 'name_ar', 'name_fr',
                    'comments_en', 'comments_ar', 'comments_ar']


class SelectionCriterionAdmin(admin.ModelAdmin):
    list_display = ['service', 'text_en', 'text_ar', 'text_fr']


class SelectionCriterionInlineAdmin(admin.TabularInline):
    model = SelectionCriterion

    # Staff can't add/delete criteria here, just edit the ones that are there:
    can_delete = False
    extra = 0
    max_num = 0
    # (Though if they're clever, they can go to the admin for selection criteria
    # and create or edit one there that links to the service.)


class OurOSMWidget(OSMWidget):
    # Use our own template that actually respects 'default_zoom'
    template_name = 'admin/osm-map.html'

    # The GeoModelAdmin.get_map_widget will subclass this widget class
    # and put a lot of config into an attribute 'params'. But the render
    # method of OSMWidget never looks at 'params'... Sigh.
    def render(self, name, value, attrs=None):
        if attrs:
            self.params.update(attrs)
        return super().render(name, value, attrs=self.params)

    # The __init__ of OSMWidget does some messing around with
    # its attrs and args for default_lon and default_lat. I don't
    # feel like trying to figure that out, so just bypass it.
    def __init__(self, attrs=None):
        # Yes, we are deliberately NOT invoking OSMWidget's own __init__
        super(OSMWidget, self).__init__(attrs)
<commit_msg>290 Fix map not working on staging in admin<commit_after>from django.conf import settings
from django.contrib import admin, messages
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.contrib.gis.admin import GeoModelAdmin
from django.contrib.gis.forms import OSMWidget
from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from services.models import Provider, Service, ServiceArea, SelectionCriterion, ProviderType, \
    ServiceType, JiraUpdateRecord
from services.utils import validation_error_as_text


class ProviderAdmin(admin.ModelAdmin):
    list_display = ['name_en', 'name_ar', 'name_fr', 'type']


class ProviderTypeAdmin(admin.ModelAdmin):
    list_display = ['name_en', 'name_ar', 'name_fr']


class ServiceTypeAdmin(admin.ModelAdmin):
    list_display = ['number',
                    'name_en', 'name_ar', 'name_fr',
                    'comments_en', 'comments_ar', 'comments_ar']


class SelectionCriterionAdmin(admin.ModelAdmin):
    list_display = ['service', 'text_en', 'text_ar', 'text_fr']


class SelectionCriterionInlineAdmin(admin.TabularInline):
    model = SelectionCriterion

    # Staff can't add/delete criteria here, just edit the ones that are there:
    can_delete = False
    extra = 0
    max_num = 0
    # (Though if they're clever, they can go to the admin for selection criteria
    # and create or edit one there that links to the service.)


class OurOSMWidget(OSMWidget):
    # Use our own template that actually respects 'default_zoom'
    template_name = 'admin/osm-map.html'

    # Use CDN for openlayers, and http or https as appropriate.
    class Media:
        extend = False  # We want to replace OSMWidget's media, not add to it
        js = (
            '//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js',
            '//www.openstreetmap.org/openlayers/OpenStreetMap.js',
            'gis/js/OLMapWidget.js',
        )


    # The GeoModelAdmin.get_map_widget will subclass this widget class
    # and put a lot of config into an attribute 'params'. But the render
    # method of OSMWidget never looks at 'params'... Sigh.
    def render(self, name, value, attrs=None):
        if attrs:
            self.params.update(attrs)
        return super().render(name, value, attrs=self.params)

    # The __init__ of OSMWidget does some messing around with
    # its attrs and args for default_lon and default_lat. I don't
    # feel like trying to figure that out, so just bypass it.
    def __init__(self, attrs=None):
        # Yes, we are deliberately NOT invoking OSMWidget's own __init__
        super(OSMWidget, self).__init__(attrs)

{'fraction_non_alphanumeric': 0.08490566037735849, 'fraction_numerical': 0.002161949685534591, 'mean_word_length': 3.7076780758556893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3051923', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1443, 'n_words': 476}