Esempio n. 1
0
    def delete_availability(self, user, opening_id):
        if not user:

            return { "error": True}
        # TODO: MOAR PERMISSIONS.  ALL OF THE PERMISSIONS
        ScheduleAvailability.get(opening_id).delete()
        return{"success": True}
Esempio n. 2
0
 def get_schedule(self, user, business_id):
     if not user:
         return
     # TODO: not permissions...Just kidding, it IS permissions
     db = ScheduleAvailability.gql("WHERE business_id = :1", business_id)
     ret = gql_to_raw(db)
     return ret
Esempio n. 3
0
    def add_availability(self, user, business_id, day, start, end):
        if end < start:
            return {"error": "you can't end before you start"}

        if not user:

            return {"error": "F**K OFF CHEATY"}
        # TODO: make sure the user has authourity over the business

        new_availability = ScheduleAvailability(
            business_id = business_id,
            day = day,
            start_time = start,
            end_time = end
        )

        new_availability.put()
        return {"success": True}
Esempio n. 4
0
 def edit_availability(self, user, opening_id, day = None, start = None, end = None, **kwargs ):
     if end < start:
         return {"error": "You can't end before you start"}
     if not user:
         return {"error": "F**K OFF CHEATY"}
     oldie = ScheduleAvailability.get(opening_id)
     # TODO: PERMISSIONS, and null check
     if day: oldie.day = day
     if start: oldie.start_time = start
     if end: oldie.end_time = end
     oldie.put()
     return {"success": "yay"}
Esempio n. 5
0
    def get_availability(self, business_id, starting=None, until=None):
        # TODO: add a minimum appt length
        if not starting:
            starting = js_time()
        if not until:
            until = starting + (7*24*60*60*1000)

        available = ScheduleAvailability.gql("WHERE business_id = :1", business_id)
        booked = Booking.gql("WHERE business_id = :1", business_id)

        el_booking = NextMunger()
        el_available = NextMunger()

        for availability in available:
            el_available.add(WeeklyEvent(availability))
        for booking in booked:
            el_booking.add(SingleEvent(booking))

        ret_arr = []
        def maybe_append(el):
            # Just to make sure that we don't send tiny openings.
            # This will be better fixed in the future with better data integrity TODO: do that - AH
            # pulled this number out of what the bugs look like
            if el["end"] - el["start"] > 100000\
            and el["start"] < until:
                ret_arr.append(el)


        cursor = starting
        while cursor < until and el_available.next(cursor):
            next_available = el_available.next(cursor)
            next_book = el_booking.next(cursor)
            if next_book and next_book["start"]<next_available["start"]:
                cursor = next_book["end"] + 1 # + 1 is an extra ms just in case something broke with equal values in the algorithm
            elif next_book and next_book["start"] < next_available["end"]:
                augment = next_available
                augment["end"] = next_book["start"]
                if augment["end"] != augment["start"]:
                    maybe_append(augment)
                cursor = next_book["end"] + 1
            else:
                if next_available["end"] != next_available["start"]:
                    maybe_append(next_available)
                cursor = next_available["end"] + 1

        return ret_arr