示例#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()
示例#2
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('apps.desktop')
            and request.REQUEST.get('format') is None):
            return self.redirect(reverse('desktop:index'), request)
        
        # 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,
            'xiaofang':sms_entry().get_random(),
           
        }
        return self.render(request, context, 'home/index',
                           expires=timedelta(minutes=10))
示例#3
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
    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
示例#5
0
                       url(r'^discussions/(?P<slug>[-\w]+)/$',
                           EntryDiscussions(),
                           name='entry_entry_discussion_feed'),
                       url(r'^comments/(?P<slug>[-\w]+)/$',
                           EntryComments(),
                           name='entry_entry_comment_feed'),
                       url(r'^pingbacks/(?P<slug>[-\w]+)/$',
                           EntryPingbacks(),
                           name='entry_entry_pingback_feed'),
                       url(r'^trackbacks/(?P<slug>[-\w]+)/$',
                           EntryTrackbacks(),
                           name='entry_entry_trackback_feed'),
    (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'}),
    (r'^maps/(?P<remain>.*)$', 'redirect_to', {'url': '/places/%(remain)s'}),
    (r'^osm/(?P<remain>.*)$', 'redirect_to', {'url': '/maps/osm/%(remain)s'}),
    ('^activity/', include('actstream.urls')),
    
)