def handle(self, *args, **options): try: filename = args[0] if filename == '-': filename = None except IndexError: filename = None verbosity = int(options['verbosity']) replace_existing = options['replace_existing'] if verbosity >= 1: if filename: self.stdout.write('Using %r' % filename) else: self.stdout.write('Using STDIN') if filename: f = open(filename, 'rb') else: f = sys.stdin raw_str = f.read() if filename: f.close() d = load_json(raw_str) results = dict2db(d, verbosity, replace_existing) for cardset_name, b_count, w_count in results: if verbosity >= 1: print('{} total# {} question# {} answer# {}'.format(cardset_name, b_count + w_count, b_count, w_count))
def handle(self, *args, **options): try: filename = args[0] if filename == "-": filename = None except IndexError: filename = None verbosity = int(options["verbosity"]) replace_existing = options["replace_existing"] if verbosity >= 1: if filename: self.stdout.write("Using %r" % filename) else: self.stdout.write("Using STDIN") if filename: f = open(filename, "rb") else: f = sys.stdin raw_str = f.read() if filename: f.close() d = load_json(raw_str) results = dict2db(d, verbosity, replace_existing) for cardset_name, b_count, w_count in results: if verbosity >= 1: print "%s total# %d question# %d answer# %d" % (cardset_name, b_count + w_count, b_count, w_count)
def import_cards(request): raw_json_str = '' raw_json_str = request.GET.get('json') if raw_json_str is None: return HttpResponse('Looks like we need a form') try: d = load_json(raw_json_str) except ValueError as info: return HttpResponse(repr(info)) verbosity = 0 replace_existing = False results = dict2db(d, verbosity, replace_existing) return HttpResponse(repr(results))
return super(SubmitCardView, self).dispatch(request, *args, **kwargs) def get_form_kwargs(self): kwargs = super(SubmitCardView, self).get_form_kwargs() kwargs['user'] = self.user return kwargs def get_success_url(self): return reverse("submit-card") def get_context_data(self, **kwargs): context = super(SubmitCardView, self).get_context_data(**kwargs) context['action'] = reverse("submit-card") return context @staff_member_required def import_cards(request): raw_json_str = '' raw_json_str = request.GET.get('json') if raw_json_str is None: return HttpResponse('Looks like we need a form') try: d = load_json(raw_json_str) except ValueError, info: return HttpResponse(repr(info)) verbosity = 0 replace_existing = False results = dict2db(d, verbosity, replace_existing) return HttpResponse(repr(results))