コード例 #1
0
ファイル: test_notes_model.py プロジェクト: bjdm/la-ayudante
def test_remove_header_with_multiple_line_note():
    test_note = Note(
        "# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.\nSome other notes.")
    assert test_note.remove_header() == "Some notes.\nSome other notes."
コード例 #2
0
ファイル: test_notes_model.py プロジェクト: bjdm/la-ayudante
def test_remove_header_with_note():
    test_note = Note("# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.")
    assert test_note.remove_header() == 'Some notes.'
コード例 #3
0
ファイル: test_notes_model.py プロジェクト: bjdm/la-ayudante
def test_remove_header_only_next_string():
    test_note = Note("# Next: T1@7:45PM")
    assert test_note.remove_header() == None
コード例 #4
0
ファイル: test_notes_model.py プロジェクト: bjdm/la-ayudante
def test_remove_header_only_out_string():
    test_note = Note("# Out @ 7:45PM")
    assert test_note.remove_header() == None
コード例 #5
0
ファイル: test_notes_model.py プロジェクト: bjdm/la-ayudante
def test_remove_header_no_current_note():
    test_note = Note(None)
    assert test_note.remove_header() == None
コード例 #6
0
ファイル: reservation.py プロジェクト: bjdm/la-ayudante
class Reservation:
    def __init__(self, id, start_time, notes, table_ids, json):
        self.id = id
        self.start_time = start_time
        self.notes = Note(notes)
        self.json = json
        self.tables = []
        for table_id in table_ids:
            t = Table.get_table_by_id(table_id)
            self.tables.append(t)
            t.add_reservation(self)

    def update_time_notes(self, setup_minutes=5):
        """ Add notes
        Sort out different cases
        """
        # TODO: change this. I want to calculate out_time by getting the
        # generate out string and next string
        #out_time = datetime.DateTime
        next_reservations = self.get_next_reservations()
        if len(next_reservations) < 1:
            # There are no reservations after -> remove the note header if it
            # exists and exit early
            self.notes.remove_header()
            return
        elif len(next_reservations) == 1:
            if len(self.tables) > 1:
                # the current reservation uses more than one table. allow
                # setup_minutes minutes for setup
                out_time = next_reservations[0].start_time - timedelta(
                    minutes=setup_minutes)
            else:
                out_time = next_reservations[0].start_time
        elif len(next_reservations) > 1:
            if len(self.tables) > 1:
                # more than one of the tables being used by this reservation is
                # required for a proceeding reservation. allow setup_minutes
                # minutes for setup from the EARLIEST next_reservation
                out_time = min(next_reservations, key=lambda r: r.start_time
                               ).start_time - timedelta(minutes=setup_minutes)
            else:
                # the current table is part of a reservation using multiple
                # tables. allow setup_minutes minutes for setup
                out_time = next_reservations[0].start_time - timedelta(
                    minutes=setup_minutes)
        else:
            out_time = next_reservations[0].start_time

        self.notes.generate_note(out_time,
                                 (([table.number
                                    for table in res.tables], res.start_time)
                                  for res in next_reservations))

    def get_next_reservations(self):
        # TODO: only returns 1 reservation if the start_time's are the same. is
        # this the best way to handle this?
        return [
            table.get_reservation_after(self.start_time)
            for table in self.tables
            if table.get_reservation_after(self.start_time)
        ]