Ejemplo n.º 1
0
    def get_layergroups(self, names=None, workspaces=None):
        '''
        names and workspaces can be provided as a comma delimited strings or as arrays, and are used for filtering.
        If no workspaces are provided, will return all layer groups in the catalog (global and workspace specific).
        Will always return an array.
        '''

        layergroups = []

        if workspaces is None or len(workspaces) == 0:
            # Add global layergroups
            url = "{}/layergroups.xml".format(self.service_url)
            groups = self.get_xml(url)
            layergroups.extend([
                LayerGroup(self,
                           g.find("name").text, None)
                for g in groups.findall("layerGroup")
            ])
            workspaces = []
        elif isinstance(workspaces, string_types):
            workspaces = [
                s.strip() for s in workspaces.split(',') if s.strip()
            ]
        elif isinstance(workspaces, Workspace):
            workspaces = [workspaces]

        if not workspaces:
            workspaces = self.get_workspaces()

        for ws in workspaces:
            ws_name = _name(ws)
            url = "{}/workspaces/{}/layergroups.xml".format(
                self.service_url, ws_name)
            try:
                groups = self.get_xml(url)
            except FailedRequestError as e:
                if "no such workspace" in str(e).lower():
                    continue
                else:
                    raise FailedRequestError(
                        "Failed to get layergroups: {}".format(e))

            layergroups.extend([
                LayerGroup(self,
                           g.find("name").text, ws_name)
                for g in groups.findall("layerGroup")
            ])

        if names is None:
            names = []
        elif isinstance(names, string_types):
            names = [s.strip() for s in names.split(',') if s.strip()]

        if layergroups and names:
            return ([lg for lg in layergroups if lg.name in names])

        return layergroups
Ejemplo n.º 2
0
 def get_layergroups(self):
     groups = self.get_xml("%s/layergroups.xml" % self.service_url)
     return [
         LayerGroup(self,
                    g.find("name").text)
         for g in groups.findall("layerGroup")
     ]
Ejemplo n.º 3
0
 def get_layergroup(self, name=None):
     try:
         group_url = url(self.service_url, ["layergroups", name + ".xml"])
         group = self.get_xml(group_url)
         return LayerGroup(self, group.find("name").text)
     except FailedRequestError:
         return None
Ejemplo n.º 4
0
    def get_layergroups(self, workspace=None):
        wks_name = None
        path_parts = ['layergroups.xml']
        if workspace is not None:
            wks_name = _name(workspace)
            path_parts = ['workspaces', wks_name] + path_parts

        groups_url = url(self.service_url, path_parts)
        groups = self.get_xml(groups_url)
        return [LayerGroup(self, g.find("name").text, wks_name) for g in groups.findall("layerGroup")]
Ejemplo n.º 5
0
 def get_layergroups(self, workspace=None):
     wks_name = None
     path_parts = "layergroups.xml"
     if workspace is not None:
         wks_name = _name(workspace)
         path_parts = "workspaces/{}/{}".format(wks_name, path_parts)
     groups_url = urljoin(self.service_url, path_parts)
     groups = self.get_xml(groups_url)
     return [
         LayerGroup(self, g.find("name").text, wks_name)
         for g in groups.findall("layerGroup")
     ]
Ejemplo n.º 6
0
    def get_layergroup(self, name=None, workspace=None):
        try:
            path_parts = ["layergroups", name + ".xml"]
            if workspace is not None:
                wks_name = _name(workspace)
                path_parts = ['workspaces', wks_name] + path_parts

            group_url = url(self.service_url, path_parts)
            group = self.get_xml(group_url)
            wks_name = group.find("workspace").find("name").text if group.find("workspace") else None
            return LayerGroup(self, group.find("name").text, wks_name)
        except FailedRequestError:
            return None
Ejemplo n.º 7
0
 def get_layergroup(self, name=None, workspace=None):
     try:
         path_parts = "layergroups/{}.xml".format(name)
         if workspace is not None:
             wks_name = _name(workspace)
             path_parts = "workspaces/{}".format(wks_name) + path_parts
         group_url = urljoin(self.service_url, path_parts)
         group = self.get_xml(group_url)
         if group.find("workspace"):
             wks_name = group.find("workspace").find("name").text
         else:
             wks_name = None
         return LayerGroup(self, group.find("name").text, wks_name)
     except FailedRequestError:
         return None
Ejemplo n.º 8
0
def survey_update_project(request, survey_id):
    try:
        survey = Survey.objects.get(id=survey_id)
        sections = SurveySection.objects.filter(
            survey=survey).order_by('order')
        permissions = SurveyReadGroup.objects.filter(survey=survey)
        '''
        Create the project
        '''
        if survey.project_id != None:
            project = Project.objects.get(id=survey.project_id)
            project.delete()

        project = Project(
            name=survey.name,
            title=survey.title,
            description=survey.title,
            center_lat=0,
            center_lon=0,
            zoom=2,
            extent=
            '-31602124.97422327,-7044436.526761844,31602124.97422327,7044436.526761844',
            toc_order={},
            toc_mode='toc_hidden',
            created_by=request.user.username,
            is_public=False)
        project.save()

        survey.project_id = project.id
        survey.save()

        lgname = str(project.id) + '_' + str(
            survey_id) + '_' + survey.name + '_' + request.user.username
        layergroup = LayerGroup(name=lgname,
                                title=survey.name,
                                cached=False,
                                created_by=request.user.username)
        layergroup.save()

        survey.layer_group_id = layergroup.id
        survey.save()

        mapservice_backend.reload_nodes()

        project_layergroup = ProjectLayerGroup(project=project,
                                               layer_group=layergroup)
        project_layergroup.save()
        assigned_layergroups = []
        prj_lyrgroups = ProjectLayerGroup.objects.filter(project_id=project.id)
        for prj_lyrgroup in prj_lyrgroups:
            assigned_layergroups.append(prj_lyrgroup.layer_group.id)

        toc_structure = core_utils.get_json_toc(assigned_layergroups)
        project.toc_order = toc_structure
        project.save()

        for permission in permissions:
            project_usergroup = ProjectUserGroup(
                project=project, user_group=permission.user_group)
            project_usergroup.save()
        '''
        Create the layers
        '''
        if project:
            lyorder = 0
            for section in sections:
                survey_section_update_project_operation(
                    request, survey, section, lyorder)
                lyorder = lyorder + 1

        response = {'result': 'OK'}

    except Exception as e:
        response = {'result': 'Error', 'message': str(e)}

    return HttpResponse(json.dumps(response, indent=4),
                        content_type='application/json')