def get_claims(): with contextlib.closing(make_session()) as session: claims = session.query(Claim).all() return [(json_decode(claim.claimant_information), json_decode(claim.employee_record), claim.submitted_at) for claim in claims]
def send_doc(update, context): args = update.message.text.split(' ', 3) user_id = update.message.from_user.id fname = None with make_session() as session: user = session.query(User).filter( User.id == update.message.from_user.id).one() if len(args) < 2: resp = "\n".join("%s: %s" % (b.shortname, b.url) for b in user.bookmarks) update.message.reply_text(resp, quote=True) else: explicit_sleep = None if len(args) >= 3: explicit_sleep = int(args[1]) url = session.query(Bookmark)\ .filter(Bookmark.user_id == user_id)\ .filter(Bookmark.shortname == args[-1])\ .one().url fname = gen_fname() + ".png" if fname: make_screenshot(url, fname, explicit_sleep) with open(fname, 'rb') as fin: update.message.reply_document(fin, quote=True) os.remove(fname)
def chomp_claim_done(claim_id): with contextlib.closing(make_session()) as session: claim = _multiple_results_hack( session.query(Claim).filter( Claim.claim_id == claim_id)) claim.chomp_claim_lifecycle.done = datetime.now() session.commit()
def claims_against_company(employer_id): with contextlib.closing(make_session()) as session: claims = session.query(Claim)\ .filter(Claim.employer_id == employer_id).all() return [(json_decode(claim.claimant_information), json_decode(claim.employee_record)) for claim in claims]
def employee_via_nino(nino): with contextlib.closing(make_session()) as session: try: employee = session.query(Employee).filter(Employee.nino == nino).one() return {key: json.loads(value, object_hook=decode_special_types) for key, value in employee.hstore.items()} except NoResultFound: pass
def get_claims_submitted_between(start, end): with contextlib.closing(make_session()) as session: claims = session.query(Claim).filter(Claim.submitted_at is not None)\ .filter(Claim.submitted_at > start)\ .filter(Claim.submitted_at < end).all() return [(claim.claimant_information, claim.employee_record, claim.submitted_at) for claim in claims]
def add_claim(claimant_information, employee_record): with contextlib.closing(make_session()) as session: claim = Claim() claim.employer_id = employee_record.get('employer_id', None) claim.claimant_information = json_encode(claimant_information) claim.employee_record = json_encode(employee_record) session.add(claim) session.commit() return claim.claim_id
def employee_via_nino(nino): nino = nino.upper() with contextlib.closing(make_session()) as session: try: employee = _multiple_results_hack( session.query(Employee).filter( Employee.nino == nino)) return json_decode(employee.hstore) except NoResultFound: pass
def add_rp14_form(dictionary): with contextlib.closing(make_session()) as session: employer = Employer() employer.ip_number = dictionary["ip_number"] employer.employer_name = dictionary["employer_name"] employer.company_number = dictionary["company_number"] employer.date_of_insolvency = dictionary["date_of_insolvency"] employer.hstore = json_encode(dictionary) session.add(employer) session.commit()
def add_rp14_form(dictionary): with contextlib.closing(make_session()) as session: employer = Employer() employer.ip_number = dictionary["ip_number"] employer.employer_name = dictionary["employer_name"] employer.company_number = dictionary["company_number"] employer.date_of_insolvency = dictionary["date_of_insolvency"] employer.hstore = {key: json.dumps(value, default=encode_special_types) for key, value in dictionary.items()} session.add(employer) session.commit()
def add_rp1_form(dictionary): with contextlib.closing(make_session()) as session: claimant = Claimant() claimant.nino = dictionary["nino"].upper() claimant.date_of_birth = dictionary["date_of_birth"] claimant.title = dictionary["title"] claimant.forenames = dictionary["forenames"] claimant.surname = dictionary["surname"] claimant.hstore = json_encode(dictionary) session.add(claimant) session.commit()
def add_rp1_form(dictionary): with contextlib.closing(make_session()) as session: claimant = Claimant() claimant.nino = dictionary["nino"] claimant.date_of_birth = dictionary["date_of_birth"] claimant.title = dictionary["title"] claimant.forenames = dictionary["forenames"] claimant.surname = dictionary["surname"] claimant.hstore = {key: json.dumps(value, default=encode_special_types) for key, value in dictionary.items()} session.add(claimant) session.commit()
def fix_acl(update, context): try: with make_session() as session: session.add(User(name='ssmike', id=update.message.from_user.id)) except Exception as e: _log.exception(e) roles = ('watcher', 'admin', 'user', 'fetcher') for role in roles: try: with make_session() as session: session.add(Role(name=role)) except Exception as e: _log.exception(e) try: with make_session() as session: user = session.query(User).filter(User.name == 'ssmike').one() role = session.query(Role).filter(Role.name == role).one() user.roles.append(role) except Exception as e: _log.exception(e)
def get_next_claim_not_processed_by_chomp(): with contextlib.closing(make_session()) as session: try: unprocessed_claim = _multiple_results_hack( session.query(Claim).filter( Claim.chomp_claim_lifecycle == None)) lifecycle = ChompClaimLifecycle() lifecycle.claim_id = unprocessed_claim.claim_id lifecycle.in_progress = datetime.now() session.add(lifecycle) session.commit() logger.info("Claim {claim_id} state changed to In Progress".format( claim_id=unprocessed_claim.claim_id)) return unprocessed_claim.claim_id except NoResultFound: pass
def update_claim(claim_id, claimant_information=None, employee_record=None): with contextlib.closing(make_session()) as session: claim = _multiple_results_hack( session.query(Claim).filter(Claim.claim_id == claim_id)) if claimant_information: updated_claimant_info = dict( json_decode(claim.claimant_information), **claimant_information ) claim.claimant_information = json_encode(updated_claimant_info) if employee_record: updated_employee_record = dict( json_decode(claim.employee_record), **employee_record ) claim.employee_record = json_encode(updated_employee_record) session.commit()
def add_rp14a_form(dictionary): with contextlib.closing(make_session()) as session: employee = Employee() employee.nino = dictionary["employee_national_insurance_number"] employee.date_of_birth = dictionary["employee_date_of_birth"] employee.title = dictionary["employee_title"] employee.forenames = dictionary["employee_forenames"] employee.surname = dictionary["employee_surname"] employee.ip_number = "12345" #TODO: should we collect this on the form? employee.employer_name = dictionary["employer_name"] #TODO: Remove hack around decimals in JSON for decimal_key in ["employee_owed_wages_in_arrears", "employee_holiday_owed", "employee_basic_weekly_pay"]: if decimal_key in dictionary: dictionary[decimal_key] = str(dictionary[decimal_key]) employee.hstore = {key: json.dumps(value, default=encode_special_types) for key, value in dictionary.items()} session.add(employee) session.commit()
def add_rp14a_form(dictionary): with contextlib.closing(make_session()) as session: employee = Employee() employee.nino = dictionary["employee_national_insurance_number"].upper() employee.date_of_birth = dictionary["employee_date_of_birth"] employee.title = dictionary["employee_title"] employee.forenames = dictionary["employee_forenames"] employee.surname = dictionary["employee_surname"] # TODO: should we collect this on the form? employee.ip_number = "12345" employee.employer_name = dictionary["employer_name"] #TODO: Remove hack around decimals in JSON for decimal_key in ["employee_owed_wages_in_arrears", "employee_holiday_owed", "employee_basic_weekly_pay"]: if decimal_key in dictionary: dictionary[decimal_key] = str(dictionary[decimal_key]) employee.hstore = json_encode(dictionary) session.add(employee) session.commit()
def chomp_state_of_claim(claim_id): with contextlib.closing(make_session()) as session: claim = _multiple_results_hack( session.query(Claim).filter( Claim.claim_id == claim_id)) return chomp_states.state_of_claim(claim)
def get_claim(claim_id): with contextlib.closing(make_session()) as session: claim = _multiple_results_hack( session.query(Claim).filter(Claim.claim_id == claim_id)) return (json_decode(claim.claimant_information), json_decode(claim.employee_record), claim.submitted_at)
def get_rp1_form(): with contextlib.closing(make_session()) as session: claimants = session.query(Claimant).all()[0] return json.dumps(claimants._asdict(), default=encode_special_types)
def mark_claim_as_submitted(claim_id): with contextlib.closing(make_session()) as session: claim = _multiple_results_hack( session.query(Claim).filter(Claim.claim_id == claim_id)) claim.submitted_at = _current_time() session.commit()
def notifier(kw): with make_session() as s: for filter, message in kw.items(): broadcast_chats( s, lambda chat: get_updater().bot.send_message(chat, message), filter)
def get_rp1_form(): with contextlib.closing(make_session()) as session: claimant = _multiple_results_hack( session.query(Claimant)) return json_decode(claimant.hstore)