def handle(self, *args, **options): if len(args) == 1: with zipfile.ZipFile(args[0], "r") as zip: meta = json.loads(zip.read('metadata.json'), object_hook=json_util.object_hook) fdict = json.loads(zip.read('fingerprint.json'), object_hook=json_util.object_hook) new_fingerprint = Fingerprint() new_hash = None level = self.__checkFeasibility(meta, fdict) if level == AS_IS: self.stdout.write( '-- Hash/fingerprint_id are free, import as is on exported file.\n' ) new_fingerprint.__dict__.update(fdict) new_fingerprint.save() self.__import(zip, args[0], new_fingerprint) elif level == NEW_IDS: self.stdout.write( '-- Hash/fingerprint_id are occupied, importing with a new id.\n' ) new_hash = generate_hash() fdict['fingerprint_hash'] = new_hash del fdict['id'] new_fingerprint.__dict__.update(fdict) new_fingerprint.save() self.__addShares(meta, new_fingerprint) self.__import(zip, args[0], new_fingerprint, replacing=True) else: # impossible self.stdout.write( '-- ERROR: Impossible to import fingerprint, the questionnaire doesnt exist, or doesnt match the slug.' ) else: self.stdout.write( '-- USAGE: \n ' + 'python manage.py fingerprint_import <path_file>' + '\n\n')
def handle(self, *args, **options): if len(args) == 1: with zipfile.ZipFile(args[0],"r") as zip: meta = json.loads(zip.read('metadata.json'),object_hook=json_util.object_hook) fdict = json.loads(zip.read('fingerprint.json'),object_hook=json_util.object_hook) new_fingerprint = Fingerprint() new_hash =None level = self.__checkFeasibility(meta, fdict) if level == AS_IS: self.stdout.write('-- Hash/fingerprint_id are free, import as is on exported file.\n') new_fingerprint.__dict__.update(fdict) new_fingerprint.save() self.__import(zip, args[0], new_fingerprint) elif level == NEW_IDS: self.stdout.write('-- Hash/fingerprint_id are occupied, importing with a new id.\n') new_hash = generate_hash() fdict['fingerprint_hash'] = new_hash del fdict['id'] new_fingerprint.__dict__.update(fdict) new_fingerprint.save() self.__addShares(meta, new_fingerprint) self.__import(zip, args[0], new_fingerprint, replacing=True) else: # impossible self.stdout.write('-- ERROR: Impossible to import fingerprint, the questionnaire doesnt exist, or doesnt match the slug.') else: self.stdout.write('-- USAGE: \n '+ 'python manage.py fingerprint_import <path_file>'+ '\n\n')
def show_fingerprint_page_read_only( request, q_id, qs_id, SouMesmoReadOnly=False, aqid=None, errors={}, template_name="advanced_search.html" ): """ Return the QuestionSet template Also add the javascript dependency code. """ # Getting first timestamp if template_name == "database_add.html": hide_add = True else: hide_add = False serialized_query = None if template_name == "advanced_search.html" and aqid != None: this_query = AdvancedQuery.objects.get(id=aqid) serialized_query = this_query.serialized_query try: qs_list = QuestionSet.objects.filter(questionnaire=q_id).order_by("sortid") if int(qs_id) == 99: qs_id = len(qs_list) - 1 question_set = qs_list[int(qs_id)] questions = question_set.questions() questions_list = {} for qset_aux in qs_list: questions_list[qset_aux.id] = qset_aux.questions() fingerprint_id = generate_hash() #### Find out about the number of answers serverside qreturned = [] for x in question_set.questionnaire.questionsets(): ttct = x.total_count() ans = 0 percentage = 0 qreturned.append([x, ans, ttct, percentage]) #### End of finding out about the number of answers serverside r = r2r( template_name, request, questionset=question_set, globalprogress=0, questionsets=qreturned, runinfo=None, progress=None, async_progress=None, async_url=None, qs_list=qs_list, fingerprint_id=fingerprint_id, breadcrumb=True, hide_add=hide_add, q_id=q_id, aqid=aqid, serialized_query=serialized_query, ) r["Cache-Control"] = "no-cache" r["Expires"] = "Thu, 24 Jan 1980 00:00:00 GMT" except: raise return r
def show_fingerprint_page_read_only(request, q_id, qs_id, SouMesmoReadOnly=False, aqid=None, errors={}, template_name='advanced_search.html'): """ Return the QuestionSet template Also add the javascript dependency code. """ # Getting first timestamp if template_name == "database_add.html": hide_add = True else: hide_add = False serialized_query = None if template_name == 'advanced_search.html' and aqid != None: this_query = AdvancedQuery.objects.get(id=aqid) serialized_query = this_query.serialized_query try: qs_list = QuestionSet.objects.filter( questionnaire=q_id).order_by('sortid') if (int(qs_id) == 99): qs_id = len(qs_list) - 1 question_set = qs_list[int(qs_id)] questions = question_set.questions() questions_list = {} for qset_aux in qs_list: questions_list[qset_aux.id] = qset_aux.questions() fingerprint_id = generate_hash() #### Find out about the number of answers serverside qreturned = [] for x in question_set.questionnaire.questionsets(): ttct = x.total_count() ans = 0 percentage = 0 qreturned.append([x, ans, ttct, percentage]) #### End of finding out about the number of answers serverside r = r2r(template_name, request, questionset=question_set, globalprogress=0, questionsets=qreturned, runinfo=None, progress=None, async_progress=None, async_url=None, qs_list=qs_list, fingerprint_id=fingerprint_id, breadcrumb=True, hide_add=hide_add, q_id=q_id, aqid=aqid, serialized_query=serialized_query) r['Cache-Control'] = 'no-cache' r['Expires'] = "Thu, 24 Jan 1980 00:00:00 GMT" except: raise return r