def get(self):
        user_id = self.request.get('user_id')
        orders = []

        if user_id is not None:
            #each subject pick up 5 orders. then randomly choose 5 from the set
            subjects = TutorSubject.query_by_tutor_id(user_id)
            for s in subjects:
                ods = Order.query_by_subject(str(s.subject))
                for od in ods:
                    userinfo = UserInfo.query_by_id(od.owner_id)
                    if userinfo:
                        orders.append({'subject': od.subject, 'title': od.title, \
                                    'comment': od.comment, 'status_code': od.status_code,\
                                    'order_id': od.key.id(), 'user_id': od.owner_id, 'name': userinfo.name,\
                                    'picture': getPictureURL(str(userinfo.picture))})
        if orders == []:
            #randomly pick up
            ods = Order.query()
            for od in ods:
                userinfo = UserInfo.query_by_id(od.owner_id)
                if userinfo:
                    orders.append({'subject': od.subject, 'title': od.title, \
                                'comment': od.comment, 'status_code': od.status_code,\
                                'order_id': od.key.id(), 'user_id': od.owner_id, 'name': userinfo.name,\
                                'picture': getPictureURL(str(userinfo.picture))})
        random.shuffle(orders)
        recommendOrders = orders[:5]
        self.response.write(json.dumps(recommendOrders))
Esempio n. 2
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))
Esempio n. 3
0
    def post(self):
        owner_id = users.get_current_user().user_id()
        subject = self.request.get('subject')
        title = self.request.get('title')
        comment = self.request.get('comment')
        return_url = self.request.get('return_url')

        order = Order(owner_id=owner_id, subject=subject, title=title, \
                    comment=comment, status_code=1)
        key = order.put()

        self.response.write(json.dumps({'status_code': 0, 'key': key.id()}))
        if return_url:
            self.redirect(getAlertMessage(return_url, "A new post is created!"))
        else:
            self.redirect('/')
Esempio n. 4
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))
Esempio n. 5
0
    def get(self):
        user_id = self.request.get('user_id')
        orders = Order.query_by_owner_id(user_id)

        if orders is None:
            self.response.write(json.dumps([]))
        else:
            myOrders = [{'subject': od.subject, 'title': od.title, \
                        'comment': od.comment, 'status_code': od.status_code,\
                        'order_id': od.key.id(),\
                        } for od in orders]
            self.response.write(json.dumps(myOrders))
Esempio n. 6
0
    def get(self):
        query = self.request.get('query')
        orders = Order.query_by_subject(query)

        if orders is None:
            self.response.write(json.dumps([]))
        else:
            myOrders = []
            for od in orders:
                userinfo = UserInfo.query_by_id(od.owner_id)
                if userinfo:
                    myOrders.append({'subject': od.subject, 'title': od.title, \
                                'comment': od.comment, 'status_code': od.status_code,\
                                'order_id': od.key.id(), 'user_id': od.owner_id, 'name': userinfo.name,\
                                'picture': getPictureURL(str(userinfo.picture))})

            self.response.write(json.dumps(myOrders))
Esempio n. 7
0
    def post(self):
        order_id = self.request.get('order_id') #tutor id
        user_id = self.request.get('user_id')
        return_url = self.request.get('return_url')
        message = "Application deleted!"

        order = Order.query_by_id(order_id)
        if order is not None:
            #check if already invited
            existOrder = OrderUser.query_by_user_and_order(user_id, order_id)
            if existOrder is not None:
                existOrder.key.delete()
                self.response.write(json.dumps({'status_code': 0}))
        else:
            self.response.write(json.dumps({'status_code': 1}))
            message = "No such application!"

        if return_url:
            self.redirect(getAlertMessage(return_url, message))
 def getOrderByID(self, order_id):
     return Order(self.orderRepository.getOrderByID(order_id))
 def getOrdersByCustomer(self, customer_id):
     return [ Order(orderInfo) for orderInfo in self.orderRepository.getOrdersByCustomer(customer_id) ]