示例#1
0
    def setup_template_variables(self, context, data_dict):
        data_dict.update({'available_only': True})

        toolkit.c.groups_available = toolkit.c.userobj and \
            toolkit.c.userobj.get_groups('organization') or []
        toolkit.c.licences = [('', '')] + base.model.Package.get_license_options()
        toolkit.c.is_sysadmin = authz.Authorizer().is_sysadmin(toolkit.c.user)

        ## This is messy as auths take domain object not data_dict
        context_pkg = context.get('package', None)
        pkg = context_pkg or toolkit.c.pkg
        if pkg:
            try:
                if not context_pkg:
                    context['package'] = pkg
                logic.check_access('package_change_state', context)
                toolkit.c.auth_for_change_state = True
            except logic.NotAuthorized:
                toolkit.c.auth_for_change_state = False

        #Get MetroPulse fields and add them to the form
        here = os.path.dirname(__file__)
        rootdir = os.path.dirname(os.path.dirname(here))

        if 'cmap_data_family' in toolkit.c.pkg_dict:
            data_family = toolkit.c.pkg_dict['cmap_data_family']
        else:
            data_family = ''

        if 'cmap_data_category' in toolkit.c.pkg_dict:
            data_cat = toolkit.c.pkg_dict['cmap_data_category']
        else:
            data_cat = ''

        if 'cmap_data_subcategory' in toolkit.c.pkg_dict:
            data_subcat = toolkit.c.pkg_dict['cmap_data_subcategory']
	else:
            data_subcat = ''

        
        geogLevelsFile = open(os.path.join(rootdir, 'MetroPulseGeogLevels.xml'), 'r')
        geogLevelsXml = geogLevelsFile.read()

        fieldsFile = open(os.path.join(rootdir, 'MetroPulseFields.xml'), 'r')
        fieldsXml = fieldsFile.read()

        geogLevelsList = metropulse.getFilteredChildren(geogLevelsXml, "geoglevels", ('id', 'name'))
        toolkit.c.cmap_geog_levels = geogLevelsList

        dataFamilyList = metropulse.getFilteredChildren(fieldsXml, "data", ('id', 'caption'))
        toolkit.c.cmap_data_families = dataFamilyList


        # attributeRegEx regular expression narrows future values to ones 
        # that are children of current values (makes sure selections make sense together)
        
        attributeRegEx = {'id': data_family}
        dataCatList = metropulse.getFilteredChildren(fieldsXml, "datafamily", ('id', 'caption'), attributeRegEx)
        toolkit.c.cmap_data_categories = dataCatList

        attributeRegEx = {'id': data_cat}
        dataSubcatList = metropulse.getFilteredChildren(fieldsXml, "datacat", ('id', 'caption'), attributeRegEx)
        toolkit.c.cmap_data_subcategories = dataSubcatList

        attributeRegEx = {'id': data_subcat}
        dataFieldList = metropulse.getFilteredChildren(fieldsXml, "datasubcat", ('id', 'caption'), attributeRegEx)
        toolkit.c.cmap_data_fields = dataFieldList
示例#2
0
    def setup_template_variables(self, context, data_dict):
        data_dict.update({'available_only': True})

        toolkit.c.groups_available = toolkit.c.userobj and \
            toolkit.c.userobj.get_groups('organization') or []
        toolkit.c.licences = [('', '')
                              ] + base.model.Package.get_license_options()
        toolkit.c.is_sysadmin = authz.Authorizer().is_sysadmin(toolkit.c.user)

        ## This is messy as auths take domain object not data_dict
        context_pkg = context.get('package', None)
        pkg = context_pkg or toolkit.c.pkg
        if pkg:
            try:
                if not context_pkg:
                    context['package'] = pkg
                logic.check_access('package_change_state', context)
                toolkit.c.auth_for_change_state = True
            except logic.NotAuthorized:
                toolkit.c.auth_for_change_state = False

        #Get MetroPulse fields and add them to the form
        here = os.path.dirname(__file__)
        rootdir = os.path.dirname(os.path.dirname(here))

        if 'cmap_data_family' in toolkit.c.pkg_dict:
            data_family = toolkit.c.pkg_dict['cmap_data_family']
        else:
            data_family = ''

        if 'cmap_data_category' in toolkit.c.pkg_dict:
            data_cat = toolkit.c.pkg_dict['cmap_data_category']
        else:
            data_cat = ''

        if 'cmap_data_subcategory' in toolkit.c.pkg_dict:
            data_subcat = toolkit.c.pkg_dict['cmap_data_subcategory']
        else:
            data_subcat = ''

        geogLevelsFile = open(
            os.path.join(rootdir, 'MetroPulseGeogLevels.xml'), 'r')
        geogLevelsXml = geogLevelsFile.read()

        fieldsFile = open(os.path.join(rootdir, 'MetroPulseFields.xml'), 'r')
        fieldsXml = fieldsFile.read()

        geogLevelsList = metropulse.getFilteredChildren(
            geogLevelsXml, "geoglevels", ('id', 'name'))
        toolkit.c.cmap_geog_levels = geogLevelsList

        dataFamilyList = metropulse.getFilteredChildren(
            fieldsXml, "data", ('id', 'caption'))
        toolkit.c.cmap_data_families = dataFamilyList

        # attributeRegEx regular expression narrows future values to ones
        # that are children of current values (makes sure selections make sense together)

        attributeRegEx = {'id': data_family}
        dataCatList = metropulse.getFilteredChildren(fieldsXml, "datafamily",
                                                     ('id', 'caption'),
                                                     attributeRegEx)
        toolkit.c.cmap_data_categories = dataCatList

        attributeRegEx = {'id': data_cat}
        dataSubcatList = metropulse.getFilteredChildren(
            fieldsXml, "datacat", ('id', 'caption'), attributeRegEx)
        toolkit.c.cmap_data_subcategories = dataSubcatList

        attributeRegEx = {'id': data_subcat}
        dataFieldList = metropulse.getFilteredChildren(fieldsXml, "datasubcat",
                                                       ('id', 'caption'),
                                                       attributeRegEx)
        toolkit.c.cmap_data_fields = dataFieldList
示例#3
0
import cgi
import cgitb
import json

form = cgi.FieldStorage()
data_family = form.getvalue("data_family")
data_cat = form.getvalue("data_cat")
data_subcat = form.getvalue("data_subcat")

geogLevelsFile = open('MetroPulseGeogLevels.xml', 'r')
geogLevelsXml = geogLevelsFile.read()

fieldsFile = open('MetroPulseFields.xml', 'r')
fieldsXml = fieldsFile.read()

geogLevelsList = metropulse.getFilteredChildren(geogLevelsXml, "geoglevels", ('id', 'name'))

dataFamilyList = metropulse.getFilteredChildren(fieldsXml, "data", ('id', 'caption'))


# attributeRegEx regular expression narrows future values to ones
# that are children of current values (makes sure selections make sense together)
rlist = ""

if data_family:
    attributeRegEx = {'id': data_family}
    rlist = metropulse.getFilteredChildren(fieldsXml, "datafamily", ('id', 'caption'), attributeRegEx)
elif data_cat:
    attributeRegEx = {'id': data_cat}
    rlist = metropulse.getFilteredChildren(fieldsXml, "datacat", ('id', 'caption'), attributeRegEx)
elif data_subcat:
    def before_view(self, pkg_dict):

        geog_level = ''
        data_family = ''
        data_category = ''
        data_subcategory = ''
        data_field = ''

        if len(
                pkg_dict['extras']
        ) > 0 and toolkit.c.action == 'read' and toolkit.request.path.split(
                "/")[1] == 'dataset':
            for extra in pkg_dict['extras']:
                if extra['key'] == 'cmap_geographical_level':
                    geog_level = extra['value']

                if extra['key'] == 'cmap_data_family':
                    data_family = extra['value']

                if extra['key'] == 'cmap_data_category':
                    data_category = extra['value']

                if extra['key'] == 'cmap_data_subcategory':
                    data_subcategory = extra['value']

                if extra['key'] == 'cmap_data_field':
                    data_field = extra['value']

            GEOG_LEVEL_NOT_FOUND_ALERT = 'Error: Geographical Level Not Found'
            DATA_FAMILY_NOT_FOUND_ALERT = 'Error: Data Family Not Found'
            ID_DOES_NOT_MATCH_ALERT = 'Error: ID Does Not Match Other Selections'

            here = os.path.dirname(__file__)
            rootdir = os.path.dirname(os.path.dirname(here))

            geogLevelsFile = open(
                os.path.join(rootdir, 'MetroPulseGeogLevels.xml'), 'r')
            geogLevelsXml = geogLevelsFile.read()

            fieldsFile = open(os.path.join(rootdir, 'MetroPulseFields.xml'),
                              'r')
            fieldsXml = fieldsFile.read()

            if geog_level != '':
                geogLevelsList = mp.getFilteredChildren(
                    geogLevelsXml, "geoglevels", ('id', 'name'))
                toolkit.c.cmap_geographical_level = GEOG_LEVEL_NOT_FOUND_ALERT
                for i, v in enumerate(geogLevelsList):
                    if v[0] == geog_level:
                        toolkit.c.cmap_geographical_level = v[1]
                        break
            else:
                toolkit.c.cmap_geographical_level = ''

            if data_family != '':
                metalist = mp.getFilteredChildren(fieldsXml, "data",
                                                  ('id', 'caption'))
                toolkit.c.cmap_data_family = DATA_FAMILY_NOT_FOUND_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_family:
                        toolkit.c.cmap_data_family = v[1]
                        break
            else:
                toolkit.c.cmap_data_family = ''

            if data_category != '':
                attributeRegEx = {'id': data_family}
                metalist = mp.getFilteredChildren(fieldsXml, "datafamily",
                                                  ('id', 'caption'),
                                                  attributeRegEx)
                toolkit.c.cmap_data_category = ID_DOES_NOT_MATCH_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_category:
                        toolkit.c.cmap_data_category = v[1]
                        break
            else:
                toolkit.c.cmap_data_category = ''

            if data_subcategory != '':
                attributeRegEx = {'id': data_category}
                metalist = mp.getFilteredChildren(fieldsXml, "datacat",
                                                  ('id', 'caption'),
                                                  attributeRegEx)
                toolkit.c.cmap_data_subcategory = ID_DOES_NOT_MATCH_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_subcategory:
                        toolkit.c.cmap_data_subcategory = v[1]
                        break
            else:
                toolkit.c.cmap_data_subcategory = ''

            if data_field != '':
                attributeRegEx = {'id': data_subcategory}
                metalist = mp.getFilteredChildren(fieldsXml, "datasubcat",
                                                  ('id', 'caption'),
                                                  attributeRegEx)
                toolkit.c.cmap_data_field = ID_DOES_NOT_MATCH_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_field:
                        toolkit.c.cmap_data_field = v[1]
                        break
            else:
                toolkit.c.cmap_data_field = ''

            #Add resources that use the MetroPulse API
            mp.auto_add_metropulse_resources(geog_level, data_subcategory,
                                             data_field, pkg_dict)

        return pkg_dict
    def before_view(self, pkg_dict):

        geog_level = ''
        data_family = ''
        data_category = ''
        data_subcategory = ''
        data_field = ''
       
        if len(pkg_dict['extras']) > 0 and toolkit.c.action == 'read' and toolkit.request.path.split("/")[1] == 'dataset':   
            for extra in pkg_dict['extras']:
                if extra['key'] == 'cmap_geographical_level':
                    geog_level = extra['value']

                if extra['key'] == 'cmap_data_family':
                    data_family = extra['value']

                if extra['key'] == 'cmap_data_category':
                    data_category = extra['value']

                if extra['key'] == 'cmap_data_subcategory':
                    data_subcategory = extra['value']

                if extra['key'] == 'cmap_data_field':
                    data_field = extra['value']

            GEOG_LEVEL_NOT_FOUND_ALERT = 'Error: Geographical Level Not Found'
            DATA_FAMILY_NOT_FOUND_ALERT = 'Error: Data Family Not Found'
            ID_DOES_NOT_MATCH_ALERT = 'Error: ID Does Not Match Other Selections'
     
            here = os.path.dirname(__file__)
            rootdir = os.path.dirname(os.path.dirname(here))
            
            geogLevelsFile = open(os.path.join(rootdir, 'MetroPulseGeogLevels.xml'), 'r')
            geogLevelsXml = geogLevelsFile.read()

            fieldsFile = open(os.path.join(rootdir, 'MetroPulseFields.xml'), 'r')
            fieldsXml = fieldsFile.read()
           
            if geog_level != '':
                geogLevelsList = mp.getFilteredChildren(geogLevelsXml, "geoglevels", ('id', 'name'))
                toolkit.c.cmap_geographical_level = GEOG_LEVEL_NOT_FOUND_ALERT
                for i, v in enumerate(geogLevelsList):
                    if v[0] == geog_level:
                        toolkit.c.cmap_geographical_level = v[1]
                        break
            else:
                toolkit.c.cmap_geographical_level = ''

            if data_family != '':
                metalist = mp.getFilteredChildren(fieldsXml, "data", ('id', 'caption'))
                toolkit.c.cmap_data_family = DATA_FAMILY_NOT_FOUND_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_family:
                        toolkit.c.cmap_data_family = v[1]
                        break
            else:
                toolkit.c.cmap_data_family = ''
            
            if data_category != '':
                attributeRegEx = {'id': data_family}
                metalist = mp.getFilteredChildren(fieldsXml, "datafamily", ('id', 'caption'), attributeRegEx)
                toolkit.c.cmap_data_category = ID_DOES_NOT_MATCH_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_category:
                        toolkit.c.cmap_data_category = v[1]
                        break
            else:
                toolkit.c.cmap_data_category = ''

            if data_subcategory != '':
                attributeRegEx = {'id': data_category}
                metalist = mp.getFilteredChildren(fieldsXml, "datacat", ('id', 'caption'), attributeRegEx)
                toolkit.c.cmap_data_subcategory = ID_DOES_NOT_MATCH_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_subcategory:
                        toolkit.c.cmap_data_subcategory = v[1]
                        break
            else:
                toolkit.c.cmap_data_subcategory = ''

            if data_field != '':
                attributeRegEx = {'id': data_subcategory}
                metalist = mp.getFilteredChildren(fieldsXml, "datasubcat", ('id', 'caption'), attributeRegEx)
                toolkit.c.cmap_data_field = ID_DOES_NOT_MATCH_ALERT
                for i, v in enumerate(metalist):
                    if v[0] == data_field:
                        toolkit.c.cmap_data_field = v[1]
                        break
            else:
                 toolkit.c.cmap_data_field = ''

                            
            #Add resources that use the MetroPulse API
            mp.auto_add_metropulse_resources(geog_level, data_subcategory, data_field, pkg_dict)
       
        return pkg_dict
示例#6
0
import cgi
import cgitb
import json

form = cgi.FieldStorage()
data_family = form.getvalue("data_family")
data_cat = form.getvalue("data_cat")
data_subcat = form.getvalue("data_subcat")

geogLevelsFile = open('MetroPulseGeogLevels.xml', 'r')
geogLevelsXml = geogLevelsFile.read()

fieldsFile = open('MetroPulseFields.xml', 'r')
fieldsXml = fieldsFile.read()

geogLevelsList = metropulse.getFilteredChildren(geogLevelsXml, "geoglevels",
                                                ('id', 'name'))

dataFamilyList = metropulse.getFilteredChildren(fieldsXml, "data",
                                                ('id', 'caption'))

# attributeRegEx regular expression narrows future values to ones
# that are children of current values (makes sure selections make sense together)
rlist = ""

if data_family:
    attributeRegEx = {'id': data_family}
    rlist = metropulse.getFilteredChildren(fieldsXml, "datafamily",
                                           ('id', 'caption'), attributeRegEx)
elif data_cat:
    attributeRegEx = {'id': data_cat}
    rlist = metropulse.getFilteredChildren(fieldsXml, "datacat",