Example #1
0
    def put(self, request):
        # If authenticated
        if request.auth or request.user.is_authenticated():
            user = request.user
            result = {}

            if user.is_superuser or user.groups.filter(name='importers').exists():

                iq = ImportQuestionnaire.factory('excel', request.DATA)
                iq.import_questionnaire()

                result['status'] = 'authenticated'
                result['method'] = 'POST'
                result['user'] = str(user)
            else:
                result['status'] = 'forbidden'
                result['method'] = 'POST'
                result['user'] = str(user)

        # NOT authenticated
        else:
            result = {'status': 'NOT authenticated', 'method': 'POST'}

        response = Response(result, status=status.HTTP_200_OK)
        return response
Example #2
0
    def put(self, request):
        # If authenticated
        if request.auth or request.user.is_authenticated():
            user = request.user
            result = {}

            if user.is_superuser or user.groups.filter(
                    name='importers').exists():

                iq = ImportQuestionnaire.factory('excel', request.DATA)
                iq.import_questionnaire()

                result['status'] = 'authenticated'
                result['method'] = 'POST'
                result['user'] = str(user)
            else:
                result['status'] = 'forbidden'
                result['method'] = 'POST'
                result['user'] = str(user)

        # NOT authenticated
        else:
            result = {'status': 'NOT authenticated', 'method': 'POST'}

        response = Response(result, status=status.HTTP_200_OK)
        return response
Example #3
0
    def post(self, request):
        try:
            uploaded_file = request.FILES['file']

            iq = ImportQuestionnaire.factory('excel', uploaded_file)
            iq.import_questionnaire()
            return self.get(request, success_message="Questionnaire imported, to import another questionnaire please add it below.")
        except:
            return self.get(request, error_message="Error importing questionnaire. Make sure you are importing a xlsx file with a questionnaire schema. If the problem persists please try again later, or contact the administrator.")
Example #4
0
    def handle(self, *args, **options):
        if len(args) == 1:

            iq = ImportQuestionnaire.factory('excel', args[0])

            iq.import_questionnaire()

            print "-- Finished processing " + args[0]

        else:
            self.stdout.write(
                '-- USAGE: \n    ' +
                'python manage.py import_questionnaire <path_file>' + '\n\n')
    def handle(self, *args, **options):
        if len(args) == 1:

            iq = ImportQuestionnaire.factory('excel', args[0])

            iq.import_questionnaire()

            print "-- Finished processing "+args[0]

        else:
            self.stdout.write('-- USAGE: \n    '+
                'python manage.py import_questionnaire <path_file>'+
                '\n\n')
    def post(self, request):
        try:
            uploaded_file = request.FILES['file']

            iq = ImportQuestionnaire.factory('excel', uploaded_file)
            iq.import_questionnaire()
            return self.get(
                request,
                success_message=
                "Questionnaire imported, to import another questionnaire please add it below."
            )
        except:
            return self.get(
                request,
                error_message=
                "Error importing questionnaire. Make sure you are importing a xlsx file with a questionnaire schema. If the problem persists please try again later, or contact the administrator."
            )
Example #7
0
    def handle(self, *args, **options):
        if len(args) == 2:

            iq = ImportQuestionnaire.factory('excel', args[0])

            if options['similar'] != 1:
                print "Similarity mode"
                def infer_function(question, new, old):
                    # default map translations that need no manual confirmation( this should go to a separate file later)
                    default_map = {
                        'Repeated collection(more than once)': 'Repeated collection (specify frequency and/or time interval) ',
                        'Subgroup analyzed (eg. Dementia)': 'Subgroup analyzed (eg. Dementia, please specify subgroup)'
                    }

                    try:
                        if ratio(unicode(default_map[old]), unicode(new)) > 0.97:
                            return True

                        return False

                    except KeyError:
                        print "Not default mapping, manual input required"

                    input = None


                    # Ignore low scores automatically
                    if ratio(old, new) < float(options['ignore']):
                        return False

                    while not (input == 'y' or input == 'n'):
                        print """The number of new choices missing processing for question %s is 1, there could be a non obvious match.\n

                        Is '%s' a change of '%s' ? (y/n)
                        """ % (question, new, old)
                        input = raw_input()

                    if input == 'y':
                        return True

                    return False

                res = iq.import_questionnaire(merge=args[1], mode=ImportQuestionnaireExcel.SIMILARITY_MODE,
                    percentage=float(options['similar']), infer_function=infer_function)


            else:
                print "Exact match mode"

                res = iq.import_questionnaire(merge=args[1])


            print "RESULT:"
            print res

            print "-- Finished processing "+args[0]

        else:
            self.stdout.write('-- USAGE: \n    '+
                'python manage.py merge_questionnaire <path_file> <questionnaire_id> [--similar=<percentage> --ignore=<percentage>]'+
                '\n\n')