def whatever():
    id = 'wisid_RegionProfileData2016_56c377709c1c5'

    data = [u'taccpuPSch', u'accprPhar', u'popEleRol', u'accpuPSch', u'taccprGP', u'accpuFood', u'accprGP', u'hlthLLTI',
            u'taccpuPO', u'popSpkWlsh', u'taccpuLib', u'accprPO', u'taccprPhar', u'pop16to64', u'accprFood', u'taccprPSch',
            u'taccprPO', u'popTotPop', u'emyInact', u'accpuSSch', u'accprLC', u'houFlat', u'houSDet', u'accpuPO',
            u'houAll', u'taccpuFood', u'pop65plus', u'hlthLExpF', u'accprLib', u'eduThres2', u'accpuGP', u'accpuLib',
            u'taccpuLC', u'taccpuSSch', u'eduNQF4', u'hlthLExpM', u'houTer', u'accpuPhar', u'taccpuPhar', u'accprSSch',
            u'accprPetrl', u'emyEmploy', u'taccprLib', u'taccprSSch', u'accpuLC', u'houTaxEF', u'taccprFood',
            u'taccprPetr', u'taccpuGP', u'accprPSch', u'houTaxGI', u'pop0to15', u'eduNoQual', u'houTaxCD', u'emyBenClai',
            u'houDet', u'emyWkEarn', u'houTaxAB', u'taccprLC']


    for d in data:

        uuid_str = str(uuid.uuid4())

        nomis_search = models.NomisSearch()
        nomis_search.uuid = uuid_str
        nomis_search.user = get_request_user(None)
        nomis_search.dataset_id = dataset_id
        nomis_search.geography_id = geog
        nomis_search.search_attributes = codelist_to_attributes(codelist)
        nomis_search.search_type = models.SearchType.objects.get(name='Nomis')
        nomis_search.save()
def whatever():
    id = 'wisid_RegionProfileData2016_56c377709c1c5'

    data = [
        u'taccpuPSch', u'accprPhar', u'popEleRol', u'accpuPSch', u'taccprGP',
        u'accpuFood', u'accprGP', u'hlthLLTI', u'taccpuPO', u'popSpkWlsh',
        u'taccpuLib', u'accprPO', u'taccprPhar', u'pop16to64', u'accprFood',
        u'taccprPSch', u'taccprPO', u'popTotPop', u'emyInact', u'accpuSSch',
        u'accprLC', u'houFlat', u'houSDet', u'accpuPO', u'houAll',
        u'taccpuFood', u'pop65plus', u'hlthLExpF', u'accprLib', u'eduThres2',
        u'accpuGP', u'accpuLib', u'taccpuLC', u'taccpuSSch', u'eduNQF4',
        u'hlthLExpM', u'houTer', u'accpuPhar', u'taccpuPhar', u'accprSSch',
        u'accprPetrl', u'emyEmploy', u'taccprLib', u'taccprSSch', u'accpuLC',
        u'houTaxEF', u'taccprFood', u'taccprPetr', u'taccpuGP', u'accprPSch',
        u'houTaxGI', u'pop0to15', u'eduNoQual', u'houTaxCD', u'emyBenClai',
        u'houDet', u'emyWkEarn', u'houTaxAB', u'taccprLC'
    ]

    for d in data:

        uuid_str = str(uuid.uuid4())

        nomis_search = models.NomisSearch()
        nomis_search.uuid = uuid_str
        nomis_search.user = get_request_user(None)
        nomis_search.dataset_id = dataset_id
        nomis_search.geography_id = geog
        nomis_search.search_attributes = codelist_to_attributes(codelist)
        nomis_search.search_type = models.SearchType.objects.get(name='Nomis')
        nomis_search.save()
Exemple #3
0
def survey_metadata(request, wiserd_id):
    wiserd_id = wiserd_id.strip()

    user_profile = get_request_user(request)
    allowed, access_data = survey_visible_to_user(wiserd_id, user_profile)

    surveys = []
    if allowed:
        survey_models = models.Survey.objects.all().filter(identifier=wiserd_id).values("surveyid", "identifier", "survey_title", "datacollector", "collectionstartdate", "collectionenddate", "moc_description", "samp_procedure", "collectionsituation", "surveyfrequency", "surveystartdate", "surveyenddate", "des_weighting", "samplesize", "responserate", "descriptionofsamplingerror", "dataproduct", "dataproductid", "location", "link", "notes", "user_id", "created", "updated", "long", "short_title", "spatialdata")
        for survey_model in survey_models:
            surveys.append({
                'data': survey_model,
                'wiserd_id': wiserd_id
            })
    else:
        # TODO decide if more info is needed here
        pass

    api_data = {
        'url': request.get_full_path(),
        'method': 'survey_metadata',
        'search_result_data': surveys,
        'results_count': len(surveys),
        'access_data': access_data,
        'read_access': allowed
    }
    return HttpResponse(json.dumps(api_data, indent=4, default=date_handler), content_type="application/json")
 def get_login_redirect_url(self, request):
     request_user = get_request_user(request)
     # If the user hasn't been shown the welcome screen before, show it now.
     if not request_user.init_user:
         return reverse("welcome")
     else:
         print "user role", request_user.role
         if request_user.role == "naw":
             return reverse("naw_dashboard")
         else:
             return reverse("index")
Exemple #5
0
 def get_login_redirect_url(self, request):
     request_user = get_request_user(request)
     # If the user hasn't been shown the welcome screen before, show it now.
     if not request_user.init_user:
         return reverse('welcome')
     else:
         print 'user role', request_user.role
         if request_user.role == 'naw':
             return reverse('naw_dashboard')
         else:
             return reverse('index')
def usage_tracker(request):
    userr = get_request_user(request)

    # print 'User loaded a page : ', userr.user.username, datetime.now(), get_client_ip(request), request.get_full_path()
    if 'admin_tools' not in request.get_full_path():
        ut = models.UserTracking()
        ut.user = userr
        ut.ip = get_client_ip(request)
        ut.url = request.get_full_path()
        ut.save()

    return {}
Exemple #7
0
def convert_csv_to_json(csv_file):
    reader = csv.reader(open(csv_file, 'r'))
    header = None
    ds = []

    for r in reader:
        if header:
            d = dict()
            for idx, h in enumerate(header):
                if h:
                    d[h] = r[idx]
            ds.append(d)
        else:
            header = r

    print header
    print pprint.pformat(ds)
    fixtures = []
    categories = []
    for idx, d in enumerate(ds):
        d['geom'] = "POINT ({} {})".format(d['x'], d['y'])
        categories.append(d['category'].strip())
        fixtures.append(
            {
                "pk": str(idx),
                "model": "dataportal3.WMHpoints",
                "fields": d
            }
        )

    with open('mining_features.json', 'w') as mhw_fixtures:
        mhw_fixtures.write(json.dumps(fixtures, indent=4))

    from django.core.management import call_command

    call_command('loaddata', 'mining_features.json', app_label='dataportal3', database='new')

    html_snippet = '''
    <li>
        <a href="#" data-wiserd_layer_uuid="{}" class="wiserd_layer_toggle">
            <i class="fa fa-map-marker fa-fw"></i> {}
        </a>
    </li>
'''
    ns, created = models.NomisSearch.objects.get_or_create(
        uuid = 'WMHpoints',
        user=get_request_user()
    )
    ns.name = 'All Locations'
    ns.uuid = 'WMHpoints'
    ns.dataset_id = 'WMHpoints'
    ns.geography_id = ''
    ns.search_attributes = {}
    ns.display_attributes = {
        "bin_num": "5",
        "bin_type": "q",
        "colorpicker": "YlGnBu",
        "point_icon": "fa-bolt",
        "remote_value_key": "category",
    }
    ns.display_fields = {}
    ns.search_type = models.SearchType.objects.get(name='LocalResearch')
    ns.save()

    all_html = html_snippet.format('WMHpoints', 'All locations')

    for category in set(categories):
        ns, created = models.NomisSearch.objects.get_or_create(
            uuid = 'WMHpoints_{}'.format(category.replace(' ', '_')),
            user=get_request_user()
        )
        ns.name = '{}'.format(category)
        ns.dataset_id = 'WMHpoints'
        ns.geography_id = ''
        ns.search_attributes = {}
        ns.display_attributes = {
            "bin_num": "5",
            "bin_type": "q",
            "colorpicker": "YlGnBu",
            "point_icon": "fa-bolt",
            "remote_value_key": "category",
            "filter": category
        }
        ns.display_fields = {}
        ns.search_type = models.SearchType.objects.get(name='LocalResearch')
        ns.save()

        all_html += html_snippet.format(ns.uuid, category)

    print all_html