Ejemplo n.º 1
0
    def get(self):
        user = users.get_current_user()
        if not user:
            self.response.out.write('ERROR: NO USER')
            return

        object_type = self.request.get("object_type")
        if object_type == "client":
            name = self.request.get('name')
            comment = self.request.get('comment')
            data.addClient(name, comment)
            self.response.out.write('OK')
            return
        elif object_type == "service":
            name = self.request.get('name')
            active = self.request.get('active')
            key = data.addService(name, active)
            self.response.out.write({key: key})
            return
        elif object_type == "assist":
            email = self.request.get('email')
            key = data.addAssistant(email)
            self.response.out.write('OK')
            return

        self.response.out.write('ERROR: UNSUPPORTED OBJECT')
Ejemplo n.º 2
0
    def get(self):
        user = users.get_current_user()
        if not user:
            self.response.out.write('ERROR: NO USER')
            return  

        object_type = self.request.get("object_type")
        if object_type == "client":
            name = self.request.get('name')
            comment = self.request.get('comment')
            data.addClient(name, comment)
            self.response.out.write('OK')
            return

        self.response.out.write('ERROR: UNSUPPORTED OBJECT')
Ejemplo n.º 3
0
    def post(self):
        user = users.get_current_user()
        if not user:
            self.response.out.write('ERROR: NO USER')
            return

        object_type = self.request.get("object_type")
        if object_type == "client":
            name = self.request.get('name')
            comment = self.request.get('comment')
            data.addClient(name, comment)
            self.response.out.write('OK')
            return
        elif object_type == "service":
            name = self.request.get('name')
            active = self.request.get('active') == "True"
            key = data.addService(name, active)
            self.response.out.write(str(key))
            return
        elif object_type == "client_service":
            key = self.request.get('service_key')
            comment = self.request.get('comment')
            newKey = data.addClientService(key, comment, user.user_id())
            if newKey == "":
                self.error(500)
                return
            self.response.out.write(str(newKey))
            return
        elif object_type == "offer_service":
            name = self.request.get('name')
            user_comment = self.request.get('user_comment')
            user_id = user.user_id()
            newKey = data.add_offer(user_id, name, user_comment)
            self.response.out.write(str(newKey))
            return
        elif object_type == "user_event":
            client_key = self.request.get('client_key')
            comment = self.request.get('comment')
            user_id = user.user_id()
            event_date = datetime.datetime(self.request.get('event_date'))
            duration = int(self.request.get('duration'))
            newKey = addUserEvent(client_key, comment, user_id, event_date,
                                  duration)
            self.response.out.write(str(newKey))
            return

        self.response.out.write('ERROR: UNSUPPORTED OBJECT')
Ejemplo n.º 4
0
    def post(self):
        user = users.get_current_user()
        events = data.getUserEvents(user.user_id())
        if not user:
            self.response.out.write('ERROR: NO USER')
            return

        object_type = self.request.get("object_type")
        if object_type == "client":
            name = self.request.get('name')
            comment = self.request.get('comment')
            data.addClient(name, comment)
            self.response.out.write('OK')
            return
        elif object_type == "service":
            name = self.request.get('name')
            active = self.request.get('active') == "True"
            key = data.addService(name, active)
            self.response.out.write(str(key))
            return
        elif object_type == "client_service":
            key = self.request.get('service_key')
            comment = self.request.get('comment')
            newKey = data.addClientService(key, comment, user.user_id())
            if newKey == "":
                self.error(500)
                return
            self.response.out.write(str(newKey))
            return
        elif object_type == "offer_service":
            name = self.request.get('name')
            user_comment = self.request.get('user_comment')
            user_id = user.user_id()
            newKey = data.add_offer(user_id, name, user_comment)
            self.response.out.write(str(newKey))
            return
        elif object_type == "user_event":
            client_key = self.request.get('client_key')
            comment = self.request.get('comment')
            user_id = user.user_id()
            event_date = datetime.datetime.strptime(
                self.request.get('event_date'), "%Y-%m-%d")
            event_time = datetime.datetime.strptime(
                self.request.get('event_time'), "%H:%M")
            duration = int(self.request.get('duration'))
            for an_event in events:
                moment = event_date
                moment = moment.replace(hour=event_time.hour)
                moment = moment.replace(minute=event_time.minute)
                engaged = an_event.event_date
                engaged = engaged.replace(hour=an_event.event_time.hour)
                engaged = engaged.replace(minute=an_event.event_time.minute)
                delta = moment - engaged
                moment_dur = datetime.timedelta(minutes=duration)
                engaged_dur = datetime.timedelta(minutes=an_event.duration)
                if delta > datetime.timedelta(days=0, hours=0, minutes=0):
                    if delta < engaged_dur:
                        newKey = 10 / 0
                if delta < datetime.timedelta(days=0, hours=0, minutes=0):
                    if -delta < moment_dur:
                        newKey = 10 / 0
            newKey = data.addUserEvent(client_key, comment, user_id,
                                       event_date, event_time, duration)
            self.response.out.write(str(newKey))
            return
        elif object_type == "assist":
            email = self.request.get('email')
            key = data.addAssistant(email)
            self.response.out.write('OK')
            return

        self.response.out.write('ERROR: UNSUPPORTED OBJECT')