Beispiel #1
0
def load_batches():
    batch_details = []
    for app in all_apps():
        for provider in app.providers:
            for method_name in dir(provider):
                method = getattr(provider, method_name)
                if not getattr(method, 'is_batch', False):
                    continue
                    
                batch_details.append({
                    'title': method.__doc__ or provider.class_path,
                    'local_name': app.local_name,
                    'provider_name': provider.class_path,
                    'method_name': method_name,
                    'cron_stmt': method.cron_stmt,
                    'initial_metadata': method.initial_metadata,
                })

    batches = set()
    for batch_detail in batch_details:
        batch, _ = Batch.objects.get_or_create(
            local_name = batch_detail['local_name'],
            provider_name = batch_detail['provider_name'],
            method_name = batch_detail['method_name'],
            defaults = {'title': batch_detail['title'],
                        'cron_stmt': batch_detail['cron_stmt'],
                        '_metadata': simplejson.dumps(batch_detail['initial_metadata'])})
        batches.add(batch)
    for batch in Batch.objects.all():
        if not batch in batches:
            batch.delete()
Beispiel #2
0
def load_batches():
    batch_details = []
    for app in all_apps():
        for provider in app.providers:
            for method_name in dir(provider):
                method = getattr(provider, method_name)
                if not getattr(method, 'is_batch', False):
                    continue
                    
                batch_details.append({
                    'title': method.__doc__ or provider.class_path,
                    'local_name': app.local_name,
                    'provider_name': provider.class_path,
                    'method_name': method_name,
                    'cron_stmt': method.cron_stmt,
                    'initial_metadata': method.initial_metadata,
                })

    batches = set()
    for batch_detail in batch_details:
        batch, created = Batch.objects.get_or_create(
            local_name = batch_detail['local_name'],
            provider_name = batch_detail['provider_name'],
            method_name = batch_detail['method_name'],
            defaults = {'title': batch_detail['title'],
                        'cron_stmt': batch_detail['cron_stmt'],
                        '_metadata': simplejson.dumps(batch_detail['initial_metadata'])})
        batches.add(batch)
    for batch in Batch.objects.all():
        if not batch in batches:
            batch.delete()
Beispiel #3
0
    def handle_GET(self, request, context):
        # Check whether the referer header is from the same host as the server
        # is responding as
        try:
            internal_referer = request.META.get('HTTP_REFERER', '').split('/')[2] == request.META.get('HTTP_HOST')
        except IndexError:
            internal_referer = False

        # Redirects if the user is a desktop browser who hasn't been referred
        # from this site. Also extra checks for preview mode and DEBUG.
        if ("generic_web_browser" in device_parents[request.device.devid]
            and not request.session.get('home:desktop_shown', False)
            and not request.GET.get('preview') == 'true'
            and not internal_referer
            and not settings.DEBUG
            and conf.has_app('molly.apps.desktop')):
            return HttpResponseRedirect(reverse('desktop:index'))

        applications = [{
            'application_name': app.application_name,
            'local_name': app.local_name,
            'title': app.title,
            'url': reverse('%s:index' % app.local_name) if app.has_urlconf else None,
            'display_to_user': app.display_to_user,
        } for app in conf.all_apps()]

        context = {
            'applications': applications,
            'hide_feedback_link': True,
        }
        return self.render(request, context, 'home/index')
Beispiel #4
0
    def handle_GET(self, request, context):
        # Check whether the referer header is from the same host as the server
        # is responding as
        try:
            referer_host = request.META.get('HTTP_REFERER', '').split('/')[2]
            internal_referer = referer_host == request.META.get('HTTP_HOST')
        except IndexError:
            internal_referer = False

        # Redirects if the user is a desktop browser who hasn't been referred
        # from this site. Also extra checks for preview mode and DEBUG.
        if ("generic_web_browser" in device_parents[request.device.devid]
                and not request.session.get('home:desktop_shown', False)
                and not request.GET.get('preview') == 'true'
                and not internal_referer and not settings.DEBUG
                and conf.has_app('molly.apps.desktop')):
            return HttpResponseRedirect(reverse('desktop:index'))

        # Add any one-off messages to be shown to this user
        messages = []

        if not request.session.get('home:opera_mini_warning', False) \
          and request.browser.mobile_browser == u'Opera Mini':
            messages.append("""Please note that the "Mobile View" on Opera Mini
                            does not display this site correctly. To ensure
                            correct operation of this site, ensure "Mobile View"
                            is set to Off in Opera settings""")
            request.session['home:opera_mini_warning'] = True

        applications = [{
            'application_name': app.application_name,
            'local_name': app.local_name,
            'title': app.title,
            'url': reverse('%s:index' % app.local_name) \
                    if app.has_urlconf else None,
            'display_to_user': app.display_to_user,
        } for app in conf.all_apps()]

        # Add accesskeys to the first 9 apps to be displayed to the user
        for i, app in enumerate(
            [app for app in applications if app['display_to_user']][:9]):
            app['accesskey'] = i + 1

        context = {
            'applications': applications,
            'hide_feedback_link': True,
            'is_christmas': datetime.now().month == 12,
            'messages': messages,
            'favourites': get_favourites(request),
        }
        return self.render(request,
                           context,
                           'home/index',
                           expires=timedelta(minutes=10))
Beispiel #5
0
    def handle_GET(self, request, context):
        # Check whether the referer header is from the same host as the server
        # is responding as
        try:
            referer_host = request.META.get('HTTP_REFERER', '').split('/')[2]
            internal_referer = referer_host == request.META.get('HTTP_HOST')
        except IndexError:
            internal_referer = False

        # Redirects if the user is a desktop browser who hasn't been referred
        # from this site. Also extra checks for preview mode and DEBUG.
        if ("generic_web_browser" in device_parents[request.device.devid]
            and not request.session.get('home:desktop_shown', False)
            and not request.GET.get('preview') == 'true'
            and not internal_referer
            and not settings.DEBUG
            and conf.has_app('molly.apps.desktop')):
            return HttpResponseRedirect(reverse('desktop:index'))
        
        # Add any one-off messages to be shown to this user
        messages = []
        
        if not request.session.get('home:opera_mini_warning', False) \
          and request.browser.mobile_browser == u'Opera Mini':
            messages.append("""Please note that the "Mobile View" on Opera Mini
                            does not display this site correctly. To ensure
                            correct operation of this site, ensure "Mobile View"
                            is set to Off in Opera settings""")
            request.session['home:opera_mini_warning'] = True

        applications = [{
            'application_name': app.application_name,
            'local_name': app.local_name,
            'title': app.title,
            'url': reverse('%s:index' % app.local_name) \
                    if app.has_urlconf else None,
            'display_to_user': app.display_to_user,
        } for app in conf.all_apps()]

        # Add accesskeys to the first 9 apps to be displayed to the user
        for i, app in enumerate(
                [app for app in applications if app['display_to_user']][:9]
            ):
            app['accesskey'] = i + 1

        context = {
            'applications': applications,
            'hide_feedback_link': True,
            'is_christmas': datetime.now().month == 12,
            'messages': messages,
            'favourites': get_favourites(request),
        }
        return self.render(request, context, 'home/index',
                           expires=timedelta(minutes=10))
Beispiel #6
0
    def _get_search_form_class(self):
        APPLICATION_CHOICES = (
            ('', _('Show all')),
        ) + tuple((app.local_name, app.title) for app in all_apps() if app.application_name)

        class SearchForm(forms.Form):
            query = forms.CharField(label=_('Search'))
            application = forms.ChoiceField(
                label='Filter',
                widget=forms.HiddenInput(),
                choices=APPLICATION_CHOICES,
                required=False,
            )

        return SearchForm
Beispiel #7
0
    def _get_search_form_class(cls):
        APPLICATION_CHOICES = (
            ('', 'Show all'),
        ) + tuple((app.local_name, app.title) for app in all_apps() if app.application_name)

        class SearchForm(forms.Form):
            query = forms.CharField(label='Search')
            application = forms.ChoiceField(
                label='Filter',
                widget=forms.HiddenInput(),
                choices=APPLICATION_CHOICES,
                required=False,
            )

        return SearchForm
    def find_applications(self):
        self.applications = {}
        for application in all_apps():

            if self.local_names and not application in self.local_names:
                continue
            try:
                search_module_name = '%s.search' % application.application_name
                _temp = __import__(search_module_name, globals(), locals(),
                                   ['ApplicationSearch'], -1)
                if not hasattr(_temp, 'ApplicationSearch'):
                    raise ImportError
            except ImportError:
                continue
            else:
                search_provider = _temp.ApplicationSearch(application)

            self.applications[application.local_name] = search_provider
    def find_applications(self):
        self.applications = {}
        for application in all_apps():
            
            if self.local_names and not application in self.local_names:
                continue
            try:
                search_module_name = '%s.search' % application.application_name
                _temp = __import__(search_module_name,
                                   globals(), locals(),
                                   ['ApplicationSearch'], -1)
                if not hasattr(_temp, 'ApplicationSearch'):
                    raise ImportError
            except ImportError:
                continue
            else:
                search_provider = _temp.ApplicationSearch(application)

            self.applications[application.local_name] = search_provider
Beispiel #10
0
def load_batches():
    batch_details = []
    for app in all_apps():
        for provider in app.providers:
            for method_name in dir(provider):
                method = getattr(provider, method_name)
                if not getattr(method, "is_batch", False):
                    continue

                batch_details.append(
                    {
                        "title": method.__doc__ or provider.class_path,
                        "local_name": app.local_name,
                        "provider_name": provider.class_path,
                        "method_name": method_name,
                        "cron_stmt": method.cron_stmt,
                        "initial_metadata": method.initial_metadata,
                    }
                )

    batches = set()
    for batch_detail in batch_details:
        batch, _ = Batch.objects.get_or_create(
            local_name=batch_detail["local_name"],
            provider_name=batch_detail["provider_name"],
            method_name=batch_detail["method_name"],
            defaults={
                "title": batch_detail["title"],
                "cron_stmt": batch_detail["cron_stmt"],
                "_metadata": simplejson.dumps(batch_detail["initial_metadata"]),
            },
        )
        batches.add(batch)
    for batch in Batch.objects.all():
        if not batch in batches:
            batch.delete()
Beispiel #11
0
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin

from molly.conf import applications, all_apps

admin.autodiscover()

all_apps()

urlpatterns = patterns('',
    (r'^adm/', include(admin.site.urls)),

    # These are how we expect all applications to be eventually.
    (r'^contact/', applications.contact.urls),
    (r'^service-status/', applications.service_status.urls),
    (r'^weather/', applications.weather.urls),
    (r'^library/', applications.library.urls),
    (r'^podcasts/', applications.podcasts.urls),
    (r'^webcams/', applications.webcams.urls),
    (r'^results/', applications.results.urls),
    (r'^search/', applications.search.urls),
    (r'^geolocation/', applications.geolocation.urls),
    (r'^places/', applications.places.urls),
    (r'^feedback/', applications.feedback.urls),
    (r'^news/', applications.news.urls),
    (r'^external-media/', applications.external_media.urls),
    (r'^device-detection/', applications.device_detection.urls),
    (r'^osm/', applications.osm.urls),
    (r'^desktop/', applications.desktop.urls),
    (r'^url-shortener/', applications.url_shortener.urls),
Beispiel #12
0
from django.contrib import admin

from molly.conf import applications, all_apps

# Admin
admin.autodiscover()

urlpatterns = patterns(
    '',
    (r'^adm/', include(admin.site.urls)),  # Admin site
    (r'^comments/',
     include('django.contrib.comments.urls')),  # Django comments
    (r'', applications.home.urls))  # Home default

# Dynamically add apps
for app in (app for app in all_apps()
            if app.has_urlconf and app.local_name != 'home'):
    urlpatterns += patterns('',
                            (r'^' + app.local_name + '/', include(app.urls)))

# Redirecting old URLs
urlpatterns += patterns(
    'django.views.generic.simple',
    (r'^maps/busstop:(?P<atco>[A-Z\d]+)/(?P<remain>.*)$', 'redirect_to', {
        'url': '/places/atco:%(atco)s/%(remain)s'
    }),
    (r'^maps/[a-z]\-+:(?P<id>\d{8})/(?P<remain>.*)$', 'redirect_to', {
        'url': '/places/oxpoints:%(id)s/%(remain)s'
    }),
    (r'^maps/[a-z]\-+:(?P<id>[NW]\d{8})/(?P<remain>.*)$', 'redirect_to', {
        'url': '/places/osm:%(id)s/%(remain)s'
Beispiel #13
0
from molly.conf import applications, all_apps
from molly.utils.i18n import SetLanguageView, javascript_catalog

# Admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^adm/', include(admin.site.urls)), # Admin site
    (r'^comments/', include('django.contrib.comments.urls')), # Django comments
    (r'', applications.home.urls), # Home default
    (r'set-language/$', SetLanguageView, {}, 'set-language'), # Change language view
    (r'^jsi18n/$', javascript_catalog,
     {'packages': settings.INSTALLED_APPS}, 'js-i18n')) # JS i18n catalogues

# Dynamically add apps
for app in (app for app in all_apps() if app.has_urlconf and app.local_name != 'home'):
    urlpatterns += patterns('',
        (r'^' + app.local_name + '/', include(app.urls)))

# Redirecting old URLs
urlpatterns += patterns('django.views.generic.simple',
    (r'^maps/busstop:(?P<atco>[A-Z\d]+)/(?P<remain>.*)$', 'redirect_to', {'url': '/places/atco:%(atco)s/%(remain)s'}),
    (r'^maps/[a-z]\-+:(?P<id>\d{8})/(?P<remain>.*)$', 'redirect_to', {'url': '/places/oxpoints:%(id)s/%(remain)s'}),
    (r'^maps/[a-z]\-+:(?P<id>[NW]\d{8})/(?P<remain>.*)$', 'redirect_to', {'url': '/places/osm:%(id)s/%(remain)s'}),
    (r'^maps/(?P<remain>.*)$', 'redirect_to', {'url': '/places/%(remain)s'}),
    (r'^osm/(?P<remain>.*)$', 'redirect_to', {'url': '/maps/osm/%(remain)s'}),
)

handler500 = 'molly.utils.views.handler500'

if settings.DEBUG:
Beispiel #14
0
    def handle_GET(self, request, context):
        # Check whether the referer header is from the same host as the server
        # is responding as
        try:
            referer_host = request.META.get('HTTP_REFERER', '').split('/')[2]
            internal_referer = referer_host == request.META.get('HTTP_HOST')
        except IndexError:
            internal_referer = False

        # Redirects if the user is a desktop browser who hasn't been referred
        # from this site. Also extra checks for preview mode and DEBUG.
        if ("generic_web_browser" in device_parents[request.device.devid]
                and not request.session.get('home:desktop_shown', False)
                and not request.GET.get('preview') == 'true'
                and not internal_referer and not settings.DEBUG
                and conf.has_app('molly.apps.desktop')
                and request.REQUEST.get('format') is None):
            return self.redirect(reverse('desktop:index'), request)

        messages = []
        # Add any one-off messages to be shown to this user
        if UserMessage.objects.filter(
                read=False, session_key=request.session.session_key).count():
            messages.append({
                'url': reverse('home:messages'),
                'body': _('You have a message from the developers')
            })

        # Warn users who use Opera devices
        if not request.session.get('home:opera_mini_warning', False) \
          and request.browser.mobile_browser == u'Opera Mini':
            messages.append({
                'body':
                _("""Please note that the "Mobile View" on Opera Mini does not display this site correctly. To ensure correct operation of this site, ensure "Mobile View" is set to Off in Opera settings"""
                  )
            })
            request.session['home:opera_mini_warning'] = True

        if has_app_by_application_name('molly.apps.weather'):
            weather_id = app_by_application_name(
                'molly.apps.weather').location_id
            try:
                weather = Weather.objects.get(ptype='o',
                                              location_id=weather_id)
            except Weather.DoesNotExist:
                weather = None
        else:
            weather = None

        applications = [{
            'application_name': app.application_name,
            'local_name': app.local_name,
            'title': app.title,
            'url': reverse('%s:index' % app.local_name) \
                    if app.has_urlconf else None,
            'display_to_user': app.display_to_user,
        } for app in conf.all_apps()]

        # Add accesskeys to the first 9 apps to be displayed to the user
        for i, app in enumerate(
            [app for app in applications if app['display_to_user']][:9]):
            app['accesskey'] = i + 1

        context = {
            'applications': applications,
            'hide_feedback_link': True,
            'messages': messages,
            'favourites': get_favourites(request),
            'weather': weather,
        }
        return self.render(request,
                           context,
                           'home/index',
                           expires=timedelta(minutes=10))
Beispiel #15
0
    def handle_GET(self, request, context):
        # Check whether the referer header is from the same host as the server
        # is responding as
        try:
            referer_host = request.META.get('HTTP_REFERER', '').split('/')[2]
            internal_referer = referer_host == request.META.get('HTTP_HOST')
        except IndexError:
            internal_referer = False

        # Redirects if the user is a desktop browser who hasn't been referred
        # from this site. Also extra checks for preview mode and DEBUG.
        if ("generic_web_browser" in device_parents[request.device.devid]
            and not request.session.get('home:desktop_shown', False)
            and not request.GET.get('preview') == 'true'
            and not internal_referer
            and not settings.DEBUG
            and conf.has_app('molly.apps.desktop')
            and request.REQUEST.get('format') is None):
            return self.redirect(reverse('desktop:index'), request)
        
        messages = []
        # Add any one-off messages to be shown to this user
        if UserMessage.objects.filter(
                read=False, session_key=request.session.session_key).count():
            messages.append({
                'url': reverse('home:messages'),
                'body': _('You have a message from the developers')
            })
        
        # Warn users who use Opera devices
        if not request.session.get('home:opera_mini_warning', False) \
          and request.browser.mobile_browser == u'Opera Mini':
            messages.append(
                { 'body': _("""Please note that the "Mobile View" on Opera Mini does not display this site correctly. To ensure correct operation of this site, ensure "Mobile View" is set to Off in Opera settings""") })
            request.session['home:opera_mini_warning'] = True
        
        if has_app_by_application_name('molly.apps.weather'):
            weather_id = app_by_application_name('molly.apps.weather').location_id
            try:
                weather = Weather.objects.get(ptype='o', location_id=weather_id)
            except Weather.DoesNotExist:
                weather = None
        else:
            weather = None
        
        applications = [{
            'application_name': app.application_name,
            'local_name': app.local_name,
            'title': app.title,
            'url': reverse('%s:index' % app.local_name) \
                    if app.has_urlconf else None,
            'display_to_user': app.display_to_user,
        } for app in conf.all_apps()]

        # Add accesskeys to the first 9 apps to be displayed to the user
        for i, app in enumerate(
                [app for app in applications if app['display_to_user']][:9]
            ):
            app['accesskey'] = i + 1

        context = {
            'applications': applications,
            'hide_feedback_link': True,
            'messages': messages,
            'favourites': get_favourites(request),
            'weather': weather,
        }
        return self.render(request, context, 'home/index',
                           expires=timedelta(minutes=10))
Beispiel #16
0
from molly.utils.i18n import SetLanguageView, javascript_catalog

# Admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^adm/', include(admin.site.urls)), # Admin site
    (r'^comments/', include('django.contrib.comments.urls')), # Django comments
    (r'', applications.home.urls), # Home default
    (r'^reverse', ReverseView, {}, 'reverse'),
    (r'^set-language/$', SetLanguageView, {}, 'set-language'), # Change language view
    (r'^jsi18n/$', javascript_catalog,
     {'packages': settings.INSTALLED_APPS}, 'js-i18n')) # JS i18n catalogues

# Dynamically add apps
for app in (app for app in all_apps() if app.has_urlconf and app.local_name != 'home'):
    urlpatterns += patterns('',
        (r'^' + app.local_name + '/', include(app.urls)))

# Redirecting old URLs
urlpatterns += patterns('django.views.generic.simple',
    (r'^maps/busstop:(?P<atco>[A-Z\d]+)/(?P<remain>.*)$', 'redirect_to', {'url': '/places/atco:%(atco)s/%(remain)s'}),
    (r'^maps/[a-z]\-+:(?P<id>\d{8})/(?P<remain>.*)$', 'redirect_to', {'url': '/places/oxpoints:%(id)s/%(remain)s'}),
    (r'^maps/[a-z]\-+:(?P<id>[NW]\d{8})/(?P<remain>.*)$', 'redirect_to', {'url': '/places/osm:%(id)s/%(remain)s'}),
    (r'^maps/(?P<remain>.*)$', 'redirect_to', {'url': '/places/%(remain)s'}),
    (r'^osm/(?P<remain>.*)$', 'redirect_to', {'url': '/maps/osm/%(remain)s'}),
)

handler500 = 'molly.utils.views.handler500'

if settings.DEBUG: