Example #1
0
    def add_booking_code(self, user, business_id, start, end, user_with):
        if user_with:
            # Make sure they are allowed to propose to this user
            if not business.user_owns_business(user.user_id(), business_id):
                return {"error": "not your business bro"}
            user_with = CoUser.get(user_with)
            if not user_with:
                return {"error":"that guy does not exist"}

            interaction = InteractionRecord.gql("WHERE business_id = :1 AND user = :2", business_id, user_with).get()

            if not interaction:
                return {"error":"You have no reason to talk to that user"}
            user = user_with
            contractor = True
            client = False
        else:
            contractor = False
            client = True
            need_to_create_this = InteractionRecord.guaranteed_get(business_id, user)

        new_booking = Booking(
            user = user,
            business_id = business_id,
            start_time = start,
            end_time = end,
            approved_by_customer = client,
            approved_by_contractor = contractor
        )
        new_booking.put()

        send_emails.booking_created(user, business_id, start, end, user_with)

        return new_booking
Example #2
0
def send_message_code(user, business_id, message, user_id):
    recv_user = None
    if user_id:
        if not business.user_owns_business(user.user_id(), business_id):
            return {"error": "You don't own that business"}
        recv_user = CoUser.get(user_id)
        if not recv_user:
            return {"error": "no such user"}
        interaction = InteractionRecord.gql("WHERE business_id = :1 AND user = :2", business_id, recv_user).get()
        if not interaction:
            return {"error": "no reason to talk to that person"}
        contractor = True
    else:
        interaction = InteractionRecord.guaranteed_get(business_id, user)
        contractor = False
    senderoo = Solicitation(
        interaction = interaction,
        from_contractor = contractor,
        when = js_time(),
        message = message
    )

    senderoo.put()

    send_emails.message_recieved(user, business_id,recv_user, message)

    return model_to_dict(senderoo)
Example #3
0
    def get_messages(self, user, business_id, user_id = None):
        if user_id:
            if not business.user_owns_business(user.user_id(), business_id):
                return {"error": "You do not own that business"}
            user = CoUser.get(user_id)
            if not user:
                return {"error": "What are you doing?"}

        interaction = InteractionRecord.gql("WHERE business_id = :1 AND user = :2", business_id, user).get()
        if not interaction:
            return []
        messages = Solicitation.gql("WHERE interaction = :1 ORDER BY when", interaction)
        return gql_to_raw(messages)
Example #4
0
    def get_bookings(self, user, business_id, user_id=None):
        # My intuition tells me that this is bad design
        # My laziness told it to shut up
        if user_id:
            if not business.user_owns_business(user.user_id(), business_id):
                return {"error": "You don't own that business"}

            # At this point, permissions are good
            user = CoUser.get(user_id)

        if not user:
            return []

        bookings = Booking.gql("WHERE user = :1 AND business_id = :2", user, business_id)
        return gql_to_raw(bookings)
Example #5
0
 def check_for_user_or_create_session(self, user, *args, **kwargs):
     if not user:
         # Create session
         sess = gaesessions.get_current_session()
         user_id = sess.get("user_id", None)
         if user_id == None:
             new_user = CoUser()
             new_user.put()
             sess["user_id"] = new_user.user_id()
             return fn(self, user=new_user, *args, **kwargs)
         else:
             old_user = CoUser.get(user_id)
             return fn(self, user=old_user, *args, **kwargs)
     else:
         return fn(self, user=user, *args, **kwargs)