示例#1
0
def tableResourcesText(request):
    """ Generates a text file containing a list of resources and their properties. """
    data_header = sharkdata_core.ResourcesUtils().getHeaders()
    translated_header = sharkdata_core.ResourcesUtils().translateHeaders(data_header)
    #
    data_rows = models.Resources.objects.values_list(*data_header)
    #
    response = HttpResponse(content_type = 'text/plain; charset=cp1252')    
    response['Content-Disposition'] = 'attachment; filename=sharkdata_resources.txt'    
    response.write('\t'.join(translated_header) + '\r\n') # Tab separated.
    for row in data_rows:
        response.write('\t'.join(row) + '\r\n') # Tab separated.        
    return response
    def updateDatasetsAndResources(self, logfile_name, user):
        """ """
        error_counter = 0
        try:
            sharkdata_core.SharkdataAdminUtils().log_write(
                logfile_name, log_row='\nDatasets:')
            error_counter += sharkdata_core.DatasetUtils(
            ).writeLatestDatasetsInfoToDb(logfile_name, )

            sharkdata_core.SharkdataAdminUtils().log_write(
                logfile_name, log_row='\nResources:')
            error_counter += sharkdata_core.ResourcesUtils(
            ).writeResourcesInfoToDb(logfile_name, )

            if error_counter > 0:
                sharkdata_core.SharkdataAdminUtils().log_close(
                    logfile_name,
                    new_status='FINISHED-' + str(error_counter) + '-errors')
            else:
                sharkdata_core.SharkdataAdminUtils().log_close(
                    logfile_name, new_status='FINISHED')

        except Exception as e:
            error_message = 'Failed when loading datasets or resources.' + '\nException: ' + str(
                e) + '\n'
            sharkdata_core.SharkdataAdminUtils().log_write(
                logfile_name, log_row=error_message)
            sharkdata_core.SharkdataAdminUtils().log_close(logfile_name,
                                                           new_status='FAILED')
        #
        return None  # No error message.
示例#3
0
 def translateDataHeaders(self,
                          data_header,
                          resource_name='translate_headers',
                          language='darwin_core'):
     #                        language = 'english'):
     """ """
     return sharkdata_core.ResourcesUtils().translateHeaders(
         data_header, resource_name, language)
示例#4
0
def listResourcesJson(request):
    """ Generates a JSON file containing a list of resources and their properties. """
    data_header = sharkdata_core.ResourcesUtils().getHeaders()
    resources_json = []
    #
    data_rows = models.Resources.objects.values_list(*data_header)
    for data_row in data_rows:
        row_dict = dict(zip(data_header, data_row))
        resources_json.append(row_dict)
    #
    response = HttpResponse(content_type = 'application/json; charset=cp1252')
    response['Content-Disposition'] = 'attachment; filename=sharkdata_resource_list.json'    
    response.write(json.dumps(resources_json, encoding = 'utf8'))
    return response
示例#5
0
def tableResourcesJson(request):
    """ Generates a text file containing a list of resources and their properties. 
        Organised as header and rows.
    """
    data_header = sharkdata_core.ResourcesUtils().getHeaders()
    #
    data_rows = models.Resources.objects.values_list(*data_header)
    #
    response = HttpResponse(content_type = 'application/json; charset=cp1252')
    response['Content-Disposition'] = 'attachment; filename=sharkdata_resources.json'    
    response.write('{')
    response.write('"header": ["')
    response.write('", "'.join(data_header) + '"], ') # Tab separated.
    response.write(u"'rows': [")
    row_delimiter = ''
    for row in data_rows:
        response.write(row_delimiter + '["' + '", "'.join(row) + '"]')      
        row_delimiter = ', '
    response.write(']')
    response.write('}')
    #
    return response