コード例 #1
0
 def from_frontend(cls, frontend_data: Dict):
     receiver_list = [(Member.from_frontend(receiver_dict['receiver']),
                       receiver_dict['burden'])
                      for receiver_dict in frontend_data['receiverList']]
     return PeriodicFlow(
         amount_payed=frontend_data['amountPayed'],
         period=frontend_data['period'],
         pay_day=frontend_data['payDay'],
         last_payed=date_from_iso_format(frontend_data['lastPayed']),
         issuer=Member.from_frontend(frontend_data['issuer']),
         receiver_list=receiver_list,
         is_update_automatic=frontend_data['isUpdateAutomatic'])
コード例 #2
0
def add_member_data(member: Member, group_name: str):
    data_path = get_members_data_file_path(group_name)
    # Determine if file will be opened with "append" or "write", depending if file already exists or not.
    open_mode = _get_open_mode(data_path)
    # Edit file (writing or appending)
    with open(data_path, open_mode) as data_file:
        writer = csv.writer(data_file)
        writer.writerow(member.to_database())
コード例 #3
0
def modify_members_data(member: Member, id_: int, group_name: str):
    member_list = get_members_data(group_name)
    member_list[id_] = member

    with open(get_members_data_file_path(group_name), 'w') as data_file:
        writer = csv.writer(data_file)
        for member in member_list:
            writer.writerow(member.to_database())
コード例 #4
0
async def update_member(request: web.Request) -> web.Response:
    token = request.rel_url.query['token']

    # Checking if member is locked.
    if is_locked(token):
        return web.Response(status=200, )

    # Extracting inputs from frontend.
    group_name = request.rel_url.query['group_name']
    fronted_data = Member.pre_process_request(request)
    id_str = request.rel_url.query['id']
    id_ = int(id_str)

    # Transforming member input from type "dict" to type "Member".
    member = Member.from_frontend(frontend_data=fronted_data)

    # Modifying member data.
    modify_members_data(member, id_, group_name)

    return web.Response(status=201, body="Member updated successfully.")
コード例 #5
0
async def add_member(request: web.Request) -> web.Response:
    token = request.rel_url.query['token']

    # Checking if member is locked.
    if is_locked(token):
        return web.Response(
            status=200,
            body=
            "Another person is using the app, sorry. You cannot modify stuff.")

    # Extracting inputs from frontend.
    group_name = request.rel_url.query['group_name']
    fronted_data = Member.pre_process_request(request)

    # Transforming member input from type "dict" to type "Member".
    member = Member.from_frontend(frontend_data=fronted_data)

    # Adding inputs from frontend into database.
    add_member_data(member, group_name)
    return web.Response(status=201, body="Member added successfully.")
コード例 #6
0
def get_members_data(group_name: str) -> List[Member]:
    member_list: List[Member] = []

    with open(get_members_data_file_path(group_name), 'r') as data_file:
        reader = csv.reader(data_file)
        for row in reader:
            if len(row) == 0:
                continue
            member_list.append(Member.from_database(row))

    return member_list
コード例 #7
0
ファイル: flow.py プロジェクト: PraderioM/debtManager
 def from_frontend(cls, frontend_data: Dict) -> 'Flow':
     return Flow(issuer=Member.from_frontend(frontend_data['issuer']),
                 receiver=Member.from_frontend(frontend_data['receiver']),
                 amount=frontend_data['amount'],
                 concept=frontend_data['concept'],
                 date=date_from_iso_format(frontend_data['date']))
コード例 #8
0
def get_member_by_name(name: str, member_list: List[Member]) -> Member:
    for member in member_list:
        if name == member.name:
            return member

    return Member(name=name, e_mail=None)