View Function Modules¶
hedwig.view.admin¶
- class hedwig.view.admin.AdminView¶
- home(current_user, facilities)¶
- message_list(current_user, db, args, form)¶
- message_view(current_user, db, message_id)¶
- message_alter_state(current_user, db, message_id, form)¶
- message_thread(current_user, db, facilities, thread_type, thread_id)¶
- _make_thread_links(current_user, db, facilities, thread_type, thread_id)¶
- processing_status(current_user, db, facilities, form)¶
- _add_proposal(db, facilities, proposals, reviewers, id_field, entries, proposal_facilities, facility_text_roles, facility_reviewer_roles)¶
- _add_moc_facility(entries, facilities, clash_tool_facilities)¶
- request_status(current_user, db, facilities, form)¶
- _add_req_prop(db, facilities, requests, proposals, proposal_facilities)¶
- user_unregistered(current_user, db, form)¶
- site_group_view(current_user, db, site_group_type)¶
- site_group_member_add(current_user, db, site_group_type, form)¶
- _message_site_group_invite(current_user, db, site_group_info, person_id, person_name)¶
- site_group_member_edit(current_user, db, site_group_type, form)¶
- site_group_member_reinvite(current_user, db, site_group_type, member_id, form)¶
hedwig.view.auth¶
- class hedwig.view.auth.Authorization(view, edit)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('view', 'edit')¶
- classmethod _make(iterable)¶
Make a new Authorization object from a sequence or iterable
- _replace(**kwds)¶
Return a new Authorization object replacing specified fields with new values
- edit¶
Alias for field number 1
- view¶
Alias for field number 0
- class hedwig.view.auth.AuthorizationWithRating(view, edit, view_rating)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('view', 'edit', 'view_rating')¶
- classmethod _make(iterable)¶
Make a new AuthorizationWithRating object from a sequence or iterable
- _replace(**kwds)¶
Return a new AuthorizationWithRating object replacing specified fields with new values
- edit¶
Alias for field number 1
- view¶
Alias for field number 0
- view_rating¶
Alias for field number 2
- hedwig.view.auth.for_call(current_user, db, call, auth_cache=None)¶
Determine the current user’s authorization regarding the given call.
Currently only “view” authorization is considered.
- hedwig.view.auth.for_call_review(current_user, db, call, auth_cache=None)¶
Determine the current user’s authorization regarding the general review of proposals for a given call.
(Authorization to view the proposals and the individual reviews is controlled by the more specific for_proposal and for_review methods below.)
When making multiple calls to this function, an auth_cache dictionary can be provided. This function can then use this to cache some information which it fetches from the database.
- hedwig.view.auth.for_call_review_proposal(current_user, db, proposal, auth_cache=None)¶
Determine general authorization for call reviews, based on a proposal record.
This constucts a dummy call record and then calls
for_call_review().
- hedwig.view.auth.for_person(current_user, db, person, auth_cache=None)¶
Determine the current user’s authorization regarding this profile.
person can be set to None to skip person-specific authorization. (Access will then be granted based only on administrative access.)
- hedwig.view.auth.for_person_list(current_user, db, auth_cache=None)¶
Determine the current user’s authorization regarding the full person list (including those without public profiles).
This is limited to site administrators and review coordinators.
- hedwig.view.auth.for_person_member(current_user, db, member, auth_cache=None)¶
Determine authorization for a person profile, based on a member record.
This constucts a dummy person record and then calls
for_person().
- hedwig.view.auth.for_person_reviewer(current_user, db, reviewer, auth_cache=None)¶
Determine authorization for a person profile, based on a reviewer record.
This constucts a dummy person record and then calls
for_person().
- hedwig.view.auth.for_institution(current_user, db, institution, auth_cache=None)¶
Determine the current user’s authorization regarding this institution.
- hedwig.view.auth.for_private_moc(current_user, db, facility_id, auth_cache=None)¶
Determine whether the current user can view/search private MOCs.
Currently only “view” authorization is considered.
- hedwig.view.auth.for_proposal(role_class, current_user, db, proposal, auth_cache=None, allow_unaccepted_review=None)¶
Determine the current user’s authorization regarding this proposal.
- hedwig.view.auth.for_proposal_prev_proposal(current_user, db, prev_proposal, members=None, auth_cache=None)¶
Estimate authorization for a proposal, based on a previous proposal record.
This constructs a dummy proposal record and then calls
for_proposal().A collection of members can be provided if any approximate information is available.
- hedwig.view.auth._dummy_proposal_prev_proposal(prev_proposal, members=None)¶
- hedwig.view.auth.for_proposal_decision(current_user, db, proposal, call=None, auth_cache=None)¶
Determine the current user’s authorization regarding the review committee decision.
Currently only “edit” authorization is considered.
The call object can optionally be provided. Otherwise the call is looked up based on the proposal’s call identifier.
- hedwig.view.auth.for_proposal_feedback(role_class, current_user, db, proposal, auth_cache=None)¶
Determine the current user’s authorization regarding general feedback for a proposal.
This may include, but is not limited to, the feedback review. For more specific access to that review, use the for_review function. This function currently only allows view access.
- hedwig.view.auth.for_review(role_class, current_user, db, reviewer, proposal, auth_cache=None, skip_membership_test=False, allow_unaccepted=None)¶
Determine the current user’s authorization regarding this review.
“reviewer” can be set to “None” to skip reviewer-specific authorization. (Access will then be granted based only on proposal membership, administrative access and committee membership.) Otherwise this can be either a Reviewer or ReviewerInfo object.
When making multiple calls to this function, an auth_cache dictionary can be provided. This function can then use this to cache some information which it fetches from the database.
If the proposal has a non-None reviewers attribute, then this may be used in determining authorization in cases where it may depend on other roles. (The only example so far is allowing reviewers in “feedback roles” to edit the “feedback” review.) This means that if some reviewers are attached, they all must be.
The skip_membership_test argument can be set to skip the check that the person is not a member of the proposal. This should only be used when considering access for non-sensitive information which it is acceptable for the proposal members to see, such as calculation results. The membership check is not applied if “reviewer” is given and the role is FEEDBACK because feedback reports should not contain sensitive information and the review coordinator may need to process feedback for thier own proposal.
The allow_unaccepted argument controls handling of reviews roles with acceptance (role_class.is_accepted_review returns True). If this is None (the default) then an attempt to authenticate for an unaccepted review results in a redirect to the acceptance page. This mode can only be used from routes within the facility blueprint. If it is True then acceptance is ignored. If it is False then authentication is denied for unaccepted reviews.
- Return AuthorizationWithRating:
including field indicating whether the ratings can be viewed.
- hedwig.view.auth.for_review_prev_proposal(current_user, db, prev_proposal, members=None, auth_cache=None)¶
Estimate authorization for reviews of a proposal, based on a previous proposal record.
This constructs a dummy proposal record and then calls
for_review(), giving the reviewer as None for a non-reviewer-specific authorization.A collection of members can be provided if any approximate information is available.
- hedwig.view.auth.can_be_admin(current_user, db, auth_cache=None)¶
Check whether the user is permitted to take administrative privileges.
- hedwig.view.auth.can_add_review_roles(type_class, role_class, current_user, db, proposal, include_indirect=True, auth_cache=None)¶
Determine for which reviewer roles a person can add a review to a proposal.
If no reviews can be added then an empty list is returned.
- hedwig.view.auth.find_addable_reviews(current_user, db, facilities, auth_cache=None)¶
Find proposals for which the user can add reviews.
This function only considers reviews which the user can “directly” add — i.e. for suitable proposals it calls
can_add_review_roles()with include_indirect=False.- Parameters:
db – database control object/
facilities – dictionary of FacilityInfo objects.
auth_cache – authentication cache dictionary. Providing this dictionary is strongly recommended.
- Return ProposalCollection:
proposals for which the user can add reviews, with the reviewers attribute containing a ReviewerCollection of dummy Review namedtuples for those reviews.
- hedwig.view.auth._redirect_review_accept(reviewer)¶
Generate (but do not raise) a redirect exception to the acceptance page for the given review.
This generates a URL in the current blueprint, so it can only be used from the blueprint of the facility corresponding to the given review.
- hedwig.view.auth._get_call(db, call_id)¶
- hedwig.view.auth._get_group_membership(db, person_id)¶
- hedwig.view.auth._get_institutions(db, has_registered_person)¶
- hedwig.view.auth._get_proposal_co_membership(db, person_id)¶
Get proposal membership for proposals in editable states.
- hedwig.view.auth._get_site_group_membership(db, person_id)¶
- hedwig.view.auth._get_queue_reviewers(db, queue_id)¶
Get reviewers in for the given queue for proposals in review states.
hedwig.view.calculator¶
- class hedwig.view.calculator.CalculationInfo(id, parent_id, title, overwrite)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('id', 'parent_id', 'title', 'overwrite')¶
- classmethod _make(iterable)¶
Make a new CalculationInfo object from a sequence or iterable
- _replace(**kwds)¶
Return a new CalculationInfo object replacing specified fields with new values
- id¶
Alias for field number 0
- overwrite¶
Alias for field number 3
- parent_id¶
Alias for field number 1
- title¶
Alias for field number 2
- class hedwig.view.calculator.BaseCalculator(facility, id_)¶
- classmethod get_code()¶
Get the calculator “code”.
This is a short string used to uniquely identify the calculator within facilities which use it. It will correspond to an entry in the “calculator” table and be used in URLs.
- get_default_facility_code()¶
Get the code of the facility for which this calculator is designed.
This is used by the
make_calculator_view()function when constructing the names of the templates to use for the calculator view. If this method returns a value other than None then it is used as an additional facility directory in which to search for the calculator’s HTML template.Calculators need only override this method if the calculator is intended to be used with multiple facilities.
- Returns:
a facility code if necessary, or None otherwise
- get_custom_routes()¶
Method used to find any custom routes required by this calculator.
Note that the route information will automatically be prefixed as follows:
template: <facility code>/calculator_<calculator code>_
rule: /calculator/<calculator code>/
endpoint: calc_<calculator code>_
- Returns:
a list of RouteInfo tuples
- view(current_user, db, mode, args, form, calculation=None, review_calculation=None, can=None, parent_proposal=None, parent_reviewer=None)¶
Web view handler for a generic calculator.
Accepts additional keyword arguments for use via the proposal and review calculation route view functions. The parent_proposal and parent_reviewer can be used to generate information about the proposal / review (proposal code and reviewer role) and so providing them may avoid additional database queries being required.
This view handler tracks two sets of identifiers:
for_proposal_id / for_reviewer_id
This is a proposal / review which we are definitely interacting with. I.e. it:
Is the parent of the calculation / review calculation given as a keyword argument.
Is the proposal / review to which a calculation was saved.
Is passed as a query parameter proposal_id / reviewer_id when the user follows a link from the proposal / review to add a calculation.
Is passed as posted form argument for_proposal_id / for_reviewer_id. (This is a hidden parameter allowing the calculator to remember the value selected in any of the above ways.)
Is used to set up the title and “back to” links on the page.
calculation_info.parent_id / review_calculation_info.parent_id
This is the value posted in the form calculation_id / review_calculation_id select input, giving the user’s choice from the save area of the form (or as a hidden parameter when there is no output thus no save area).
This value:
Is initialized when a calculation / review calculation is given as a keyword argument.
Is also initialized via query parameter when the user follows a link to add a calculation for a proposal / review.
Is otherwise initialized to the first review editable by the user for the proposal specified by for_proposal_id.
- format_input(inputs, values)¶
Format the calculator inputs for display in the input form.
This is because the input form needs to take string inputs so that we can give it back malformatted user input strings for correction.
- get_extra_context()¶
Method which subclasses can override to supply extra context information to the view template.
- get_form_input(inputs, form)¶
Extract the input values from the submitted form.
This example would be sufficient in the case of some input text boxes, but subclasses need to override to support other form elements such as checkboxes.
- get_mode_info(mode)¶
Get mode information named tuple for the given mode.
- is_valid_mode(mode)¶
Determine whether the given mode is valid.
Does this by seeing if it appears in the calculator’s “modes” attribute (normally a dictionary).
- condense_calculation(mode, version, calculation)¶
Method which can be called before an existing calculation result is to be displayed in a compact form.
Takes a “CalculationExtra” object, which has “inputs”, “input”, “outputs” and “output” attributes and modifies it in place.
- _encode_query(inputs, values)¶
- _decode_query(mode, query)¶
hedwig.view.help¶
Return a new dict which maps field names to their values.
Make a new NavLink object from a sequence or iterable
Return a new NavLink object replacing specified fields with new values
Alias for field number 4
Alias for field number 5
Alias for field number 2
Alias for field number 3
Alias for field number 0
Alias for field number 1
- class hedwig.view.help.TOCEntry(mtime, title)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('mtime', 'title')¶
- classmethod _make(iterable)¶
Make a new TOCEntry object from a sequence or iterable
- _replace(**kwds)¶
Return a new TOCEntry object replacing specified fields with new values
- mtime¶
Alias for field number 0
- title¶
Alias for field number 1
- class hedwig.view.help.TreeEntry(mtime, toc)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('mtime', 'toc')¶
- classmethod _make(iterable)¶
Make a new TreeEntry object from a sequence or iterable
- _replace(**kwds)¶
Return a new TreeEntry object replacing specified fields with new values
- mtime¶
Alias for field number 0
- toc¶
Alias for field number 1
- class hedwig.view.help.HelpView¶
- help_home(current_user, db)¶
- help_page(current_user, doc_root, page_name, toc_cache)¶
Prepare template context information for viewing a help page.
The toc_cache argument is a dictionary in which we can store information about other pages for use in generating tables of contents.
- help_graph(current_user, doc_root, graph_name)¶
Convert Graphviz image and return as a PNG image.
- hedwig.view.help._read_rst_file(doc_root, path_name)¶
Read a file and return the body, title and toc.
- hedwig.view.help._get_page_title(doc_root, page_name, title_cache, mtime=None)¶
Get the title of a page, using the cache if possible.
The mtime can be given to skip checking if the file exists and reading its mtime.
Find navigation links for the given page.
This is called recursively, starting with page_name=’index’.
hedwig.view.home¶
hedwig.view.people¶
- class hedwig.view.people.InstitutionLogExtra(prev, person_name, institution_name, new)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('prev', 'person_name', 'institution_name', 'new')¶
- classmethod _make(iterable)¶
Make a new InstitutionLogExtra object from a sequence or iterable
- _replace(**kwds)¶
Return a new InstitutionLogExtra object replacing specified fields with new values
- institution_name¶
Alias for field number 2
- new¶
Alias for field number 3
- person_name¶
Alias for field number 1
- prev¶
Alias for field number 0
- class hedwig.view.people.GroupsByFacility(name, code, groups)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('name', 'code', 'groups')¶
- classmethod _make(iterable)¶
Make a new GroupsByFacility object from a sequence or iterable
- _replace(**kwds)¶
Return a new GroupsByFacility object replacing specified fields with new values
- code¶
Alias for field number 1
- groups¶
Alias for field number 2
- name¶
Alias for field number 0
- class hedwig.view.people.PersonLogExtra(proposal_facility_code, proposal_code, institution_name, other_person_name)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('proposal_facility_code', 'proposal_code', 'institution_name', 'other_person_name')¶
- classmethod _make(iterable)¶
Make a new PersonLogExtra object from a sequence or iterable
- _replace(**kwds)¶
Return a new PersonLogExtra object replacing specified fields with new values
- institution_name¶
Alias for field number 2
- other_person_name¶
Alias for field number 3
- proposal_code¶
Alias for field number 1
- proposal_facility_code¶
Alias for field number 0
- class hedwig.view.people.ProposalsByFacility(name, code, type_class, proposals)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('name', 'code', 'type_class', 'proposals')¶
- classmethod _make(iterable)¶
Make a new ProposalsByFacility object from a sequence or iterable
- _replace(**kwds)¶
Return a new ProposalsByFacility object replacing specified fields with new values
- code¶
Alias for field number 1
- name¶
Alias for field number 0
- proposals¶
Alias for field number 3
- type_class¶
Alias for field number 2
- class hedwig.view.people.ReviewsByFacility(name, code, role_class, proposals)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('name', 'code', 'role_class', 'proposals')¶
- classmethod _make(iterable)¶
Make a new ReviewsByFacility object from a sequence or iterable
- _replace(**kwds)¶
Return a new ReviewsByFacility object replacing specified fields with new values
- code¶
Alias for field number 1
- name¶
Alias for field number 0
- proposals¶
Alias for field number 3
- role_class¶
Alias for field number 2
- class hedwig.view.people.PeopleView¶
- log_in(db, args, form, remote_addr, remote_agent, referrer)¶
- log_out(current_user, db)¶
- register_user(db, args, form, remote_addr, remote_agent)¶
- change_user_name(current_user, db, form, remote_addr)¶
- change_password(current_user, db, form, remote_addr)¶
- password_reset_token_get(db, args, form, remote_addr)¶
- password_reset_token_use(db, args, form, remote_addr)¶
- take_admin(current_user, db, args, referrer)¶
- drop_admin(current_user, referrer)¶
- user_log(current_user, db, user, person, name, args)¶
- user_enable_disable(current_user, db, user, person, name, disabled, form)¶
- user_session_list(current_user, db)¶
- user_session_log_out(current_user, db, auth_token_id, form)¶
- register_person(current_user, db, args, form, remote_addr)¶
- person_list(current_user, db, args)¶
- person_view(current_user, db, person, can, facilities)¶
- person_invite(current_user, db, person, args, form)¶
- person_edit(current_user, db, person, can, args, form)¶
- person_edit_institution(current_user, db, person, can, args, form)¶
- person_edit_email_own(current_user, db, args, form)¶
- person_edit_email(current_user, db, person, can, form)¶
- _person_edit_email(current_user, db, person, args, form)¶
- person_email_verify_get_primary(current_user, db, args, form, remote_addr)¶
- person_email_verify_get(current_user, db, person, can, email_id, form, remote_addr)¶
- _person_email_verify_get(current_user, db, person, email, args, form, remote_addr)¶
- person_email_verify_use(current_user, db, args, form, remote_addr)¶
- person_proposals_own(current_user, db, facilities)¶
- person_proposals_other(current_user, db, person, can, facilities)¶
- _person_proposals(db, person_id, facilities, person, title)¶
- person_reviews_own(current_user, db, facilities)¶
- person_reviews_other(current_user, db, person, can, facilities, args)¶
- _person_reviews(current_user, db, person_id, facilities, person, as_admin=False, view_all=None, auth_cache=None)¶
- person_log(current_user, db, person, facilities, args)¶
- person_subsume(current_user, db, person, form)¶
- institution_list(current_user, db)¶
- institution_view(current_user, db, institution, can)¶
- institution_delete(current_user, db, institution, form)¶
- institution_edit(current_user, db, institution, can, form)¶
- institution_frozen_members(current_user, db, institution, facilities)¶
- institution_log(current_user, db, institution_id, form)¶
- institution_log_approval(current_user, db, form)¶
- _display_institution_log(db, institution_id, form)¶
- institution_subsume(current_user, db, institution_id, form)¶
- invitation_token_enter(current_user, db, args)¶
- invitation_token_accept(current_user, db, facilities, args, form, remote_addr)¶
- _determine_invitee_target(db, facilities, person)¶
Attempt to determine where to redirect, based on the “old” person record (from before invitation acceptance).
Ideally there will only be one proposal or review associated with this person record. If there are multiple proposals or multiple reviews, the person proposals / reviews page is returned. If there is a mixture of proposals or reviews (or none of either) then None is returned.
- hedwig.view.people._update_session_user(db, user_id, sess=flask.session, remote_addr=None, remote_agent=None)¶
Clears the session and inserts a token for the given user identifier.
This should be done on log in to ensure that nothing from a previous session remains.
hedwig.view.query¶
- class hedwig.view.query.QueryView¶
- cadc_name_resolver = 'https://ws.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/cadc-target-resolver/find'¶
- fixed_name_responses = {}¶
- get_country_list()¶
- get_institution_list(db)¶
- get_person_list(current_user, db, public)¶
- classmethod add_fixed_name_response(target, response, format_='json', type_='application/json;charset=ISO-8859-1')¶
- resolve_name(args)¶
Simple proxy for the CADC name resolver service.
Ideally CADC’s service would support HTTPS and CORS so that our JavaScript code could access it directly.
- hedwig.view.query.truncate(value, length, abbreviation=None)¶
hedwig.view.tool¶
- class hedwig.view.tool.TargetCoord(name, x, y, system)¶
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('name', 'x', 'y', 'system')¶
- classmethod _make(iterable)¶
Make a new TargetCoord object from a sequence or iterable
- _replace(**kwds)¶
Return a new TargetCoord object replacing specified fields with new values
- name¶
Alias for field number 0
- system¶
Alias for field number 3
- x¶
Alias for field number 1
- y¶
Alias for field number 2
- class hedwig.view.tool.BaseTargetTool(facility, id_)¶
- proposal_message_error = True¶
- classmethod get_code()¶
Get the target tool “code”.
This is a short string used to uniquely identify the target tool within facilities which use it. It will be used in URLs and would correspond to an entry in a “tool” database table if there is ever a need to store target tool results in the database.
- get_name()¶
Get the target tool’s name.
- get_default_facility_code()¶
Get the code of the facility for which this target tool is designed.
Target tools need only override this method if the tool is intended to be used with multiple facilities.
- Returns:
None if the tool is not expected to be used with multiple facilities, or the facility code otherwise
- get_custom_routes()¶
Method used to find any custom routes required by this tool.
Note that the route information will automatically be prefixed as follows:
template: <facility code>/tool_<tool code>_
rule: /tool/<tool code>/
endpoint: tool_<tool code>_
- Returns:
a list of RouteInfo tuples
- view_single(current_user, db, args, form)¶
View handler function for stand-alone usage of a target tool.
This is a generic implementation of the view for the target tool’s “single” mode. It parses coordinates entered by the user and calls the _view_single method with these coordinates, or None if no coordinate was available — e.g. when the form is first displayed for input or in the case of a parsing error.
- _view_single(current_user, db, target_object, extra_info, args, form)¶
Prepare extra template context for target tool in “single” mode.
Target tool sub-classes should override this method if they need to behave differently in different modes — otherwise they need only override _view_any_mode.
- Returns:
template context dictionary
- view_upload(current_user, db, args, form, file_)¶
View handler for stand-alone usage by file upload.
This is a generic implementation of the view for the target tool’s “upload” mode. It parses the file uploaded by the user and calls the _view_upload method with a list of coordinates, or None if no coordinates were available — e.g. when the form is first displayed for input or in the case of a parsing error.
- _view_upload(current_user, db, target_objects, extra_info, args, form)¶
Prepare extra template context for target tool in “upload” mode.
Target tool sub-classes should override this method if they need to behave differently in different modes — otherwise they need only override _view_any_mode.
- Returns:
template context dictionary
- view_proposal(current_user, db, proposal, can, args)¶
View handler function for proposal-based usage of a target tool.
This is a generic implementation of the view for the target tool’s “proposal” mode. It retrieves target coordinates from the given proposal and calls the _view_proposal method with this list. Unlike other target tool modes, in this mode we (currently) always perform the target analysis immediately on the HTTP GET request. So there is normally no input form stage and _view_proposal should not be called without a list of targets to process.
- Raises:
ErrorPage – if the proposal did not have any targets with coordinates
- _view_proposal(current_user, db, proposal, target_objects, extra_info, args, auth_cache)¶
Prepare extra template context for target tool in “proposal” mode.
Target tool sub-classes should override this method if they need to behave differently in different modes — otherwise they need only override _view_any_mode.
- Returns:
template context dictionary
- _view_any_mode(current_user, db, target_objects, extra_info, args, form, auth_cache)¶
Prepare extra template context for target tool in any mode.
Target tool sub-classes should override this method to implement the analysis routine which the tool is intended to perform.
If the tool needs to behave differently in different modes it can override the specific mode protected methods instead.
- Parameters:
db – database access object
target_object – list of TargetObject instances
args – HTTP arguments
form – HTTP form or None if not a POST request
- Returns:
template context dictionary
- _view_extra_info(args, form)¶
Read extra information from the query arguments or form.
This should be in a form safe to write to an encoded query string.
Errors parsing the input should be left until later.
- _encode_query(target, extra_info)¶
- _decode_query(query)¶
hedwig.view.util¶
- hedwig.view.util.count_words(text)¶
Counts the number of words in the given text.
“text” can be a string, or any object with a “text” attribute, such as PropsalText.
- hedwig.view.util.float_or_none(value)¶
Converts the given string to a float, or returns None if it is empty.
Intended for parsing form selection values where there is an undefined value.
- hedwig.view.util.int_or_none(value)¶
Converts the given string to an integer, or returns None if it is empty.
Intended for parsing form selection values where there is an undefined value.
- hedwig.view.util.str_or_none(value)¶
Returns the given string as is, unless it is empty, in which case None is returned.
- hedwig.view.util.join_list(words, conjunction='and')¶
Join the words in the given list with commas, ending the list with the given conjunction and final word.
- hedwig.view.util.with_call_review(permission)¶
Decorator for methods which deal with reviews of all the proposals for a given call.
Assumes that the first arguents are a database object and call ID. The wrapped method is called with the database, call record and authorization object followed by any remaining arguments.
Note: this currently can only be used to decorate methods of facility classes because it uses self.id_ for the facility ID.
- hedwig.view.util.with_institution(permission)¶
Decorator for methods which deal with institution records.
Assumes that the first arguments are a database object and institution ID. Checks that the uesr has the requested permission and then calls the wrapped method with the database, institution and authorization object as the first arguments.
- hedwig.view.util.with_person(permission)¶
Decorator for methods which deal with personal profiles.
Assumes that the first arguments are a database object and person ID. Checks that the user has the requested permission and then calls the wwrapped method with the database, proposal and authorization object as the first arguments.
- hedwig.view.util.with_proposal(permission, indirect_facility=False, allow_unaccepted_review=None, **get_proposal_kwargs)¶
Decorator for methods which deal with proposals.
Assumes that the first arguments are a database object and proposal ID. Then checks that the current user has the requested permission. The wrapped method is then called with the database, proposal and authorization objects as the first three arguments.
“permission” should be one of: “VIEW”, “EDIT”, “FEEDBACK” or “NONE”.
When “FEEDBACK” is selected, view authorization to the proposal feedback is required.
When “NONE” is selected, no authorization object is passed on.
The allow_unaccepted_review argument is passed on to auth.for_proposal.
Additional keyword arguments are passed to the get_proposal database method.
Note: this currently can only be used to decorate methods of facility classes because it uses self.id_ for the facility ID.
- hedwig.view.util.with_relevant_text_role(f)¶
Decorator to fetch the facility text role class.
Assumes that the argument list contains the proposal (as set up by with_proposal followed by the role identifier. Gets the facility’s text role class and proposal section order for the type of the given proposal. If the text role has a specified proposal section, and that section is not part of the given proposal, raises an HTTPNotFound exception.
Adds the role class to the argument list, just before the role. (It currently does this rather than replacing the role argument with the role info because some existing view methods interact with the role class itself.)
Note: this currently can only be used to decorate methods of facility classes because it uses facility methods.
- hedwig.view.util.with_review(permission, with_invitation=False, with_note=False, with_acceptance=False, allow_unaccepted=None, **get_proposal_kwargs)¶
Decorator for methods which deal with reviews of proposals.
Assumes that the first arguents are a database object and reviewer ID. The wrapped method is called with the database, reviewer record, proposal record and authorization object followed by any remaining arguments.
The allow_unaccepted argument is passed on to auth.for_review.
Additional keyword arguments are passed to the get_proposal database method.
- hedwig.view.util.with_user()¶
- hedwig.view.util.parse_time(input_time)¶
Accepts a time string, either as a decimal number of hours, or as hours:minutes:seconds, and returns a float in hours.