def indexing_details(request, step=None, template='mdtui/indexing.html'): """Indexing: Step 2 : Index Details""" # Context init context = {} document_keys = None warnings = [] errors = [] cleanup_search_session(request) docrule_id = None try: docrule_id = request.session['indexing_docrule_id'] except KeyError: warnings.append(MDTUI_ERROR_STRINGS['NO_DOCRULE']) try: document_keys = request.session["document_keys_dict"] except KeyError: pass log.debug('indexing_details view called with docrule_id: %s, document_keys: %s, warnings: %s' % (docrule_id, document_keys, warnings)) if request.POST: secondary_indexes = processDocumentIndexForm(request) if secondary_indexes: request.session["document_keys_dict"] = secondary_indexes # Checking for forbidden keys and changing view behaviour if found forbidden_keys = check_for_forbidden_new_keys_created(secondary_indexes, docrule_id, request.user) if forbidden_keys: for forbidden_key in forbidden_keys: if forbidden_key[1] == 'adminlock': errors.append(MDTUI_ERROR_STRINGS['ADMINLOCKED_KEY_ATTEMPT'] + forbidden_key[0]) elif forbidden_key[1] == 'locked': errors.append(MDTUI_ERROR_STRINGS['LOCKED_KEY_ATTEMPT'] + forbidden_key[0]) # Reinitializing form form = initIndexesForm(request) else: # Success, allocate barcode and move on if "barcode" in request.session and request.session["barcode"]: pass else: dtr = DocumentTypeRule.objects.get(pk=docrule_id) request.session["barcode"] = dtr.allocate_barcode() return HttpResponseRedirect(reverse('mdtui-index-source')) else: # Return validation with errors... form = initIndexesForm(request) else: form = initIndexesForm(request) autocomplete_list = extract_secondary_keys_from_form(form) context.update( { 'step': step, 'form': form, 'document_keys': document_keys, 'autocomplete_fields': autocomplete_list, 'warnings': warnings, 'error_warnings': errors, }) return render_to_response(template, context, context_instance=RequestContext(request))
def indexing_select_type(request, step=None, template='mdtui/indexing.html'): """Indexing: Step 1 : Select Document Type @param request: is a Django request object @param step: is a current step name (for template rendering) @param template: is a name of template for this view""" # Context init context = {'step': step} docrule = None active_docrule = None warnings = [] docrules_list = make_document_type_select(user=request.user) cleanup_search_session(request) cleanup_mdts(request) log.debug('indexing_select_type view called with docrule: %s' % docrule) if request.POST: for item, value in request.POST.iteritems(): if not item == u'csrfmiddlewaretoken': docrule = int(item) request.session['indexing_docrule_id'] = docrule mdts = get_mdts_for_docrule(docrule) if mdts: request.session['mdts'] = mdts return HttpResponseRedirect(reverse('mdtui-index-details')) else: warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS']) else: # initializing form with previously selected docrule. try: docrule = request.session['indexing_docrule_id'] except KeyError: pass if docrule: active_docrule = docrule context.update({ 'active_docrule': active_docrule, 'docrules_list': docrules_list, 'warnings': warnings, }) return render_to_response(template, context, context_instance=RequestContext(request))
def get(self, request): context = self.context docrules_list = make_document_type_select(user=request.user) cleanup_search_session(request) cleanup_mdts(request) # initializing form with previously selected docrule. try: self.docrule = request.session['indexing_docrule_id'] except KeyError: pass if self.docrule: self.active_docrule = self.docrule log.debug('MuiIndexingView GET with docrule: %s' % self.docrule) context.update({ 'active_docrule': self.active_docrule, 'docrules_list': docrules_list, 'warnings': self.warnings, }) return render(request, self.template_name, context)
def search_type(request, step, template='mdtui/search.html'): """Search Step 1: Select Search MDT @param request: is a Django request object @param step: is a current step name (for template rendering) @param template: is a name of template for this view""" warnings = [] cleanup_indexing_session(request) # Initialising MDT or Docrule form according to data provided valid_call = True required_mdt = True required_docrule = True if request.POST: # Cleaning search session selections cleanup_search_session(request) cleanup_mdts(request) # Checking if docrule or mdt selected try: if request.POST['docrule']: required_mdt = False except KeyError: pass try: if request.POST['mdt']: required_docrule = False except KeyError: pass # Do not process in case docrule and MDT provided try: if request.POST['docrule'] and request.POST['mdt']: valid_call = False warnings.append(MDTUI_ERROR_STRINGS['NO_MDT_NO_DOCRULE']) except KeyError: pass # Rendering forms accordingly mdts_filtered_form = make_mdt_select_form(request.user, required_mdt) mdts_form = mdts_filtered_form(request.POST or None) docrules_filtered_form = make_document_type_select_form(request.user, required_docrule) docrules_form = docrules_filtered_form(request.POST or None) # POST Validation for either docrule OR mdt selected if request.POST and valid_call: if mdts_form.is_valid() and not required_docrule: mdts = None mdt_form_id = None try: mdt_form_id = mdts_form.data["mdt"] except KeyError: pass # CouchDB connection Felt down warn user if mdt_form_id: try: mdt_names = get_mdt_from_search_mdt_select_form(mdt_form_id, mdts_filtered_form) request.session['search_mdt_id'] = mdt_form_id mdts = get_mdts_by_names(mdt_names) docrules_list = mdts['1']['docrule_id'] if not request.user.is_superuser: request.session['search_docrule_ids'] = filter_permitted_docrules(docrules_list, request.user) else: request.session['search_docrule_ids'] = docrules_list except RequestError: warnings.append(MDTUI_ERROR_STRINGS['NO_DB']) if mdts: request.session['mdts'] = mdts if valid_call: return HttpResponseRedirect(reverse('mdtui-search-options')) else: if not MDTUI_ERROR_STRINGS['NO_MDTS'] in warnings: warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS']) if docrules_form.is_valid() and not required_mdt: # If Docrule selected than MDT is not required and MDT's form is valid in fact docrule_form_id = None try: docrule_form_id = docrules_form.data["docrule"] except KeyError: pass if docrule_form_id: request.session['searching_docrule_id'] = docrule_form_id mdts = get_mdts_for_docrule(docrule_form_id) if mdts: request.session['mdts'] = mdts if valid_call: return HttpResponseRedirect(reverse('mdtui-search-options')) else: if not MDTUI_ERROR_STRINGS['NO_MDTS'] in warnings: warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS']) else: # Populating forms with preexisting data if provided mdt_id = None docrule_id = None # Trying to set docrule if previously selected try: docrule_id = request.session['searching_docrule_id'] except KeyError: pass if docrule_id: docrules_form = docrules_filtered_form({'docrule': docrule_id}) # Trying to set mdt if previously selected try: mdt_id = request.session['search_mdt_id'] except KeyError: pass if mdt_id: mdts_form = mdts_filtered_form({'mdt': mdt_id}) context = { 'warnings': warnings, 'step': step, 'mdts_form': mdts_form, 'docrules_form': docrules_form, } return render_to_response(template, context, context_instance=RequestContext(request))
def search_type(request, step, template='mdtui/search.html'): """Search Step 1: Select Search MDT @param request: is a Django request object @param step: is a current step name (for template rendering) @param template: is a name of template for this view""" warnings = [] cleanup_indexing_session(request) # Initialising MDT or Docrule form according to data provided valid_call = True required_mdt = True required_docrule = True if request.POST: # Cleaning search session selections cleanup_search_session(request) cleanup_mdts(request) # Checking if docrule or mdt selected try: if request.POST['docrule']: required_mdt = False except KeyError: pass try: if request.POST['mdt']: required_docrule = False except KeyError: pass # Do not process in case docrule and MDT provided try: if request.POST['docrule'] and request.POST['mdt']: valid_call = False warnings.append(MDTUI_ERROR_STRINGS['NO_MDT_NO_DOCRULE']) except KeyError: pass # Rendering forms accordingly mdts_filtered_form = make_mdt_select_form(request.user, required_mdt) mdts_form = mdts_filtered_form(request.POST or None) docrules_filtered_form = make_document_type_select_form( request.user, required_docrule) docrules_form = docrules_filtered_form(request.POST or None) # POST Validation for either docrule OR mdt selected if request.POST and valid_call: if mdts_form.is_valid() and not required_docrule: mdts = None mdt_form_id = None try: mdt_form_id = mdts_form.data["mdt"] except KeyError: pass # CouchDB connection Felt down warn user if mdt_form_id: try: mdt_names = get_mdt_from_search_mdt_select_form( mdt_form_id, mdts_filtered_form) request.session['search_mdt_id'] = mdt_form_id mdts = get_mdts_by_names(mdt_names) docrules_list = mdts['1']['docrule_id'] if not request.user.is_superuser: request.session[ 'search_docrule_ids'] = filter_permitted_docrules( docrules_list, request.user) else: request.session['search_docrule_ids'] = docrules_list except RequestError: warnings.append(MDTUI_ERROR_STRINGS['NO_DB']) if mdts: request.session['mdts'] = mdts if valid_call: return HttpResponseRedirect( reverse('mdtui-search-options')) else: if not MDTUI_ERROR_STRINGS['NO_MDTS'] in warnings: warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS']) if docrules_form.is_valid() and not required_mdt: # If Docrule selected than MDT is not required and MDT's form is valid in fact docrule_form_id = None try: docrule_form_id = docrules_form.data["docrule"] except KeyError: pass if docrule_form_id: request.session['searching_docrule_id'] = docrule_form_id mdts = get_mdts_for_docrule(docrule_form_id) if mdts: request.session['mdts'] = mdts if valid_call: return HttpResponseRedirect( reverse('mdtui-search-options')) else: if not MDTUI_ERROR_STRINGS['NO_MDTS'] in warnings: warnings.append(MDTUI_ERROR_STRINGS['NO_MDTS']) else: # Populating forms with preexisting data if provided mdt_id = None docrule_id = None # Trying to set docrule if previously selected try: docrule_id = request.session['searching_docrule_id'] except KeyError: pass if docrule_id: docrules_form = docrules_filtered_form({'docrule': docrule_id}) # Trying to set mdt if previously selected try: mdt_id = request.session['search_mdt_id'] except KeyError: pass if mdt_id: mdts_form = mdts_filtered_form({'mdt': mdt_id}) context = { 'warnings': warnings, 'step': step, 'mdts_form': mdts_form, 'docrules_form': docrules_form, } return render_to_response(template, context, context_instance=RequestContext(request))
def indexing_details(request, step=None, template='mdtui/indexing.html'): """Indexing: Step 2 : Index Details @param request: is a Django request object @param step: is a current step name (for template rendering) @param template: is a name of template for this view""" # Context init context = {} document_keys = None warnings = [] errors = [] cleanup_search_session(request) docrule_id = None try: docrule_id = request.session['indexing_docrule_id'] except KeyError: warnings.append(MDTUI_ERROR_STRINGS['NO_DOCRULE']) try: document_keys = request.session["document_keys_dict"] except KeyError: pass log.debug( 'indexing_details view called with docrule_id: %s, document_keys: %s, warnings: %s' % (docrule_id, document_keys, warnings)) if request.POST: secondary_indexes = processDocumentIndexForm(request) if secondary_indexes: request.session["document_keys_dict"] = secondary_indexes # Checking for forbidden keys and changing view behaviour if found forbidden_keys = check_for_forbidden_new_keys_created( secondary_indexes, docrule_id, request.user) if forbidden_keys: for forbidden_key in forbidden_keys: if forbidden_key[1] == 'adminlock': errors.append( MDTUI_ERROR_STRINGS['ADMINLOCKED_KEY_ATTEMPT'] + forbidden_key[0]) elif forbidden_key[1] == 'locked': errors.append( MDTUI_ERROR_STRINGS['LOCKED_KEY_ATTEMPT'] + forbidden_key[0]) # Reinitializing form form = initIndexesForm(request) else: # Success, allocate barcode and move on if "barcode" in request.session and request.session["barcode"]: pass else: if docrule_id: dtr = DocumentTypeRule.objects.get(pk=docrule_id) request.session["barcode"] = dtr.allocate_barcode() return HttpResponseRedirect(reverse('mdtui-index-source')) else: # Return validation with errors... form = initIndexesForm(request) else: form = initIndexesForm(request) autocomplete_list = extract_secondary_keys_from_form(form) context.update({ 'step': step, 'form': form, 'document_keys': document_keys, 'autocomplete_fields': autocomplete_list, 'warnings': warnings, 'error_warnings': errors, }) return render_to_response(template, context, context_instance=RequestContext(request))