コード例 #1
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def saved_data(facility_name, module_name, table_name, row_names, page_context):
    msg = 'Saved: '
    error = False
    saved_rows = {}
    for row_info in row_names.values():
        if row_info['name'] == 'error':

            msg = 'Error: %s,' % str(row_info['table']).replace('<', '').replace('>', '')
            error = True
        else:
            table = urllib.parse.quote(row_info['table'])
            name = urllib.parse.quote(row_info['name'])
            msg += (' <a href=' + request.url_root + facility_name + '/' + module_name + '/detail/' +
                    table + '/' + name + '>' +  row_info['name'] + '</a>,')

            # TODO: allow this to support data saving by other than name
            if not table in saved_rows:
                saved_rows[table] = []
            saved_rows[table].append({
                'column': 'name',
                'value': name,
                'id': row_info['id'],
                'table': table
            })
    msg = msg[:-1]

    if error:
        pt = PageTemplate(MODULE_NAME, 'error_message', page_context)
        return pt.page_template_context(table_name=table_name, page_msg=msg)
    else:
        pt = PageTemplate(MODULE_NAME, 'save_message', page_context)
        return pt.page_template_context(table_name=table_name, page_msg=msg, saved_rows=json.dumps(saved_rows))
コード例 #2
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def cache(facility_name):
    module_name = MODULE_NAME
    form = forms.CacheForm()
    value = None
    if form.validate_on_submit() and len(form.errors) == 0:
        if "get_value" in request.form and request.form["get_value"]:
            if form.data["key"]:
                value = current_app.cache.get(form.data["key"])
                if hasattr(value, "data"):
                    value = value.data
        elif "set_key" in request.form and request.form["set_key"]:
            if form.data["key"] and form.data["value"]:
                current_app.cache.set(form.data["key"], form.data["value"], None, None, False)
                value = "successfully set key " + form.data["key"] + " = " + form.data["value"]
        elif "get_version" in request.form and request.form["get_version"]:
            if form.data["refresh_obj"]:
                value = str(current_app.cache.get_version(form.data["refresh_obj"]))
            elif form.data["key"]:
                value = str(current_app.cache.get_key_version(form.data["key"]))
        elif "set_version" in request.form and request.form["set_version"]:
            if form.data["refresh_obj"] and form.data["version"]:
                success = current_app.cache.set_version(form.data["refresh_obj"], form.data["version"])
                if success:
                    value = "successfully "
                else:
                    value = "failed to "
                value += "set version " + form.data["refresh_obj"] + " = " + form.data["version"]

    pt = PageTemplate(MODULE_NAME, "cache")

    return pt.page_template_context(module_name=module_name, form=form, value=value)
コード例 #3
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def cache(facility_name):
    module_name = MODULE_NAME
    form = forms.CacheForm()
    value = None
    if form.validate_on_submit() and len(form.errors) == 0:
        if 'get_value' in request.form and request.form['get_value']:
            if form.data['key']:
                value = current_app.cache.get(form.data['key'])
                if hasattr(value, 'data'):
                    value = value.data
        elif 'set_key' in request.form and request.form['set_key']:
            if form.data['key'] and form.data['value']:
                current_app.cache.set(form.data['key'], form.data['value'],
                                      None, None, False)
                value = ('successfully set key ' + form.data['key'] + ' = ' +
                         form.data['value'])
        elif 'get_version' in request.form and request.form['get_version']:
            if form.data['refresh_obj']:
                value = str(current_app.cache.get_version(form.data['refresh_obj']))
            elif form.data['key']:
                value = str(current_app.cache.get_key_version(form.data['key']))
        elif 'set_version' in request.form and request.form['set_version']:
            if form.data['refresh_obj'] and form.data['version']:
                success = current_app.cache.set_version(form.data['refresh_obj'], form.data['version'])
                if success:
                    value = 'successfully '
                else:
                    value = 'failed to '
                value += ('set version ' + form.data['refresh_obj'] + ' = ' +
                          form.data['version'])

    pt = PageTemplate(MODULE_NAME, 'cache')

    return pt.page_template_context(module_name=module_name, form=form, value=value)
コード例 #4
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def review(facility_name, year = None, month = None):
    # options for dropdowns
    select_years = util.get_last_x_years(5)
    select_months = util.get_months_dict()

    if not month or not year: #mostly we default to last_month
        # default to last month, get start and end dates
        last_month = util.get_last_month()
        year = last_month.year
        month = last_month.month

    from_date, to_date = util.start_and_end_month(year, month)

    # get line_items for month
    criteria = {
            ('line_item', 'date_created'): {'from': from_date, 'to': to_date},
            ('line_item', 'price_per_unit'): {'compare': 'greater than', 'value': 0}
    }
    tqc = TableQueryCollection('line_item', criteria)
    table_query = tqc.get_first()
    pt = PageTemplate(MODULE_NAME, 'review')
    return pt.page_template_context(
            year = year, month = month,
            select_years = select_years, select_months = select_months,
            table_name = 'line_item', table_query = table_query
    )
コード例 #5
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def build_summary(table_name, page_form, context={}):
    tqc = TableQueryCollection(table_name)
    tq = tqc.get_first()
    if not tq.fc.fields:
        abort(404)

    pt = PageTemplate(MODULE_NAME, page_form, context['page_context'])
    return pt.page_template_context(table_name=table_name, table_query=tq, **context)
コード例 #6
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def invoice_summary(facility_name, year, month):
    # options for dropdowns
    select_years = util.get_last_x_years(5)
    select_months = util.get_months_dict()
    from_date, to_date = util.start_and_end_month(year, month)

    criteria = {
            ('invoice', 'invoice_month'): {'from': from_date, 'to': to_date},
    }
    tqc = TableQueryCollection('invoice', criteria)
    hidden_fields = {'year': year, 'month': month}
    pt = PageTemplate(MODULE_NAME, 'invoice_summary')
    return pt.page_template_context(
            select_years = select_years, select_months = select_months,
            year = year, month = month, from_date = from_date, table_name = 'invoice', table_query = tqc.queries[0],
            hidden_fields = hidden_fields, facility_name = facility_name
    )
コード例 #7
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def reports(facility_name, year = None, month = None):
    # options for dropdowns
    select_years = util.get_last_x_years(5)
    select_months = util.get_months_dict()

    if not month or not year: #mostly we default to last_month
        # default to last month, get start and end dates
        last_month = util.get_last_month()
        year = last_month.year
        month = last_month.month

    lc = LineItemCollection(year, month)
    lc.populate_report_data()
    pt = PageTemplate(MODULE_NAME, 'reports')
    return pt.page_template_context(
            lc = lc, year = year, month = month,
            select_years = select_years, select_months = select_months)
コード例 #8
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def detail(facility_name, table_name, row_name, page_context):
    criteria = {(table_name, 'name'): row_name}
    tqc = TableQueryCollection(table_name, criteria)
    tqc.get_results()
    add_row_id = False
    tqc.format_results(add_row_id)
    if not tqc.get_first().fc.fields:
        abort(404)
    if not tqc.get_first().table_dict:
        abort(403)
    hidden_fields = {'table': table_name, 'row_name': row_name}

    pt = PageTemplate(MODULE_NAME, 'detail', page_context)

    return pt.page_template_context(
        table_name=table_name,
        row_name=row_name,
        table_queries=tqc,
        hidden_fields=hidden_fields,
        page_context=page_context.split(',')
    )
コード例 #9
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def saved_data(facility_name, module_name, table_name, row_names, page_context):
    msg = "Saved: "
    error = False
    saved_rows = {}
    for row_info in row_names.values():
        if row_info["name"] == "error":

            msg = "Error: %s," % str(row_info["table"]).replace("<", "").replace(">", "")
            error = True
        else:
            table = urllib.parse.quote(row_info["table"])
            name = urllib.parse.quote(row_info["name"])
            msg += (
                " <a href="
                + request.url_root
                + facility_name
                + "/"
                + module_name
                + "/detail/"
                + table
                + "/"
                + name
                + ">"
                + row_info["name"]
                + "</a>,"
            )

            # TODO: allow this to support data saving by other than name
            if not table in saved_rows:
                saved_rows[table] = []
            saved_rows[table].append({"column": "name", "value": name, "id": row_info["id"], "table": table})
    msg = msg[:-1]

    if error:
        pt = PageTemplate(MODULE_NAME, "error_message", page_context)
        return pt.page_template_context(table_name=table_name, page_msg=msg)
    else:
        pt = PageTemplate(MODULE_NAME, "save_message", page_context)
        return pt.page_template_context(table_name=table_name, page_msg=msg, saved_rows=json.dumps(saved_rows))
コード例 #10
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def workflow_complete(facility_name, workflow_name, work_item_group):
    wig = WorkItemGroup(work_item_group, workflow_name)
    pt = PageTemplate(MODULE_NAME, 'workflow_complete')

    return pt.page_template_context(wig=wig)
コード例 #11
0
ファイル: routes.py プロジェクト: harvardinformatics/iggybase
def default(facility_name):
    pt = PageTemplate(MODULE_NAME, 'index.html')
    return pt.page_template_context('index.html')
コード例 #12
0
def index():
    pt = PageTemplate(None, 'index')
    return pt.page_template_context()
コード例 #13
0
def page_not_found():
    logging.info('page_not_found')
    pt = PageTemplate(None, 'not_authorized')
    return pt.page_template_context()
コード例 #14
0
def forbidden():
    pt = PageTemplate(None, 'forbidden')
    return pt.page_template_context()
コード例 #15
0
def message(page_temp, page_msg):
    pt = PageTemplate(None, page_temp, page_msg=page_msg)
    return pt.page_template_context()