Exemplo n.º 1
0
    def post(self):
        user_id = self.request.get('user_id')
        order_id = self.request.get('order_id')
        return_url = self.request.get('return_url')
        message = "Accepted invitation!"

        order = OrderUser.query_by_user_and_order(user_id, order_id)

        if (order is None):
            self.response.write(json.dumps({'status_code': -1}))
            message = "Request no longer exists."
        else:
            order.status_code = 2 #accept to be a candidate
            order.put()

            #generate notify
            order = Order.query_by_id(order_id)
            base = GetPath(self.request.url, self.request.path)
            notify = Notify(from_user="", to_user=order.owner_id, content=getAcceptCandidateMessage(), url=getInviteURL(base, order_id), status_code=1)
            notify.put()

            self.response.write(json.dumps({'status_code': 0}))

        if return_url:
            self.redirect(getAlertMessage(return_url, message))
Exemplo n.º 2
0
    def post(self):
        order_id = self.request.get('order_id')
        user_id = self.request.get('user_id') #tutor id
        self_applied = self.request.get('self_applied')
        return_url = self.request.get('return_url')
        message = 'Tutor is invited!'

        order = Order.query_by_id(order_id)
        if (order is not None) and (user_id is not None):
            #check if already invited
            existOrder = OrderUser.query_by_user_and_order(user_id, order_id)
            if existOrder is not None:
                self.response.write(json.dumps({'status_code': 0, 'message': 'already exists'}))
                if return_url:
                    self.redirect(getAlertMessage(return_url, "This tutor has already been invited!"))
                return

            #create an invitation
            invitation = OrderUser(user_id=user_id, order_id=order_id, \
                status_code=1, order_status=order.status_code)
            if (self_applied):
                invitation.status_code = 2
            else:
                #generate notify
                base = GetPath(self.request.url, self.request.path)
                notify = Notify(from_user="", to_user=user_id, content=getInviteMessage(), url=getInviteURL(base, order_id), status_code=1)
                notify.put()
            key = invitation.put()
            self.response.write(json.dumps({'status_code': 0, 'key': key.id()}))
        else:
            self.response.write(json.dumps({'status_code': -1}))
            message = "The post is no longer open!"

        if return_url:
            self.redirect(getAlertMessage(return_url, message))
Exemplo n.º 3
0
    def post(self):
        notify_id = self.request.get('notify_id')
        notify = Notify.query_by_id(notify_id)

        if (notify is not None and notify.status_code == 1):
            notify.status_code = 0
            notify.put()
        self.response.write(json.dumps({'status_code': 0}))
Exemplo n.º 4
0
    def get(self):
        to_user = self.request.get("user_id")
        notifys = Notify.query_by_to_user(to_user)

        if notifys is not None:
            newNotifys = [
                {"from_user": no.from_user, "content": no.content, "notify_id": no.key.id(), "url": no.url}
                for no in notifys
                if no.status_code == 1
            ]
            self.response.write(json.dumps(newNotifys))
        else:
            self.response.write(json.dumps([]))
Exemplo n.º 5
0
    def post(self):
        user_id = self.request.get('user_id') #tutor id
        order_id = self.request.get('order_id')
        return_url = self.request.get('return_url')
        order = OrderUser.query_by_user_and_order(user_id, order_id)
        message = "Accepted tutor!"

        if (order is None or order.status_code != 2):
            self.response.write(json.dumps({'status_code': -1}))
            message = "Request no longer exists."
        else:
            order.status_code = 3 #accept the tutor
            order.put()

            #generate notify
            base = GetPath(self.request.url, self.request.path)
            notify = Notify(from_user="", to_user=user_id, content=getAcceptTutorMessage(), url=getInviteURL(base, order_id), status_code=1)
            notify.put()
            self.response.write(json.dumps({'status_code': 0}))

        if return_url:
            self.redirect(getAlertMessage(return_url, message))