def signin(request, template_name='authopenid/signin.html', redirect_field_name=REDIRECT_FIELD_NAME, openid_form=OpenidSigninForm, auth_form=AuthenticationForm, on_failure=None, extra_context=None): """Signin page. It manage the legacy authentification (user/password) and authentification with openid. :attr request: request object :attr template_name: string, name of template to use :attr redirect_field_name: string, field name used for redirect. by default 'next' :attr openid_form: form use for openid signin, by default `OpenidSigninForm` :attr auth_form: form object used for legacy authentification. By default AuthentificationForm form auser auth contrib. :attr extra_context: A dictionary of variables to add to the template context. Any callable object in this dictionary will be called to produce the end result which appears in the context. """ if on_failure is None: on_failure = signin_failure from madrona.common.utils import get_logger log = get_logger() redirect_to = request.REQUEST.get(redirect_field_name, '') form1 = openid_form() form2 = auth_form() log.debug(request.POST.keys()) if request.POST: if not redirect_to or '//' in redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL if 'openid_url' in request.POST.keys(): form1 = openid_form(data=request.POST) if form1.is_valid(): redirect_url = "%s%s?%s" % ( get_url_host(request), reverse('user_complete_signin'), urllib.urlencode({redirect_field_name: redirect_to}) ) return ask_openid(request, form1.cleaned_data['openid_url'], redirect_url, on_failure=on_failure) else: # perform normal django authentification form2 = auth_form(data=request.POST) if form2.is_valid(): login(request, form2.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) return render(template_name, { 'form1': form1, 'form2': form2, redirect_field_name: redirect_to, 'msg': request.GET.get('msg','') }, context_instance=_build_context(request, extra_context=extra_context))
from django.dispatch.dispatcher import receiver from madrona.features import register, alternate from madrona.features.models import FeatureCollection from madrona.unit_converter.models import area_in_display_units from madrona.analysistools.models import Analysis from madrona.common.utils import asKml from madrona.async.ProcessHandler import process_is_running, process_is_complete, \ process_is_pending, get_process_result, process_is_complete, check_status_or_begin from madrona.common.utils import get_logger from seak.tasks import marxan_start from django.core.serializers.json import DjangoJSONEncoder from django.utils import simplejson as json from madrona.common.models import KmlCache from seak.jenks import get_jenks_breaks logger = get_logger() def cachemethod(cache_key, timeout=60*60*24*365): ''' http://djangosnippets.org/snippets/1130/ Cacheable class method decorator from madrona.common.utils import cachemethod @property @cachemethod("SomeClass_get_some_result_%(id)s") ''' def paramed_decorator(func): def decorated(self): key = cache_key % self.__dict__ res = cache.get(key) if res == None:
import os from django.conf import settings from madrona.common.utils import get_logger from shutil import copyfile log = get_logger() class MarxanError(Exception): pass class MarxanAnalysis(object): def __init__(self, pucosts, cfs, outdir, name="seak"): self.outdir = os.path.realpath(outdir) self.marxan_bin = os.path.realpath(settings.MARXAN_BIN) if not os.path.exists(self.marxan_bin): raise MarxanError("Marxan linux binary not found; tried %s" % self.marxan_bin) if not os.access(self.marxan_bin, os.X_OK): raise MarxanError("Marxan binary exists but is not executable; tried %s" % self.marxan_bin) self.NUMREPS = settings.MARXAN_NUMREPS self.NUMITNS = settings.MARXAN_NUMITNS self.templatedir = settings.MARXAN_TEMPLATEDIR self.pus = pucosts self.cfs = cfs self.name = name def setup(self): if os.path.exists(self.outdir): import shutil shutil.rmtree(self.outdir)
from django.db import models from django.conf import settings from django.contrib.auth.models import User, Group from madrona.features.managers import ShareableGeoManager from madrona.features.models import Feature, FeatureForm from madrona.common.utils import get_logger from django.core.urlresolvers import reverse from django.utils.encoding import DjangoUnicodeDecodeError import os logger = get_logger() class UserUploadedKml(Feature): """ Abstract Model for storing uploaded restricted-access kml files Owned by a single user, can be shared with any group(s) that the owner is a member of (assuming group has can_share_features permissions) These are features and will show up in the MyShapes/SharedShapes panels """ kml_file = models.FileField(upload_to='upload/private-kml-layers/%Y/%m/%d', help_text=""" KML or KMZ file. Can use NetworkLinks pointing to remote kml datasets or WMS servers. """, blank=False, max_length=510) description = models.TextField(default="", null=True, blank=True)
def signin(request, template_name='authopenid/signin.html', redirect_field_name=REDIRECT_FIELD_NAME, openid_form=OpenidSigninForm, auth_form=AuthenticationForm, on_failure=None, extra_context=None): """Signin page. It manage the legacy authentification (user/password) and authentification with openid. :attr request: request object :attr template_name: string, name of template to use :attr redirect_field_name: string, field name used for redirect. by default 'next' :attr openid_form: form use for openid signin, by default `OpenidSigninForm` :attr auth_form: form object used for legacy authentification. By default AuthentificationForm form auser auth contrib. :attr extra_context: A dictionary of variables to add to the template context. Any callable object in this dictionary will be called to produce the end result which appears in the context. """ if on_failure is None: on_failure = signin_failure from madrona.common.utils import get_logger log = get_logger() redirect_to = request.REQUEST.get(redirect_field_name, '') form1 = openid_form() form2 = auth_form() log.debug(request.POST.keys()) if request.POST: if not redirect_to or '//' in redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL if 'openid_url' in request.POST.keys(): form1 = openid_form(data=request.POST) if form1.is_valid(): redirect_url = "%s%s?%s" % ( get_url_host(request), reverse('user_complete_signin'), urllib.urlencode({redirect_field_name: redirect_to})) return ask_openid(request, form1.cleaned_data['openid_url'], redirect_url, on_failure=on_failure) else: # perform normal django authentification form2 = auth_form(data=request.POST) if form2.is_valid(): login(request, form2.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) return render(template_name, { 'form1': form1, 'form2': form2, redirect_field_name: redirect_to, 'msg': request.GET.get('msg', '') }, context_instance=_build_context(request, extra_context=extra_context))
import re import sys import os import time import shutil import subprocess from madrona.common.utils import get_logger log = get_logger() DJANGO = True try: from django.conf import settings except ImportError: # not in a django env DJANGO = False ''' Sets up a grass environment in the current running process. Allows grass commands to be run in a shell environment. Optimally grass python bindings would be used in the future once they become more stable and full-featured Grass is not thread-safe, see http://grass.osgeo.org/wiki/Parallel_GRASS_jobs Because of this there can be issues with race conditions while working within the same mapset with more than one process. The solution is to create a new mapset for each analysis run, copy the necessary maps into the new mapset, run the analysis, and then remove the mapset when you're done. @author: Tim Welch, Ecotrust 2009 @author: Matthew Perry, Ecotrust 2011 Concepts taken from the PyWPS project.