<commit_before>"""GeoData views."""

from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from models import EarthGeoDataPatrimony, EarthGeoDataConstruction,\
     EarthGeoDataMeeting, EarthGeoDataActor, EarthGeoDataAbstract
from forms import EarthGeoDataPatrimonyForm, EarthGeoDataConstructionForm,\
     EarthGeoDataMeetingForm, EarthGeoDataActorForm
from olwidget.widgets import InfoMap, Map, InfoLayer
from sorl.thumbnail import get_thumbnail
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.timezone import now
from datetime import timedelta
from django.contrib import messages
from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse
from profiles.models import Profile
from django.conf import settings
from django.utils.encoding import force_unicode
from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from django.views.generic.base import View, TemplateView
from django.views.generic.detail import SingleObjectMixin, DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.utils import simplejson
from django.utils.decorators import method_decorator
from django.core.exceptions import PermissionDenied






def _info_builder(geodataobjects, style = {}):
    info = []

    for i in geodataobjects:
        description = ""
        image = ""

        if i.description:
            description = i.description
        else: description = i.name

        if i.image:
            thumbnail = get_thumbnail(i.image, '100x100')
            image = "<p><a href=" + i.get_absolute_url() +\
                    "><img src=\"" + thumbnail.url + "\" width=\"" +\
                    str(thumbnail.x) + "\" height=\"" + str(thumbnail.y) +\
                    "\"></a></p>"

        mydict = { 'html': "<h1>" + i.name + "</h1>" +\
                       "<p><a href=" + i.get_absolute_url() + ">" +\
                       description + "</a></p>" + image,
                   'style': style
                   }

        info.append([ i.geometry, mydict ])
    return info


class PatrimonyListView(ListView):
    """Returns a template to present all patrimonies."""
    model = EarthGeoDataPatrimony
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(PatrimonyListView, self).get_context_data(**kwargs)

        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Patrimonies",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/patrimony.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })
        context['map'] = map_
        return context


class ConstructionListView(ListView):
    """Returns a template to present all constructions."""
    model = EarthGeoDataConstruction
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(ConstructionListView, self).get_context_data(**kwargs)
        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Constructions",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/construction.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })

        context['map'] = map_
        return context


class MeetingListView(ListView):
    """Returns a template to present all meetings."""
    model = EarthGeoDataMeeting
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(MeetingListView, self).get_context_data(**kwargs)

        #geodata_list = EarthGeoDataMeeting.objects.all()
        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Meetings",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/meeting.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })

        #context['geodata_list'] = geodata_list
        context['map'] = map_
        return context


class ActorListView(ListView):
    """Returns a template to present all meetings."""
    model = EarthGeoDataActor
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(ActorListView, self).get_context_data(**kwargs)

        geodata_list = EarthGeoDataActor.objects.all()
        map_ = InfoMap(_info_builder(geodata_list),
                       {'name': "Actors",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/actor.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })

        context['geodata_list'] = geodata_list
        context['map'] = map_
        return context


class BigMapView(TemplateView):
    """Returns a big Map with all geodatas."""
    __name__ = 'show_bigmap'

    template_name = 'show_bigmap.html'
<commit_msg>fix ActorListView<commit_after>"""GeoData views."""

from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from models import EarthGeoDataPatrimony, EarthGeoDataConstruction,\
     EarthGeoDataMeeting, EarthGeoDataActor, EarthGeoDataAbstract
from forms import EarthGeoDataPatrimonyForm, EarthGeoDataConstructionForm,\
     EarthGeoDataMeetingForm, EarthGeoDataActorForm
from olwidget.widgets import InfoMap, Map, InfoLayer
from sorl.thumbnail import get_thumbnail
from django.contrib.auth.decorators import login_required, user_passes_test
from django.utils.timezone import now
from datetime import timedelta
from django.contrib import messages
from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse
from profiles.models import Profile
from django.conf import settings
from django.utils.encoding import force_unicode
from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from django.views.generic.base import View, TemplateView
from django.views.generic.detail import SingleObjectMixin, DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.utils import simplejson
from django.utils.decorators import method_decorator
from django.core.exceptions import PermissionDenied






def _info_builder(geodataobjects, style = {}):
    info = []

    for i in geodataobjects:
        description = ""
        image = ""

        if i.description:
            description = i.description
        else: description = i.name

        if i.image:
            thumbnail = get_thumbnail(i.image, '100x100')
            image = "<p><a href=" + i.get_absolute_url() +\
                    "><img src=\"" + thumbnail.url + "\" width=\"" +\
                    str(thumbnail.x) + "\" height=\"" + str(thumbnail.y) +\
                    "\"></a></p>"

        mydict = { 'html': "<h1>" + i.name + "</h1>" +\
                       "<p><a href=" + i.get_absolute_url() + ">" +\
                       description + "</a></p>" + image,
                   'style': style
                   }

        info.append([ i.geometry, mydict ])
    return info


class PatrimonyListView(ListView):
    """Returns a template to present all patrimonies."""
    model = EarthGeoDataPatrimony
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(PatrimonyListView, self).get_context_data(**kwargs)

        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Patrimonies",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/patrimony.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })
        context['map'] = map_
        return context


class ConstructionListView(ListView):
    """Returns a template to present all constructions."""
    model = EarthGeoDataConstruction
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(ConstructionListView, self).get_context_data(**kwargs)
        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Constructions",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/construction.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })

        context['map'] = map_
        return context


class MeetingListView(ListView):
    """Returns a template to present all meetings."""
    model = EarthGeoDataMeeting
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(MeetingListView, self).get_context_data(**kwargs)

        #geodata_list = EarthGeoDataMeeting.objects.all()
        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Meetings",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/meeting.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })

        #context['geodata_list'] = geodata_list
        context['map'] = map_
        return context


class ActorListView(ListView):
    """Returns a template to present all meetings."""
    model = EarthGeoDataActor
    context_object_name = 'geodata'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(ActorListView, self).get_context_data(**kwargs)

        geodata_list = EarthGeoDataActor.objects.all()
        map_ = InfoMap(_info_builder(context['object_list']),
                       {'name': "Actors",
                        'overlay_style': {
                            'external_graphic': settings.STATIC_URL+"img/actor.png",
                            'graphic_width': 20,
                            'graphic_height': 20,
                            'fill_color': '#00FF00',
                            'stroke_color': '#008800',
                            },
                        'map_options': {'controls': ['Navigation', 'PanZoom', 'Attribution'] }
                        })

        context['map'] = map_
        return context


class BigMapView(TemplateView):
    """Returns a big Map with all geodatas."""
    __name__ = 'show_bigmap'

    template_name = 'show_bigmap.html'

{'fraction_non_alphanumeric': 0.10458854759196057, 'fraction_numerical': 0.010163064087978764, 'mean_word_length': 2.0194641630409893, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4691612', 'n_tokens_mistral': 3604, 'n_tokens_neox': 3351, 'n_words': 793}