def view_internaltransfer(db_id):
    transfer = data_models.lookup_entity(db_id)
    fund = data_models.get_parent(transfer)
    model = data_models.Model(transfer, fund.committee)
    add_transfer_form(request.form, model, ACTION_UPDATE)
    title = 'InternalTransfer to ' + transfer.dest_fund.get(
    ).name if transfer.dest_fund != None else ""
    property_list = (state_field, properties.KeyProperty('creator'),
                     properties.KeyProperty('dest_fund'),
                     properties.StringProperty('amount'),
                     properties.StringProperty('description'))
    return views.view_std_entity(model, title, property_list, action_list)
def view_pledge(db_id):
    pledge = data_models.lookup_entity(db_id)
    fund = data_models.get_parent(pledge)
    model = data_models.Model(pledge, fund.committee)
    form = PledgeForm(request.form, obj=pledge)
    model.add_form(ACTION_UPDATE.name, form)
    title = 'Pledge ' + pledge.ref_id
    property_list = (ref_id_field, state_field,
                     properties.KeyProperty('creator'),
                     properties.StringProperty('amount'),
                     properties.StringProperty('description'))
    return views.view_std_entity(
        model, title, property_list,
        (ACTION_UPDATE, ACTION_FULFILLED, ACTION_BOOKED))
def view_supplier_list():
    new_supplier = db.Supplier()
    form = SupplierForm(request.form, obj=new_supplier)
    model = data_models.Model(new_supplier, None, db.Supplier)
    model.add_form('create', form)
    property_list = (properties.StringProperty('name'), )
    supplier_query = db.Supplier.query().order(db.Supplier.name)
    return views.view_std_entity_list(model, 'Supplier List', ACTION_CREATE,
                                      property_list, supplier_query)
Beispiel #4
0
def view_project_list(db_id):
    supplier = data_models.lookup_entity(db_id)
    new_project = db.Project(parent=supplier.key)
    model = data_models.Model(new_project, None, db.Project)
    form = create_project_form(new_project, supplier)
    model.add_form(ACTION_CREATE.name, form)
    property_list = (state_field, properties.StringProperty('name', 'Name'))
    project_query = db.Project.query(ancestor=supplier.key).order(
        -db.Project.state_index, db.Project.name)
    return views.view_std_entity_list(model, 'Project List', ACTION_CREATE,
                                      property_list, project_query, supplier)
Beispiel #5
0
def view_purchase_list(db_id):
    fund = data_models.lookup_entity(db_id)
    new_purchase = db.Purchase(parent=fund.key)
    model = PurchaseModel(new_purchase, fund.committee, db.Purchase)
    add_purchase_form(request.form, model, ACTION_CREATE)
    property_list = (state_field, po_number_field, supplier_field,
                     properties.StringProperty('quote_amount'))
    purchase_query = db.Purchase.query(ancestor=fund.key).order(
        -db.Purchase.state_index, db.Purchase.po_number)
    return views.view_std_entity_list(model, 'Purchase List', ACTION_CREATE,
                                      property_list, purchase_query, fund)
def view_pledge_list(db_id):
    fund = data_models.lookup_entity(db_id)
    new_pledge = db.Pledge(parent=fund.key)
    model = data_models.Model(new_pledge, fund.committee, db.Pledge)
    form = PledgeForm(request.form, obj=new_pledge)
    model.add_form(ACTION_CREATE.name, form)
    property_list = (state_field, ref_id_field,
                     properties.StringProperty('amount'))
    pledge_query = db.Pledge.query(ancestor=fund.key).order(
        -db.Pledge.state_index, db.Pledge.ref_id)
    return views.view_std_entity_list(model, 'Pledge List', ACTION_CREATE,
                                      property_list, pledge_query, fund)
Beispiel #7
0
def view_committee_list():
    model = data_models.Model(None)
    breadcrumbs = views.view_breadcrumbs(None)
    supplier_field_list = (properties.StringProperty('name'), )
    committee_list = data_models.get_committee_list()
    entity_table = views.view_entity_list(committee_list, committee_field_list)
    user_controls = views.view_user_controls(model)
    return render_template('layout.html',
                           title='Committee List',
                           breadcrumbs=breadcrumbs,
                           user=user_controls,
                           content=entity_table)
def view_internaltransfer_list(db_id):
    fund = data_models.lookup_entity(db_id)
    new_transfer = db.InternalTransfer(parent=fund.key)
    model = data_models.Model(new_transfer, fund.committee,
                              db.InternalTransfer)
    add_transfer_form(request.form, model, ACTION_CREATE)
    property_list = (state_field, properties.KeyProperty('dest_fund'),
                     properties.StringProperty('amount'))
    transfer_query = db.InternalTransfer.query(
        ancestor=fund.key).order(-db.InternalTransfer.state_index)
    return views.view_std_entity_list(model, 'Internal Transfer List',
                                      ACTION_CREATE, property_list,
                                      transfer_query, fund)
def process_supplier(db_id):
    supplier = data_models.lookup_entity(db_id)
    if request.method == 'POST':
        form = SupplierForm(request.form)
    else:
        form = SupplierForm(obj=supplier)
    model = data_models.Model(supplier, None, db.Supplier)
    model.add_form('update', form)
    valid_actions = [ACTION_UPDATE]
    if not supplier.paid_in_sterling:
        valid_actions.append(ACTION_TRANSFER_START)
    if request.method == 'POST' and views.handle_post(model, valid_actions):
        return redirect_url(model)
    breadcrumbs = views.view_breadcrumbs_list(supplier)
    links = views.view_links(supplier, *get_link_pairs(supplier))
    fields = (properties.StringProperty('name'), )
    grid = views.view_entity(supplier, fields)
    title = 'Supplier ' + supplier.name
    purchase_payments = render_purchase_payments_list(supplier)
    content_list = [grid, purchase_payments]
    if supplier.receives_grants:
        grant_payments = render_grants_due_list(supplier)
        content_list.append(grant_payments)
    content_list.append(views.view_entity_history(supplier.key))
    buttons = views.view_actions(valid_actions, model)
    errors = views.view_errors(model)
    content = renderers.render_div(*content_list)
    user_controls = views.view_user_controls(model)
    return {
        'title': title,
        'breadcrumbs': breadcrumbs,
        'user': user_controls,
        'links': links,
        'buttons': buttons,
        'errors': errors,
        'content': content
    }
Beispiel #10
0
]


def state_of(purchase):
    state = purchase.state_index
    if state == STATE_ORDERED:
        if purchase.invoice != None and not purchase.invoice.get().paid:
            return STATE_PAYMENT_DUE
        if purchase.advance != None:
            return STATE_ADVANCED if purchase.advance.get(
            ).paid else STATE_ADVANCE_PENDING
    return state


supplier_field = properties.KeyProperty('supplier')
quote_amount_field = properties.StringProperty('quote_amount')
description_field = properties.StringProperty('description')
state_field = properties.SelectProperty(state_of, 'State',
                                        enumerate(state_labels))
po_number_field = properties.StringProperty('po_number', 'PO number')
creator_field = properties.KeyProperty('creator')

payment_amount_field = properties.StringProperty('amount', 'Payment Amount')
payment_paid_field = properties.StringProperty('paid', 'Paid')
payment_type_field = properties.StringProperty(
    lambda e: e.payment_type.capitalize(), 'Type')
payment_transfer_field = properties.KeyProperty('transfer')
payment_transferred_field = properties.StringProperty(
    lambda e: data_models.calculate_transferred_amount(e),
    'Transferred Amount')
Beispiel #11
0
#_*_ coding: UTF-8 _*_

from flask import render_template
from application import app

import data_models
import properties
import views

committee_field_list = (properties.StringProperty('name'), )


@app.route('/committee_list', methods=['GET'])
def view_committee_list():
    model = data_models.Model(None)
    breadcrumbs = views.view_breadcrumbs(None)
    supplier_field_list = (properties.StringProperty('name'), )
    committee_list = data_models.get_committee_list()
    entity_table = views.view_entity_list(committee_list, committee_field_list)
    user_controls = views.view_user_controls(model)
    return render_template('layout.html',
                           title='Committee List',
                           breadcrumbs=breadcrumbs,
                           user=user_controls,
                           content=entity_table)


@app.route('/committee/<db_id>', methods=['GET'])
def view_committee(db_id):
    model = data_models.Model(None)
    committee = data_models.lookup_committee(db_id)
Beispiel #12
0
import logging

from application import app
import custom_fields
import db
import data_models
import mailer
import properties
import renderers
import views
import urls
from role_types import RoleType

state_labels = ['Closed', 'Open']

name_field = properties.StringProperty('name')
code_field = properties.StringProperty('code')
description_field = properties.StringProperty('description')
state_field = properties.SelectProperty('state_index', 'State',
                                        enumerate(state_labels))


def close_fund(model, action_name):
    model.perform_close(action_name)
    fund = model.entity
    users = model.lookup_users_with_role(RoleType.FUND_ADMIN)
    to_addresses = map(lambda u: u.email, users)
    entity_ref = renderers.render_link(
        fund.name, urls.url_for_entity(fund, external=True))
    content = renderers.render_div('Fund closed ', entity_ref,
                                   ' code=%s' % fund.code)
Beispiel #13
0
from flask import render_template

from application import app
import db
import data_models
import views
import properties
import renderers
import role_types

from page import *

audit_fields = [
    properties.DateProperty('timestamp'),
    properties.StringProperty(lambda e: e.entity.kind(), 'EntityType'),
    properties.KeyProperty('entity'),
    properties.StringProperty('message'),
    properties.KeyProperty('user')
]


@app.route('/')
def home():
    model = data_models.Model(None)
    links = views.view_links(None, ('Committee', 'Show Committees'),
                             ('Supplier', 'Show Suppliers'),
                             ('User', 'Show Users'))
    audit_list = db.AuditRecord.query(db.AuditRecord.parent == None).order(
        -db.AuditRecord.timestamp).fetch(10)
    sub_heading = renderers.sub_heading('Recent Activity')
    model.audit(action_name, 'Fulfilled performed')


ACTION_FULFILLED = views.StateAction('fulfilled', 'Fulfilled',
                                     RoleType.INCOME_ADMIN, perform_fulfilled,
                                     [STATE_PENDING])
ACTION_BOOKED = views.StateAction('booked', 'Booked', RoleType.FUND_ADMIN,
                                  data_models.Model.perform_close,
                                  [STATE_FULFILLED])
ACTION_UPDATE = views.update_action(RoleType.COMMITTEE_ADMIN, [STATE_PENDING])
ACTION_CREATE = views.Action('create', 'New', RoleType.COMMITTEE_ADMIN,
                             perform_create)

state_field = properties.SelectProperty('state_index', 'State',
                                        enumerate(state_labels))
ref_id_field = properties.StringProperty('ref_id', 'Reference')


class MoneyForm(wtforms.Form):
    value = wtforms.IntegerField()


class PledgeForm(wtforms.Form):
    amount = wtforms.FormField(MoneyForm,
                               widget=custom_fields.form_field_widget)
    description = wtforms.TextAreaField()


@app.route('/pledge_list/<db_id>', methods=['GET', 'POST'])
def view_pledge_list(db_id):
    fund = data_models.lookup_entity(db_id)
    transfer.put()
    return transfer


def render_grants_due_list(supplier):
    cutoff_date = datetime.date.today() + datetime.timedelta(21)
    grant_list = db.find_pending_grants(supplier, cutoff_date)
    field_list = (grants.state_field, grants.target_date_field,
                  grants.creator_field, grants.source_field,
                  grants.project_field, grants.amount_field)
    sub_heading = renderers.sub_heading('Grant Payments Due')
    table = views.view_entity_list(grant_list, field_list)
    return (sub_heading, table)


po_number_field = properties.StringProperty(
    lambda e: e.key.parent().get().po_number, 'PO Number')
creator_field = properties.KeyProperty(lambda e: e.key.parent().get().creator,
                                       'Requestor')
source_field = properties.StringProperty(
    lambda e: e.key.parent().parent().get().code, 'Source Fund')
payment_field_list = [
    purchases.payment_type_field, po_number_field, creator_field, source_field,
    purchases.payment_amount_field
]


def render_purchase_payments_list(supplier):
    column_headers = properties.get_labels(payment_field_list)
    payment_list = db.find_pending_payments(supplier)
    payment_grid = properties.display_entity_list(payment_list,
                                                  payment_field_list,
Beispiel #16
0
    url = urls.url_for_list(kind, parent)
    return renderers.render_link(label, url, class_="button")


def view_links(parent, *link_pairs):
    links = [view_link(kind, label, parent) for kind, label in link_pairs]
    return renderers.render_nav(*links)


def view_errors(model):
    return renderers.render_errors(model.errors)


audit_fields = [
    properties.DateProperty('timestamp'),
    properties.StringProperty('message'),
    properties.KeyProperty('user')
]


def view_entity_history(key):
    audit_list = db.AuditRecord.query(
        db.AuditRecord.entity == key).order(-db.AuditRecord.timestamp).iter(
            limit=20)
    sub_heading = renderers.sub_heading('Activity Log')
    table = view_entity_list(audit_list,
                             audit_fields,
                             selectable=False,
                             no_links=False)
    return (sub_heading, table)
#_*_ coding: UTF-8 _*_

from flask import request
from application import app
import wtforms

import custom_fields
import data_models
import db
import properties
import views
from role_types import RoleType

name_field = properties.StringProperty('name')

ACTION_UPDATE = views.update_action(RoleType.SUPPLIER_ADMIN)
ACTION_CREATE = views.create_action(RoleType.SUPPLIER_ADMIN)


class PartnerForm(wtforms.Form):
    name = wtforms.StringField(validators=[wtforms.validators.InputRequired()])


@app.route('/partner_list/<db_id>', methods=['GET', 'POST'])
def view_partner_list(db_id):
    supplier = data_models.lookup_entity(db_id)
    new_partner = db.Partner(parent=supplier.key)
    model = data_models.Model(new_partner, None, db.Partner)
    form = PartnerForm(request.form, obj=new_partner)
    model.add_form(ACTION_CREATE.name, form)
    partner_query = db.Partner.query(ancestor=supplier.key).order(
Beispiel #18
0
    model.email_and_audit(action_name, 'Checked performed')

ACTION_CHECKED = views.StateAction('checked', 'Funds Checked', RoleType.FUND_ADMIN,
                                   perform_checked, [STATE_WAITING])
ACTION_ACKNOWLEDGED = views.StateAction('ack', 'Received', RoleType.COMMITTEE_ADMIN,
                                        data_models.Model.perform_close, [STATE_TRANSFERED])
ACTION_CANCEL = views.cancel_action(RoleType.COMMITTEE_ADMIN, [STATE_WAITING, STATE_READY])
ACTION_UPDATE = views.update_action(RoleType.COMMITTEE_ADMIN, [STATE_WAITING])
ACTION_CREATE = views.Action('create', 'New', RoleType.COMMITTEE_ADMIN, perform_create)

action_list = [ACTION_UPDATE, ACTION_CHECKED, ACTION_ACKNOWLEDGED, ACTION_CANCEL]

state_field = properties.SelectProperty(state_of, 'State', enumerate(state_labels))
creator_field = properties.KeyProperty('creator', 'Requestor')
project_field = properties.KeyProperty('project')
amount_field = properties.StringProperty('amount')
transferred_amount_field = properties.StringProperty(data_models.calculate_transferred_amount, 'Transferred Amount')
source_field = properties.StringProperty(lambda e: e.key.parent().get().code, 'Source Fund')
target_date_field = properties.DateProperty('target_date', format='%Y-%m')
description_field = properties.StringProperty('description')
foreign_transfer_field = properties.KeyProperty('transfer')

class GrantForm(wtforms.Form):
    amount = wtforms.FormField(custom_fields.MoneyForm, label='Requested Amount', widget=custom_fields.form_field_widget)
    project = custom_fields.SelectField(coerce=data_models.create_key, validators=[wtforms.validators.InputRequired()])
    target_date = wtforms.DateField(widget=widgets.MonthInput(), format='%Y-%m',
                                validators=[wtforms.validators.InputRequired()])
    description = wtforms.TextAreaField()

def add_grant_form(model, action):
    form = GrantForm(request.form, obj=model.entity)
Beispiel #19
0
import custom_fields
import data_models
import db
import views
import properties
from role_types import RoleType

ACTION_UPDATE = views.update_action(RoleType.USER_ADMIN)
ACTION_CREATE = views.create_action(RoleType.USER_ADMIN)

class UserForm(wtforms.Form):
    name = wtforms.StringField(validators=[wtforms.validators.InputRequired()])
    email =  wtforms.StringField(validators=[wtforms.validators.InputRequired()])

name_field = properties.StringProperty('name')
email_field = properties.StringProperty('email')

@app.route('/user_list', methods=['GET', 'POST'])
def view_user_list():
    new_user = db.User()
    model = data_models.Model(new_user, None, db.User)
    form = UserForm(request.form, obj=new_user)
    model.add_form(ACTION_CREATE.name, form)
    user_query = db.User.query().order(db.User.name)
    property_list = (name_field, email_field)
    return views.view_std_entity_list(model, 'User List', ACTION_CREATE, property_list,
                                      user_query)

link_pairs = [('Role', 'Show Roles')]