def app(request): """ Returns responsive app view for the Call Number App """ call_number=request.REQUEST.get('call_number',None) if call_number is not None: current = redis_helpers.get_record(call_number=call_number) else: current = setup_seed_rec() call_number = current.get('call_number') next_recs = redis_helpers.get_next(call_number, call_number_type=current['type_of']) print(next_recs) previous_recs = redis_helpers.get_previous(call_number, call_number_type=current['type_of']) return direct_to_template(request, 'call_number/app.html', {'app':APP, 'aristotle_url':settings.DISCOVERY_RECORD_URL, 'current':current, 'feedback_context':request.get_full_path(), 'feedback_form':FeedbackForm({'subject':'Call Number App'}), 'institution':settings.INSTITUTION, 'next':next_recs, 'previous':previous_recs, 'redis':redis_helpers.redis_server.info(), 'typeahead_data':None})
def job_display(request,job_pk): """ Displays a Job form for MARC batch operation :param request: HTTP Request :param job_pk: Job's Django primary key """ job_help = None template_filename = 'marc-batch-app.html' job = Job.objects.get(pk=job_pk) if job.help_rst is not None: job_help = {"title":job.name, "contents":help_loader.get(job.help_rst)} for row in job_types: if row[0] == job.job_type: template_filename = '%s.html' % row[1] ils_jobs = Job.objects.filter(job_type=3).order_by('name') marc_form = MARCRecordUploadForm() return direct_to_template(request, template_filename, {'app':APP, 'current_job':job, 'help':job_help, 'ils_jobs':ils_jobs, 'institution':INSTITUTION, 'marc_upload_form':marc_form})
def about_pages(request, page_name): try: return direct_to_template( request, template_name="pages/%s.html" % page_name) except TemplateDoesNotExist: raise Http404()
def closed(request): """ closed is the "we are closed" view for the Hours app :param request: web request """ return direct_to_template(request, 'hours/closed.html', {'app':APP,})
def solr(request): """ Displays ils view for the MARC Batch App """ APP['view'] = 'solr' return direct_to_template(request, 'marc_batch/solr.html', {'app':APP, 'institution':INSTITUTION})
def open(request): """ open is the "we are open" view for the Hours app :param request: web request """ return direct_to_template(request, 'hours/open.html', {'app':APP})
def website_header(request): """ Displays a footer replaced by a harvested footer from a website. This function is for one example of website interoperbility of the an App :param request: HTTP Request """ return direct_to_template(request, 'snippets/website-header.html', {})
def ils(request): """ Displays ils view for the MARC Batch App """ APP['view'] = 'ils' ils_jobs = Job.objects.filter(job_type=3) return direct_to_template(request, 'marc_batch/ils.html', {'app':APP, 'ils_jobs':ils_jobs, 'institution':INSTITUTION})
def manage(request): """ Displays management view for the app :param request: HTTP Request """ return direct_to_template(request, 'bibframe/app.html', {'admin':True, 'app':APP, 'institution':INSTITUTION, 'marc21_form':MARC12toMARCRForm(), 'search_form':MARCRSearchForm(), 'user':None})
def instance(request, redis_key): """ Displays a generic view of a BIBFRAME Instance :param request: HTTP Request :param redis_key: Redis key of the Authority """ add_use(redis_key, INSTANCE_REDIS) return direct_to_template(request, 'bibframe/instance.html', {'app':APP, 'institution':INSTITUTION, 'user':None})
def annotation(request, redis_key): """ Displays a generic view of a BIBFRAME Annotation :param request: HTTP Request :param redis_key: Redis key of the Annotation """ add_use(redis_key, ANNOTATION_REDIS) return direct_to_template(request, 'bibframe/annotation.html', {'app':APP, 'institution':INSTITUTION, 'user':None})
def job_finished(request,job_log_pk): """ Displays finished job :param request: HTTP Request :param job_log_pk: Job Log's primary key """ job_log = ILSJobLog.objects.get(pk=job_log_pk) return direct_to_template(request, 'marc_batch/finished.html', {'app':APP, 'ils_jobs':Job.objects.filter(job_type=3).order_by('name'), 'institution':INSTITUTION, 'log_entry':job_log})
def starting(request): """ Getting Started view for the Aristotle Library Apps project :param request: Web request from client :rtype: Generated HTML template """ return direct_to_template(request, 'getting-started.html', {'app':None, 'steps':[rst_loader.get('installing')], 'institution':json_loader.get('institution'), 'navbar_menus':json_loader.get('navbar-menus'), 'user':None})
def app(request): """ Displays default view for the app :param request: HTTP Request """ return direct_to_template(request, 'bibframe/app.html', {'app':APP, 'feedback_form':FeedbackForm({'subject':'BIBFRAME App'}), 'feedback_context':request.get_full_path(), 'institution':INSTITUTION, 'search_form':MARCRSearchForm(), 'user':None})
def subject(request,subject_name): """ Returns a subject view of related databases :param subject_name: Subject name """ return direct_to_template(request, 'dbfinder/filter.html', {'app':APP, 'alpha_dbs':get_dbs_alpha(), 'databases':get_databases(subject=subject_name), 'institution':INSTITUTION, 'filter':subject_name, 'subject_dbs':get_dbs_subjects(), 'user':None})
def default(request): """ Returns the default view for the Call Number Application """ ## return HttpResponse("Call Number Application index") seed_key = '{0}:identifiers'.format(SEED_RECORD_ID) current = redis_server.hgetall(seed_key) return direct_to_template(request, 'call_number/default.html', {'aristotle_url': settings.DISCOVERY_RECORD_URL, 'current': current, 'next': redis_helpers.get_next(current['lccn']), 'previous': redis_helpers.get_previous( current['lccn']), 'redis': redis_helpers.redis_server.info()})
def creative_work(request, redis_key): """ Displays a generic view of a BIBFRAME Creative Work :param request: HTTP Request :param redis_key: Redis key of the Creative Work """ # Tracks usage of the creative work by the hour add_use(redis_key, CREATIVE_WORK_REDIS) return direct_to_template(request, 'bibframe/creative_work.html', {'app':APP, 'institution':INSTITUTION, 'user':None})
def background(request): """ Background view for the Aristotle Library Apps project :param request: Web request from client :rtype: Generated HTML template """ return direct_to_template(request, 'background.html', {'app':None, 'history':rst_loader.get('project-history'), 'institution':json_loader.get('institution'), 'navbar_menus':json_loader.get('navbar-menus'), 'related_resources':rst_loader.get('related-resources'), 'user':None})
def app(request): """ Returns responsive app view for DBFinder App """ if request.user.is_authenticated(): user = request.user else: user = None return direct_to_template(request, 'dbfinder/app.html', {'app':APP, 'alpha_dbs':get_dbs_alpha(), 'institution':INSTITUTION, 'subject_dbs':get_dbs_subjects(), 'user':user})
def job_history(request,job_pk): """ Displays the history for a MARC batch job :param request: HTTP request :param job_pk: Django primary key for job """ job = Job.objects.get(pk=job_pk) job_logs = JobLog.objects.filter(job=job).order_by("created_on") return direct_to_template(request, 'marc_batch/history.html', {'app':APP, 'current_job':job, 'institution':INSTITUTION, 'logs':job_logs})
def manage(request,message): """ manage is the admin view for the Hours app :param request: web request """ message=None if request.GET.has_key("message"): message=request.GET["message"] return direct_to_template(request, 'hours/app.html', {'app':APP, 'feedback_context':'{0} default view'.format(request.get_full_path()), 'feedback_form':FeedbackForm({'subject':'Hours App Feedback'}), 'library_status':{'status':True}, 'message':message, 'user':request.user})
def alpha(request,letter): """ Returns a list of databases organized by letter """ if request.user.is_authenticated(): user = request.user else: user = None return direct_to_template(request, 'dbfinder/filter.html', {'app':APP, 'alpha_dbs':get_dbs_alpha(), 'databases':get_databases(letter=letter), 'filter':letter, 'subject_dbs':get_dbs_subjects(), 'institution':INSTITUTION, 'user':user})
def default(request): """ Default view for the portfolio app displays both Access and Productivity Apps depending on authentication and access rights :param request: Web request from client :rtype: Generated HTML template """ app_listing = get_apps(request.user.is_authenticated()) return direct_to_template(request, 'portfolio/app.html', {'app':APP, 'feedback_form':FeedbackForm({'subject':'Library App Portfolio'}), 'feedback_context':request.get_full_path(), 'institution':INSTITUTION, 'portfolio':app_listing, 'user':None})
def default(request): """ Default view for Aristotle Library Apps project :param request: Web request from client :rtype: Generated HTML template """ app_listing = [] return direct_to_template(request, 'index.html', {'app':None, 'institution':json_loader.get('institution'), 'navbar_menus':json_loader.get('navbar-menus'), 'portfolio':app_listing, 'vision':rst_loader.get('vision-for-aristotle-library-apps'), 'user':None})
def ils_job_manager(request,job): """ Helper function takes a Form's QueryDict and processes MARC file with specific rules :param request: HTTP reaquest :param job: Job object """ ils_job_form = MARCRecordUploadForm(request.POST,request.FILES) ils_jobs = Job.objects.filter(job_type=3).order_by('name') if ils_job_form.is_valid(): job_pk = request.POST['job_id'] original_marc = request.FILES['raw_marc_record'] job_query = Job.objects.get(pk=job_pk) params = {} ils_job_class = getattr(jobs.ils, '{0}'.format(job_query.python_module)) print("Class {} ".format(ils_job_class)) ils_job = ils_job_class(original_marc) ils_job.load() ils_log_entry = ILSJobLog(job=job_query, description=ils_job_form.cleaned_data['notes'], original_marc=original_marc, record_type=ils_job_form.cleaned_data['record_type']) ils_log_entry.save() ils_marc_output = ils_job.output() ils_log_entry.modified_marc.save('job-{0}-{1}-modified.mrc'.format(job_query.name, ils_log_entry.created_on.strftime("%Y-%m-%d")), ContentFile(ils_marc_output)) ils_log_entry.save() data = {'job':int(job_query.pk)} ils_log_form = ILSJobLogForm(data) request.session['log_pk'] = ils_log_entry.pk log_notes_form = JobLogNotesForm() return direct_to_template(request, 'marc_batch/log.html', {'app':APP, 'current_job':job_query, 'current_log':ils_log_entry, 'ils_jobs':ils_jobs, 'log_form':ils_log_form, 'log_notes_form':log_notes_form}) else: print("Invalid form errors={0}".format(ils_job_form.errors))
def widget(request): """ Returns rendered html snippet of call number browser widget """ standalone = False call_number = 'PS21 .D5185 1978' if 'standalone' in request.REQUEST: standalone = request.REQUEST.get('standalone') if 'call_number' in request.REQUEST: call_number = request.REQUEST.get('call_number') current = redis_helpers.get_record(call_number=call_number) return direct_to_template(request, 'call_number/snippets/widget.html', {'aristotle_url': settings.DISCOVERY_RECORD_URL, 'current': current, 'next': redis_helpers.get_next(call_number), 'previous': redis_helpers.get_previous( call_number), 'standalone': standalone})
def app_login(request): """ Attempts to authenticate a user to Aristotle Library Apps :param request: HTTP Request """ if request.method == 'GET': return HttpResponse("IN GET App Login") username = request.POST['username'] password = request.POST['password'] next_page = request.REQUEST.get('next') errors = [] try: user = authenticate(last_name=username, iii_id=password) except KeyError: user = None if user is not None: if user.is_active: login(request, user) if len(next_page) > 0: return redirect(next_page) else: return redirect('/apps') else: error_msg = "User not active" logger.error(error_msg) errors.append(error_msg) else: error_msg = "User {0} not found or unable to authenticate".format(username) logger.error(error_msg) errors.append(error_msg) auth_form = AuthenticationForm(request.POST) auth_form.full_clean() auth_form._errors[NON_FIELD_ERRORS] = auth_form.error_class(errors) return direct_to_template(request, 'registration/login.html', {'app':None, 'institution':json_loader.get('institution'), 'form': auth_form, 'navbar_menus':json_loader.get('navbar-menus'), 'user':user})
def default(request): """ default is the standard view for the Hours app :param request: web request """ today = datetime.datetime.now() if is_library_open(today): template = 'hours/open.html' next_time = get_closing_time(today) else: template = 'hours/closed.html' next_time = None return direct_to_template(request, template, {'app':APP, 'feedback_context':'{0}'.format(request.get_full_path()), 'feedback_form':FeedbackForm({'subject':'Hours App Feedback'}), 'institution':INSTITUTION, 'next_time':next_time})
def default(request): """ Displays default view for the MARC Batch App """ APP['view'] = 'default' ils_jobs,redis_jobs,solr_jobs = [],[],[] all_jobs = Job.objects.all().order_by('name') for job in all_jobs: if job.job_type == 1: redis_jobs.append(job) elif job.job_type == 2: solr_jobs.append(job) elif job.job_type == 3: ils_jobs.append(job) return direct_to_template(request, 'marc-batch-app.html', {'app':APP, 'current_job': None, 'feedback_form':FeedbackForm({'subject':'MARC Batch App'}), 'feedback_context':request.get_full_path(), 'ils_jobs':ils_jobs, 'institution':INSTITUTION, 'redis_jobs':redis_jobs, 'solr_jobs':solr_jobs})
def about_pages(request, page_name): try: return direct_to_template(request, template_name="pages/%s.html" % page_name) except TemplateDoesNotExist: raise Http404()
def page_404(request): return direct_to_template(request, template_name="pages/404.html")