Ejemplo n.º 1
0
    def get(self, request, record_slug):
        try:
            try:
                self.val_module = self.load_validation_module(record_slug)
            except:
                pass
            else:
                self.load_csv_module = self.load_dataset_csv(record_slug)
                self.models = self.load_module_modules(record_slug.upper())
                self.allrecords = self.load_records_in_model(self.models)
                #self.load_records_in_model(self.load_module_modules(record_slug))

                self.h = self.load_headers()
                self.hs = self.append_headers_to_list(self.h)
                self.filename = self.load_filenames(
                    self.h.pi_identification_code, record_slug)
                self.extension = self.dataset = datasetmatch.load_file_extension(
                    record_slug)

                self.hs.append(self.extension)
                self.ret = self.write_csv(self.filename, self.allrecords,
                                          self.hs, self.load_csv_module)
                return self.ret
        except:
            pass
Ejemplo n.º 2
0
    def get(self, request, record_slug):
        try:
            try:
                try:
                    self.val_module = self.load_validation_module(record_slug)
                except:
                    raise
                else:
                    self._csv_module = self.load_csv_validated_module(
                        record_slug)
                    self.models = self.load_module_modules(record_slug.upper())
                    self.allrecords = self.load_records_in_model(self.models)

                    self.h = self.load_headers()
                    self.lheaders = self.append_headers_to_list(self.h)
                    self.filename = self.load_filenames(
                        self.h.pi_identification_code, record_slug)
                    self.extension = datasetmatch.load_file_extension(
                        record_slug)
                    self.lheaders.append(self.extension)

                    self.retcsvs = self.write_v_csv(self.filename,
                                                    self.allrecords,
                                                    self._csv_module,
                                                    self.val_module,
                                                    self.lheaders)
                    return self.retcsvs
            except:
                raise
        except:
            raise
Ejemplo n.º 3
0
 def get(self, request, record_slug):
     try:
         if(record_slug):
             self._csv_module = self.load_csv_validated_module(record_slug)
             self.model = self.load_module_modules(record_slug)
             self.records = self.load_records_in_model(self.model)
             self.validation_code = self.load_validation_code(record_slug)
             
             #grab the headers
             self.h = self.load_headers()
             self.lheaders = self.append_headers_to_list(self.h)
             self.h.pi_identification_code
             self.filename = self.load_filenames(self.h.pi_identification_code, record_slug)
             self.extension =  datasetmatch.load_file_extension(record_slug)
             self.lheaders.append(self.extension)
             
             try:
                 self.joined = os.path.join(settings.MEDIA_ROOT, self.filename)
                 self.filelineno = self.create_file_object(self.joined)
                 self.csvfile = self.write_csv(self.records, self.filename, self._csv_module, self.validation_code, self.lheaders, self.filelineno)
                 self.ret = self.save_validation_in_database(self.joined, self.filename, self.filelineno)
                 if(self.ret):
                     return HttpResponseRedirect("/importdata/showsaved/andvalidated/")
                 else:
                     return HttpResponseServerError(self.ret)
                 self.filelineno.close()
             except:
                 raise 
             return HttpResponse("Working")
         else:
             return HttpResponse("FAILURE ")
     except:
         raise 
Ejemplo n.º 4
0
 def load_filenames(self, pi_code, dataset):
     """
     Load and return the filename.filenaming
     """
     try:
         self.dataset = datasetmatch.load_file_extension(dataset)
         if(self.dataset):
             return filenaming.make_filename(pi_code=pi_code, filename=self.dataset)
         else:
             return False 
     except:
         raise 
Ejemplo n.º 5
0
 def load_filenames(self, pi_code, dataset):
     """
     Load and return the filename.filenaming
     """
     try:
         self.dataset = datasetmatch.load_file_extension(dataset)
         if (self.dataset):
             self.filenames = filenaming.make_filename(
                 pi_code=pi_code, filename=self.dataset)
             print "HERE WE ARE ", self.filenames, self.dataset, pi_code, dataset
             return self.filenames
         else:
             return False
     except:
         raise
Ejemplo n.º 6
0
    def make_validation_report(self,
                               model,
                               validation_module,
                               dataset,
                               headers=None):
        """
        Create a validation Report.
        """
        self.reporter = reportstatus.ReportStatus(model_data=model)
        self.report_model = loadreportmodels.load_report_model_module(dataset)

        self.dataset_name = datasetmatch.load_file_extension(dataset)

        if (self.reporter and self.report_model):
            try:
                validation_module.begin_validation()
                self.validation_result = validation_module.get_real_passed()

                #print self.validation_result
                self.reporter.analyse_failed_passed(self.validation_result)
                #print "PASSED FIELDS ", self.reporter.get_passed()
                #print "FAILED FIELD ", self.reporter.get_failed()
                #print "TOTAL COUNT ", self.reporter.get_data_count()
                validation_module.analysis_records()
                #print "PASSED RECORDS ", validation_module.get_passed_records()
                #print "FAILED RECORDS ", validation_module.get_failed_records()
                #print validation_module.get_passed_by_id()
                self.save_status = self.save_report_results(
                    self.report_model, self.reporter, validation_module,
                    self.dataset_name, headers)
                if (self.save_status):
                    #return self.save_status
                    self.analysed = self.plot_graph(validation_module,
                                                    self.reporter,
                                                    self.dataset_name)
                    if (self.analysed):
                        return self.save_status
                    else:
                        return False
                else:
                    return self.save_status
                return True
            except:
                raise
        else:
            return False
Ejemplo n.º 7
0
    def process_context(self, request, record):
        try:
            self.template = self.load_search_template("analysispage.html")
            if (self.template):
                try:
                    self.datasetrecords = get_datarecords()
                    self.data_extension = datasetmatch.load_file_extension(
                        record)
                    self.all_returned = self.return_allfiltered(
                        self.data_extension)

                    self.paginated_gra = Paginator(self.all_returned, 1)

                    self.next_page = request.GET.get("page")
                    try:
                        self.gra_page = self.paginated_gra.page(self.next_page)
                    except PageNotAnInteger:
                        self.gra_page = self.paginated_gra.page(1)
                    except EmptyPage:
                        self.gra_page = self.paginated_gra.page(
                            self.paginated_gra.num_pages)

                    self.context = RequestContext(
                        request, {
                            "basetitle": mytitle,
                            "datasetrecords": self.datasetrecords,
                            "records_to_search": record,
                            "Exenstion": self.data_extension,
                            "allgraphed": self.gra_page
                        })
                    return self.template.render(self.context)
                except:
                    raise
            else:
                return None
        except:
            raise
Ejemplo n.º 8
0
    def post(self, request):
        """
        Process the post request.
        """
        self.template = loader.get_template("dataprocessingview.html")
        try:
            self.headers = request.POST.get("header", "")
            self.pi_code = request.POST.get("pi_identification_code", "")
            self.insitution_name = request.POST.get("institution_name", "")
            self.sub_date = request.POST.get("submission_date", "")
            self.version = request.POST.get("version_number" "")
            self.creation_date = request.POST.get("creation_date", "")

            self.query_picode = self.query_PIIdentificationCode(self.pi_code)

            self.outputformat = request.POST.get("outputformat", "")
            self.sub_date = self.sub_date.replace("-", "", len(self.sub_date))

            self.validated = request.POST.get("validated")
            self.dataset = request.POST.get("dataset", "")
            self.dataset = self.dataset.replace(" ", "_",
                                                len(self.dataset)).lower()
            self.extension = datasetmatch.load_file_extension(self.dataset)
            self.data_headers = [
                self.headers, self.pi_code, self.insitution_name,
                self.sub_date, self.version,
                self.creation_date.replace('-', "", len(self.creation_date)),
                self.extension
            ]

            if (self.first_validate(self.validated)):
                try:
                    #A request to first perform the validation of data.
                    self.data_validator = self.load_validation_module(
                        self.dataset)
                    self.load_csv = self.load_csv_module(self.dataset)
                    self.model = self.load_model(self.dataset)
                    self.allrecords = self.load_records(self.model)

                    try:
                        self.filename = self.load_filenames(
                            self.query_picode, self.dataset)
                        self.validated_csv = self.write_csv(
                            self.filename, self.allrecords, self.load_csv,
                            self.data_validator, self.data_headers)
                        if (self.validated_csv):
                            return self.validated_csv
                        else:  #perrors
                            self.datasetrecords = self.get_datarecords()
                            self.context = RequestContext(
                                request, {
                                    "perrors":
                                    "ERROR Processing request pliz report or try again with properly formated dadta",
                                    "datasetrecords": self.datasetrecords,
                                })
                            return HttpResponse(
                                self.template.render(self.context))
                    except Exception as e:

                        self.datasetrecords = self.get_datarecords()
                        self.context = RequestContext(
                            request, {
                                "perrors": e.message,
                                "datasetrecords": self.datasetrecords,
                            })
                        return HttpResponse(self.template.render(self.context))

                        raise

                except Exception as e:

                    self.datasetrecords = self.get_datarecords()
                    self.context = RequestContext(
                        request, {
                            "perrors": e.message,
                            "datasetrecords": self.datasetrecords,
                        })
                    return HttpResponse(self.template.render(self.context))

                    raise
            else:
                try:
                    self.model = self.load_model(self.dataset)
                    self.allrecords = self.load_records(self.model)
                    self.csvmodel = self.load_none_validated_csv(self.dataset)
                    self.filename = self.load_filenames(
                        self.query_picode, self.dataset)
                    self.returned_csv = self.write_none_csv(
                        self.filename,
                        self.allrecords,
                        self.csvmodel,
                        headers=self.data_headers)
                    if (self.returned_csv):
                        return self.returned_csv
                    else:
                        self.datasetrecords = self.get_datarecords()
                        self.context = RequestContext(
                            request, {
                                "perrors": "ERRO performing processing",
                                "datasetrecords": self.datasetrecords,
                            })
                        return HttpResponse(self.template.render(self.context))
                except Exception as e:
                    '''
                    self.datasetrecords = self.get_datarecords()
                    self.context = RequestContext(request, {"perrors":e.message,
                                                        "datasetrecords":self.datasetrecords,
                                                        })
                    return HttpResponse(self.template.render(self.context))
                    '''
                    raise
        except Exception as e:

            self.datasetrecords = self.get_datarecords()
            self.context = RequestContext(
                request, {
                    "perrors": e.message,
                    "datasetrecords": self.datasetrecords,
                })
            return HttpResponse(self.template.render(self.context))

            raise