def maps(request): """Displays all maps and jobs, sorted by submission time, or maps matching the search terms when provided.""" map_list = None form = forms.MapSearchForm(request.GET) if form.is_valid(): map_list = ( models.MapRenderingJob.objects.order_by('-submission_time').filter( maptitle__icontains=form.cleaned_data['query'])) if len(map_list) == 1: return HttpResponseRedirect( reverse('map-by-id', args=[map_list[0].id])) else: form = forms.MapSearchForm() if map_list is None: map_list = ( models.MapRenderingJob.objects.order_by('-submission_time')) paginator = Paginator(map_list, www.settings.ITEMS_PER_PAGE) try: try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 maps = paginator.page(page) except (EmptyPage, InvalidPage): maps = paginator.page(paginator.num_pages) return render_to_response('maposmatic/maps.html', { 'maps': maps, 'form': form, 'is_search': form.is_valid(), 'pages': helpers.get_pages_list(maps, paginator) }, context_instance=RequestContext(request))
def index(request): """The main page.""" form = forms.MapSearchForm(request.GET) job_list = ( models.MapRenderingJob.objects.all().order_by('-submission_time')) job_list = (job_list.filter(status=0) | job_list.filter(status=1)) return render_to_response('maposmatic/index.html', { 'form': form, 'queued': job_list.count() }, context_instance=RequestContext(request))
def all(request): # Do not add the useless overhead of parsing blog entries when generating # the rss feed if (django.VERSION[1] >= 4 and request.path == reverse('rss-feed')) or \ (django.VERSION[1] < 4 and request.path == reverse('rss-feed', args=['maps'])): return {} l = django.utils.translation.get_language() if www.settings.PAYPAL_LANGUAGES.has_key(l): paypal_lang_code = www.settings.PAYPAL_LANGUAGES[l][0] paypal_country_code = www.settings.PAYPAL_LANGUAGES[l][1] else: paypal_lang_code = "en_US" paypal_country_code = "US" daemon_running = www.settings.is_daemon_running() gis_lastupdate = get_osm_database_last_update() gis_lag_ok = (gis_lastupdate and datetime.datetime.utcnow() - gis_lastupdate < datetime.timedelta(minutes=10) or False) platform_status = 'off' if daemon_running and gis_lag_ok: platform_status = 'ok' elif daemon_running and gis_lastupdate and not gis_lag_ok: platform_status = 'warning-sign' return { 'DEBUG': www.settings.DEBUG, 'LANGUAGES': www.settings.LANGUAGES, 'MAP_LANGUAGES': www.settings.MAP_LANGUAGES, 'ALERT': www.settings.ALERT_MESSAGE, 'BRAND_NAME': www.settings.BRAND_NAME, 'CONTACT_EMAIL': www.settings.CONTACT_EMAIL, 'EXTRA_FOOTER': www.settings.EXTRA_FOOTER, 'MAPOSMATIC_DONATION': www.settings.MAPOSMATIC_DONATION, 'BBOX_MAXIMUM_LENGTH_IN_METERS': www.settings.BBOX_MAXIMUM_LENGTH_IN_METERS, 'PIWIK_HOST': www.settings.PIWIK_HOST, 'PIWIK_BASE': www.settings.PIWIK_BASE, 'PIWIK_SITE_ID': www.settings.PIWIK_SITE_ID, 'searchform': forms.MapSearchForm(request.GET), 'blogposts': get_latest_blog_posts(), 'daemon_running': daemon_running, 'gis_lastupdate': gis_lastupdate, 'gis_lag_ok': gis_lag_ok, 'utc_now': datetime.datetime.utcnow(), 'platform_status': platform_status, 'paypal_lang_code': paypal_lang_code, 'paypal_country_code': paypal_country_code, }