def perform_delete(model, action_name): model.entity.key.delete() parent = data_models.get_parent(model.entity) roleName = dict(get_choices()).get(model.entity.type_index, "") model.audit(action_name, "Delete role %s performed" % roleName, parent) model.entity_deleted = True return True
def render(self, model): label = 'Show Open' if model.show_closed else 'Show Closed' query_params = {} if model.show_closed else {'show_closed': 'y'} parent = data_models.get_parent(model.entity) url = urls.url_for_list(model.entity.key.kind(), parent, **query_params) return renderers.render_link(label, url, class_='button')
def perform_start_transfer(model, action_name): supplier = model.entity grant_list = db.find_ready_grants(supplier) payment_list = db.PurchasePayment.query( db.PurchasePayment.supplier == supplier.key).filter( db.PurchasePayment.paid == False).fetch() if len(grant_list) == 0 and len(payment_list) == 0: model.add_error( "No grants or purchase payments are pending - nothing to transfer") return False transfer = create_transfer(supplier, model.user) parent_audit = model.audit(action_name, 'Transfer started', transfer) model.next_entity = transfer for grant in grant_list: grant.transfer = transfer.key grant.put() model.audit(action_name, 'Transfer started', grant, parent_audit.key) for payment in payment_list: payment.transfer = transfer.key payment.put() purchase = data_models.get_parent(payment) model.audit(action_name, '%s Transfer started' % payment.payment_type.capitalize(), purchase, parent_audit.key) return True
def view_partner(db_id): partner = data_models.lookup_entity(db_id) supplier = data_models.get_parent(partner) model = data_models.Model(partner, None, db.Partner) form = PartnerForm(request.form, obj=partner) model.add_form(ACTION_UPDATE.name, form) return views.view_std_entity(model, 'Partner ' + partner.name, (name_field, ), (ACTION_UPDATE, ))
def create_breadcrumbs_list(entity): parent = data_models.get_parent(entity) breadcrumbs = create_breadcrumbs(parent) kind = entity.key.kind() query_parameters = {} if hasattr(entity, 'state_index') and entity.state_index == 0: query_parameters = {'show_closed': 'y'} url = urls.url_for_list(kind, parent, **query_parameters) return breadcrumbs + [" / ", renderers.render_link(kind + " List", url)]
def view_grant(db_id): grant = data_models.lookup_entity(db_id) fund = data_models.get_parent(grant) model = GrantModel(grant, fund.committee) add_grant_form(model, ACTION_UPDATE) title = 'Grant on ' + str(grant.target_date) property_list = (state_field, creator_field, transferred_amount_field, amount_field, project_field, target_date_field, foreign_transfer_field, description_field) return views.view_std_entity(model, title, property_list, action_list, num_wide=1)
def load_purchase_model(purchase, request_data): fund = data_models.get_parent(purchase) model = PurchaseModel(purchase, fund.committee, db.Purchase) add_purchase_form(request_data, model, ACTION_UPDATE) invoice_form = PaymentAmountForm(request_data) model.add_form(ACTION_INVOICE.name, invoice_form) advance_form = PaymentAmountForm(request_data) model.add_form(ACTION_ADVANCE.name, advance_form) return model
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 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, no_links=True) purchase_list = [data_models.get_parent(e) for e in payment_list] payment_url_list = map(urls.url_for_entity, purchase_list) sub_heading = renderers.sub_heading('Purchase Payments Due') table = renderers.render_table(column_headers, payment_grid, payment_url_list) return (sub_heading, table)
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_project(db_id): project = data_models.lookup_entity(db_id) supplier = data_models.get_parent(project) model = data_models.Model(project, None, db.Project) form = create_project_form(project, supplier) model.add_form(ACTION_UPDATE.name, form) property_list = [state_field] + map(properties.create_readonly_field, form._fields.keys(), form._fields.values()) return views.view_std_entity(model, 'Project ' + project.name, property_list, action_list, num_wide=1)
def view_supplierfund(db_id): fund = data_models.lookup_entity(db_id) supplier = data_models.get_parent(fund) model = data_models.Model(fund, None, db.SupplierFund) if request.form: form = SupplierFundForm(request.form) else: form = SupplierFundForm(obj=fund) model.add_form(ACTION_UPDATE.name, form) property_list = map(properties.create_readonly_field, form._fields.keys(), form._fields.values()) return views.view_std_entity(model, 'SupplierFund ' + fund.name, property_list, (ACTION_UPDATE, ), num_wide=1)
def redirect_url(model): if model.entity_deleted: kind = model.entity.key.kind() parent = data_models.get_parent(model.entity) return urls.url_for_list(kind, parent) return request.base_url