Пример #1
0
 def save(self, *args, **kwargs):
     auto_approve = Setting.get_value('auto_approve', 0)
     if auto_approve == 1:
         self.status = self.STATUS_APPROVED
     return super(ApprovedModelMixin, self).save(*args, **kwargs)
Пример #2
0
    def get_context_data(self, *args, **kwargs):
        context = super(KioskView, self).get_context_data(*args, **kwargs)
        geological_sites = GeologicalSite.cached.filter(is_active=True)
        volunteer_opportunities = VolunteerOpportunity.cached.all()

        sites = {}
        for s in geological_sites:
            site = model_to_dict(s)
            site["photos"] = []
            for p in s.geologicalsitephoto_set.approved():
                photo = model_to_dict(p)
                photo["photo"] = p.photo.banner.url if p.photo.banner else ""
                site["photos"].append(photo)
            site["resources"] = []
            for r in s.geologicalsiteresource_set.active():
                resource = model_to_dict(r)
                resource["favicon"] = r.favicon_url()
                site["resources"].append(resource)
            sites[s.pk] = site
        sites_json = json.dumps(sites)

        volunteers = {}
        for v in volunteer_opportunities:
            volunteer = model_to_dict(v)
            volunteer["date"] = volunteer["date"].isoformat()
            volunteer["venue"] = model_to_dict(v.venue)
            volunteer["photo"] = v.venue.photo.banner.url if v.venue.photo else ""
            del volunteer["venue"]["photo"]  # Remove photos from the array, as they are not JSON serializable
            volunteer["resources"] = []
            for r in v.volunteeropportunityresource_set.active():
                resource = model_to_dict(r)
                resource["favicon"] = r.favicon_url()
                volunteer["resources"].append(resource)
            volunteers[v.pk] = volunteer
        volunteer_json = json.dumps(volunteers)

        # Test if the current ip address is one that should behave like a kiosk
        addresses = Setting.get_value("kiosk_ip_addresses", "")
        whitelist = re.split(r"[,\s]+", addresses)
        passes_whitelist = address_passes_whitelist(self.request.META["REMOTE_ADDR"], whitelist)

        # Optional manual override for testing
        manual_is_kiosk_display = Setting.get_value("is_kiosk_display", False)

        # Set is_kiosk_display if the ip address matches or manual override is set
        is_kiosk_display = False
        if passes_whitelist or manual_is_kiosk_display:
            is_kiosk_display = True

        context.update(
            {
                "mapbox_api_key": Setting.get_value("mapbox_api_key"),
                "session_timeout_hard": Setting.get_value("session_timeout_hard", 120),
                "session_timeout_soft": Setting.get_value("session_timeout_soft", 15),
                "default_location": Setting.get_value("default_location", "44.04301, -123.06811").split(","),
                "max_zoom": Setting.get_value("max_zoom", 20),
                "min_zoom": Setting.get_value("min_zoom", 6),
                "southwest_map_boundary": Setting.get_value("southwest_map_boundary", "[38,-138]"),
                "northeast_map_boundary": Setting.get_value("northeast_map_boundary", "[50,-108]"),
                "geological_sites": geological_sites,
                "sites_json": sites_json,
                "volunteer_opportunities": volunteer_opportunities,
                "volunteer_json": volunteer_json,
                "is_kiosk_display": is_kiosk_display,
                "allow_kiosk_commenting": Setting.get_value("allow_kiosk_commenting", True),
                "oregon_border_color": Setting.get_value("oregon_border_color", "#000000"),
            }
        )
        return context
Пример #3
0
    def render(self, name, value, attrs=None):
        context = {
            'mapbox_api_key': Setting.get_value('mapbox_api_key'),
            'name': name,
            'value': value,
        }
        html = """<section class="mapbox_widget" id="id_%(name)s"></section>
        <style>
        .mapbox_widget {
            width: 600px;
            height: 400px;
        }
        </style>
        <script>

        (function($) {

            $(function() {

                var map = L.mapbox.map('id_%(name)s', '%(mapbox_api_key)s');
                var geocoder = L.mapbox.geocoderControl('%(mapbox_api_key)s')
                map.addControl(geocoder);
                map.scrollWheelZoom.disable();

                var layer = L.mapbox.tileLayer('%(mapbox_api_key)s');
                var marker = L.marker([0,0], {
                    icon: L.mapbox.marker.icon({
                        'type': "Feature", 
                        'geometry': {
                            'type': "Point",
                        },
                    }),
                    draggable: true
                });

                layer.on('ready', function(e) {
                    var tj = layer.getTileJSON();

                    var $latitude = $('#id_latitude');
                    var $longitude = $('#id_longitude');
                    var latlng = null;

                    if ($latitude.val() && $longitude.val()) {
                        latlng = [Number($latitude.val()), Number($longitude.val())];
                        marker.setLatLng(latlng);
                    }
                    else {
                        latlng = [tj.center[1], tj.center[0]]
                        marker.setLatLng(latlng);
                        $latitude.val(tj.center[1]);
                        $longitude.val(tj.center[0]);
                    }
                    marker.addTo(map);

                    if (latlng) 
                        map.setView(latlng, 9);

                    var update_marker = function() {
                        var ll = [Number($latitude.val()), Number($longitude.val())]
                        marker.setLatLng(ll);
                    };
                    $latitude.change(update_marker);
                    $longitude.change(update_marker);
                });

                marker.on('dragend', function(e) {
                    $('#id_latitude').val(marker._latlng.lat)
                    $('#id_longitude').val(marker._latlng.lng)
                });

                geocoder.on('found', function(e) {
                    $('#id_latitude').val(e.latlng[0])
                    $('#id_longitude').val(e.latlng[1]);
                    marker.setLatLng(e.latlng)

                });


            })

        })(jQuery);

        </script>

        """ % context;
        return mark_safe(html);