示例#1
0
    def get(self):

        # req_json = json.loads(self.request.body)
        # expense_name = req_json[IDENTIFIER_EXPENSE_NAME]
        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)

        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        # new_sharer_email = req_json[IDENTIFIER_NEW_EMAIL]
        new_sharer_email = self.request.get(IDENTIFIER_NEW_EMAIL)

        target_expense = None

        expense_lst = Expense.query(Expense.expense_name == expense_name)

        for expense in expense_lst:
            if user_email in expense.user_email_lst:
                target_expense = expense
                break

        if target_expense == None:
            response = {}
            response[
                'error'] = 'the expense: ' + expense_name + ' has not been created'
            return self.respond(**response)

        if not new_sharer_email in target_expense.user_email_lst:
            target_expense.user_email_lst.insert(0, new_sharer_email)

        target_expense.put()

        self.respond(expense_id=target_expense.expense_id,
                     new_user=new_sharer_email,
                     status="Success")
示例#2
0
def expenses():
    try:
        jdata = request.get_json(force=True)
        name = jdata['name']
        email = jdata['email']
        category = jdata['category']
        description = jdata['description']
        link = jdata['link']
        status = 'Pending'  #jdata['status']
        estimated_costs = jdata['estimated_costs']
        submit_date = jdata['submit_date']
        decision_date = ' '  #jdata['decision_date']
        expense = Expense(name, email, category, description, link, status,
                          estimated_costs, submit_date, decision_date)
        db.session.add(expense)
        db.session.commit()
        return Response(response=json.dumps({
            "id": expense.id,
            "name": name,
            "email": email,
            "category": category,
            "description": description,
            "link": link,
            "status": status,
            "estimated_costs": estimated_costs,
            "submit_date": submit_date,
            "decision_date": decision_date
        }),
                        status=201,
                        mimetype='application/json')
    except IntegrityError:
        return Response(status=400)
示例#3
0
    def get(self):
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()
        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt
        if cur_apt == None:
            response = {}
            response[
                'error'] = 'the apt: ' + apt_name + ' is not available for user: ' + user_email
            return self.respond(**response)

        for expense_id in cur_apt.expense_id_lst:
            expense_lst = Expense.query(
                Expense.expense_id == expense_id).fetch()
            if len(expense_lst) > 0:
                expense = expense_lst[0]
                if not expense.is_paid:
                    expense.checkout()
                    cur_apt.total_cost += expense.total_cost
                    cur_apt.put()

        self.respond(status="Success")
示例#4
0
    def get(self):

        cover_url = None
        # if IDENTIFIER_ITEM_PHOTO in req_json:
        #     cover_url = req_json[IDENTIFIER_ITEM_PHOTO]

        item_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)

        # item_name = req_json[IDENTIFIER_ITEM_NAME]
        item_name = self.request.get(IDENTIFIER_ITEM_NAME)

        # expense_name = req_json[IDENTIFIER_EXPENSE_NAME]
        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)

        # buyer_email = req_json[IDENTIFIER_BUYER_EMAIL]
        buyer_email = self.request.get(IDENTIFIER_BUYER_EMAIL)

        # sharer_email_lst = req_json[IDENTIFIER_SHARER_LIST]
        sharer_emails = self.request.get(IDENTIFIER_SHARER_LIST)
        sharer_email_lst = sharer_emails.split(",")

        expense_lst = Expense.query(Expense.expense_name == expense_name)
        expense_id = None

        # total_cost = float(req_json[IDENTIFIER_TOTAL_COST])
        cost = self.request.get(IDENTIFIER_TOTAL_COST)
        total_cost = float(cost)


        target_expense = None


        for expense in expense_lst:
            if buyer_email in expense.user_email_lst:
                expense_id = expense.expense_id
                target_expense = expense
                break

        if expense_id == None:
            response = {}
            response['error'] = 'the buyer email: ' + buyer_email + ' is not valid for this expense/apartment'
            return self.respond(**response)

        new_item = Item(item_id = str(item_id),
                        item_name = item_name,
                        cover_url = cover_url,
                        expense_id = expense_id,
                        buyer_email = buyer_email,
                        sharer_email_lst = sharer_email_lst,
                        total_cost = total_cost
                        )
        new_item.put()
        target_expense.item_id_lst.insert(0, str(item_id))
        target_expense.put()


        self.respond(item_id_id = str(item_id), status="Success")
示例#5
0
    def get(self):

        cover_url = None
        # if IDENTIFIER_ITEM_PHOTO in req_json:
        #     cover_url = req_json[IDENTIFIER_ITEM_PHOTO]

        item_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)

        # item_name = req_json[IDENTIFIER_ITEM_NAME]
        item_name = self.request.get(IDENTIFIER_ITEM_NAME)

        # expense_name = req_json[IDENTIFIER_EXPENSE_NAME]
        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)

        # buyer_email = req_json[IDENTIFIER_BUYER_EMAIL]
        buyer_email = self.request.get(IDENTIFIER_BUYER_EMAIL)

        # sharer_email_lst = req_json[IDENTIFIER_SHARER_LIST]
        sharer_emails = self.request.get(IDENTIFIER_SHARER_LIST)
        sharer_email_lst = sharer_emails.split(",")

        expense_lst = Expense.query(Expense.expense_name == expense_name)
        expense_id = None

        # total_cost = float(req_json[IDENTIFIER_TOTAL_COST])
        cost = self.request.get(IDENTIFIER_TOTAL_COST)
        total_cost = float(cost)

        target_expense = None

        for expense in expense_lst:
            if buyer_email in expense.user_email_lst:
                expense_id = expense.expense_id
                target_expense = expense
                break

        if expense_id == None:
            response = {}
            response[
                'error'] = 'the buyer email: ' + buyer_email + ' is not valid for this expense/apartment'
            return self.respond(**response)

        new_item = Item(item_id=str(item_id),
                        item_name=item_name,
                        cover_url=cover_url,
                        expense_id=expense_id,
                        buyer_email=buyer_email,
                        sharer_email_lst=sharer_email_lst,
                        total_cost=total_cost)
        new_item.put()
        target_expense.item_id_lst.insert(0, str(item_id))
        target_expense.put()

        self.respond(item_id_id=str(item_id), status="Success")
示例#6
0
    def get(self):
        print("get finish task request")

        task_id = self.request.get(IDENTIFIER_TASK_ID)
        total_cost = self.request.get(IDENTIFIER_TOTAL_COST)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        total_cost = float(total_cost)
        print("get cost " + str(total_cost))

        tasks = Task.query(Task.task_id == task_id).fetch()
        task = tasks[0]

        print("Found the task " + task.task_name)

        if task.finished:
            response = {}
            response['error'] = 'the task has already been finished'
            return self.respond(**response)
        if user_email != task.charger_email:
            response = {}
            response['error'] = 'the task has been assigned to other roommate'
            return self.respond(**response)
        task.finished = True
        task.put()
        item_id = str(uuid.uuid4())
        sharer_lst = task.candidate_lst
        # sharer_lst.remove(task.charger_email)   # newly removed this line

        print("creating item ")

        new_Item = Item(item_id=item_id,
                        cover_url=str(task.photo_blobkey),
                        expense_id=task.expense_id,
                        total_cost=total_cost,
                        buyer_email=task.charger_email,
                        sharer_email_lst=sharer_lst,
                        item_name=task.task_name)
        new_Item.put()

        expenses = Expense.query(Expense.expense_id == task.expense_id).fetch()
        if len(expenses) == 0:
            print("cannot find the expense")
        else:
            expense = expenses[0]
            item_ids = expense.item_id_lst
            item_ids.append(item_id)
            expense.item_id_lst = item_ids
            expense.put()
            print("done ")

        self.respond(item_name=task.task_name,
                     item_id=task.task_id,
                     status="Success")
示例#7
0
    def get(self):

        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt

        if cur_apt == None:
            response = {}
            response[
                'error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'the apt: ' + apt_name + ' does not have a expense named: ' + expense_name
            return self.respond(**response)
        if cur_expense.is_paid:
            response = {}
            response[
                'error'] = 'the : ' + expense_name + ' has already been paid'
            return self.respond(**response)
        cur_expense.checkout()
        cur_apt.total_cost += cur_expense.total_cost
        cur_apt.put()

        user_info_lst = []
        for user_email in cur_apt.user_email_lst:
            users = User.query(User.user_email == user_email).fetch()
            user = users[0]
            user_info = {}
            user_info['email:'] = user_email
            user_info['nick_name'] = user.nick_name
            user_info['owe'] = user.cost
            user_info['owed'] = user.borrow
            user_info['balance'] = user.owe
            user_info_lst.append(user_info)

        self.respond(user_info_lst=user_info_lst, status="Success")
示例#8
0
    def Get(self):
        _result = []
        cars = Car.all(Car.owner==self.user, key=self.rootKey()).fetch()
        for car in cars:
            _car = car.json()
            _car['expenses'] = []
            for _exp in Expense.all(key=ndb.Key(Car, car.key.id())).fetch():
                _car['expenses'].append(_exp.json())
            _result.append(_car)

        self.response.headers['Content-Type'] = "application/force-download; charset=utf-8"
        self.response.headers['Content-Disposition'] = 'attachment; filename="car-expenses-%s.json"' % str(datetime.now())[:10]
        self.response.write(json.dumps(_result))
示例#9
0
    def get(self):

        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt

        if cur_apt == None:
            response = {}
            response['error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'the apt: ' + apt_name + ' does not have a expense named: ' + expense_name
            return self.respond(**response)
        if cur_expense.is_paid:
            response = {}
            response['error'] = 'the : ' + expense_name + ' has already been paid'
            return self.respond(**response)
        cur_expense.checkout()
        cur_apt.total_cost += cur_expense.total_cost
        cur_apt.put()


        user_info_lst = []
        for user_email in cur_apt.user_email_lst:
            users = User.query(User.user_email == user_email).fetch()
            user = users[0]
            user_info = {}
            user_info['email:'] = user_email
            user_info['nick_name'] = user.nick_name
            user_info['owe'] = user.cost
            user_info['owed'] = user.borrow
            user_info['balance'] = user.owe
            user_info_lst.append(user_info)



        self.respond(user_info_lst = user_info_lst, status="Success")
示例#10
0
    def get(self):

        apt_id = self.request.get(IDENTIFIER_APT_ID)
        target_apt_lst = Apartment.query(Apartment.apt_id == apt_id).fetch()
        if len(target_apt_lst) != 1:
            print "target_apt_lst length error:" + str(len(target_apt_lst))
        query_apt = target_apt_lst[0]

        expense_id_lst = query_apt.expense_id_lst
        print "expense_id_lst length:" + str(len(expense_id_lst))

        unassigned_tasks_lst = []
        assigned_tasks_lst = []
        finished_tasks_lst = []

        for expense_id in expense_id_lst:
            # expense_id = self.request.get(IDENTIFIER_EXPENSE_ID)
            expenses = Expense.query(Expense.expense_id == expense_id).fetch()
            if len(expenses) == 0:
                continue
            expense = expenses[0]

            tasks = expense.getAllTasks()

            for task in tasks:
                cur_task = {}
                cur_task['photo_blobkey'] = str(task.photo_blobkey)
                cur_task['creator_nickname'] = task.getCreaterNickName()
                cur_task['creator_email'] = task.creater_email
                cur_task['task_name'] = task.task_name
                cur_task['description'] = task.description
                cur_task['task_id'] = str(task.task_id)
                cur_task['expense_id'] = str(task.expense_id)
                cur_task['candidate_lst_str'] = task.getCandidateListString()
                if task.assigned:
                    cur_task['charger_name'] = task.getChargerNickName()
                    cur_task['charger_email'] = task.charger_email
                    if task.finished:
                        finished_tasks_lst.append(cur_task)
                    else:
                        assigned_tasks_lst.append(cur_task)
                else:
                    unassigned_tasks_lst.append(cur_task)

        task_info = {}
        task_info['finished_tasks_lst'] = finished_tasks_lst
        task_info['unassigned_tasks_lst'] = unassigned_tasks_lst
        task_info['assigned_tasks_lst'] = assigned_tasks_lst

        self.respond(task_info=task_info, status="Success")
示例#11
0
    def get(self):

        apt_id = self.request.get(IDENTIFIER_APT_ID)
        target_apt_lst = Apartment.query(Apartment.apt_id == apt_id).fetch()
        if len(target_apt_lst)!=1:
            print "target_apt_lst length error:" + str(len(target_apt_lst))
        query_apt = target_apt_lst[0]

        expense_id_lst = query_apt.expense_id_lst
        print "expense_id_lst length:" + str(len(expense_id_lst))

        unassigned_tasks_lst = []
        assigned_tasks_lst = []
        finished_tasks_lst = []

        for expense_id in expense_id_lst:
            # expense_id = self.request.get(IDENTIFIER_EXPENSE_ID)
            expenses = Expense.query(Expense.expense_id == expense_id).fetch()
            if len(expenses) == 0:
                continue
            expense = expenses[0]

            tasks = expense.getAllTasks()

            for task in tasks:
                cur_task = {}
                cur_task['photo_blobkey'] = str(task.photo_blobkey)
                cur_task['creator_nickname'] = task.getCreaterNickName()
                cur_task['creator_email'] = task.creater_email
                cur_task['task_name'] = task.task_name
                cur_task['description'] = task.description
                cur_task['task_id'] = str(task.task_id)
                cur_task['expense_id'] = str(task.expense_id)
                cur_task['candidate_lst_str'] = task.getCandidateListString()
                if task.assigned:
                    cur_task['charger_name'] = task.getChargerNickName()
                    cur_task['charger_email'] = task.charger_email
                    if task.finished:
                        finished_tasks_lst.append(cur_task)
                    else:
                        assigned_tasks_lst.append(cur_task)
                else:
                    unassigned_tasks_lst.append(cur_task)

        task_info = {}
        task_info['finished_tasks_lst'] = finished_tasks_lst
        task_info['unassigned_tasks_lst'] = unassigned_tasks_lst
        task_info['assigned_tasks_lst'] = assigned_tasks_lst

        self.respond(task_info=task_info, status="Success")
示例#12
0
    def get(self):
        print("get finish task request")

        task_id = self.request.get(IDENTIFIER_TASK_ID)
        total_cost = self.request.get(IDENTIFIER_TOTAL_COST)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        total_cost = float(total_cost)
        print("get cost " + str(total_cost))

        tasks = Task.query(Task.task_id == task_id).fetch()
        task = tasks[0]

        print("Found the task " + task.task_name)

        if task.finished:
            response = {}
            response['error'] = 'the task has already been finished'
            return self.respond(**response)
        if user_email != task.charger_email:
            response = {}
            response['error'] = 'the task has been assigned to other roommate'
            return self.respond(**response)
        task.finished = True
        task.put()
        item_id = str(uuid.uuid4())
        sharer_lst = task.candidate_lst
        # sharer_lst.remove(task.charger_email)   # newly removed this line

        print("creating item ")

        new_Item = Item(item_id = item_id, cover_url = str(task.photo_blobkey), expense_id = task.expense_id,
                        total_cost = total_cost,
                        buyer_email = task.charger_email,
                        sharer_email_lst = sharer_lst,
                        item_name = task.task_name)
        new_Item.put()

        expenses = Expense.query(Expense.expense_id == task.expense_id).fetch()
        if len(expenses) == 0:
            print("cannot find the expense");
        else:
            expense = expenses[0]
            item_ids = expense.item_id_lst
            item_ids.append(item_id)
            expense.item_id_lst = item_ids
            expense.put()
            print("done ")

        self.respond(item_name = task.task_name, item_id = task.task_id, status="Success")
示例#13
0
def savemsg():

    if request.method == "POST":
        msg = request.form.get('Body')
        date = str(datetime.now()).split()[0]
        msg_parsed = msg.split()
        amount = msg_parsed[0]
        category = msg_parsed[1]
        description = ' '.join(msg_parsed[2:])
        expense = Expense(date=date,
                          amount=amount,
                          category=category,
                          description=description)
        db.session.add(expense)
        db.session.commit()

    return 'Testing newmsg app route'
示例#14
0
    def get(self):

        # req_json = json.loads(self.request.body)
        # expense_name = req_json[IDENTIFIER_EXPENSE_NAME]
        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)

        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)


        # new_sharer_email = req_json[IDENTIFIER_NEW_EMAIL]
        new_sharer_email = self.request.get(IDENTIFIER_NEW_EMAIL)



        target_expense = None

        expense_lst = Expense.query(Expense.expense_name == expense_name)

        for expense in expense_lst:
            if user_email in expense.user_email_lst:
                target_expense = expense
                break

        if target_expense == None:
            response = {}
            response['error'] = 'the expense: ' + expense_name + ' has not been created'
            return self.respond(**response)



        if not new_sharer_email in target_expense.user_email_lst:
            target_expense.user_email_lst.insert(0, new_sharer_email)

        target_expense.put()

        self.respond(expense_id = target_expense.expense_id,
                     new_user = new_sharer_email, status="Success")
示例#15
0
    def Post(self, car_id, expense_id = None):
        if expense_id:
            _expense = ndb.Key(Car, int(car_id), Expense, int(expense_id)).get()
        else:
            _expense = Expense(
                parent = self.rootKey(car_id),
            )
        _expense.type = self.request.get('type')
        _expense.amount = float(self.request.get('amount'))
        _expense.date = datetime.strptime(self.request.get('date'), "%Y-%m-%d")
        _expense.address = self.request.get('address')

        _lng = self.request.get('lng')
        _lat = self.request.get('lat')

        if _lng and _lat:
            _expense.location = ndb.GeoPt(_lat, _lng)

        self.response.write(_expense.put())
        if not self.request.get('ajax'):
            self.redirect('/car')
示例#16
0
    def get(self):
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()
        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt
        if cur_apt == None:
            response = {}
            response['error'] = 'the apt: ' + apt_name + ' is not available for user: ' + user_email
            return self.respond(**response)

        for expense_id in cur_apt.expense_id_lst:
            expense_lst = Expense.query(Expense.expense_id == expense_id).fetch()
            if len(expense_lst) > 0:
                expense = expense_lst[0]
                if not expense.is_paid:
                    expense.checkout()
                    cur_apt.total_cost += expense.total_cost
                    cur_apt.put()

        self.respond(status="Success")
示例#17
0
    def get(self):

        photo = None
        # if IDENTIFIER_TASK_PHOTO in req_json:
        #     photo = req_json[IDENTIFIER_TASK_PHOTO]


        task_id = uuid.uuid4()

        # req_json = json.loads(self.request.body)

        # task_name = req_json[IDENTIFIER_TASK_NAME]
        task_name = self.request.get(IDENTIFIER_TASK_NAME)

        # creater_email = req_json[IDENTIFIER_USER_EMAIL]
        creater_email = self.request.get(IDENTIFIER_USER_EMAIL)

        #create a new expense
        expense_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)
        expense_name = "Task_"+task_name

        # candidate_lst= req_json[IDENTIFIER_USER_EMAIL_LIST]
        candidates = self.request.get(IDENTIFIER_USER_EMAIL_LIST)
        candidate_lst = candidates.split(",")

        # description = req_json[IDENTIFIER_DESCRIPTION_NAME]
        description = self.request.get(IDENTIFIER_DESCRIPTION_NAME)

        apt_id = self.request.get(IDENTIFIER_APT_ID)

        target_apt_lst = Apartment.query(Apartment.apt_id == apt_id).fetch()


        if len(target_apt_lst)!=0:
            target_apt = target_apt_lst[0]
            print "Found the target_apt " + target_apt.apt_name
            new_expense = Expense(apt_id = target_apt.apt_id,
                                  creater_email = creater_email,
                                  user_email_lst = candidate_lst,
                                  cover_url = None,
                                  expense_name = expense_name,
                                  total_cost = 0,
                                  is_paid = False,
                                  expense_id = str(expense_id ))

            target_apt.expense_id_lst.insert(0, str(expense_id))
            new_expense.put()
            target_apt.put()
            task_id_lst = new_expense.task_id_lst
            if not task_id_lst:
                task_id_lst = []
            task_id_lst.append(str(task_id))
            new_expense.task_id_lst = task_id_lst
            new_expense.put()

        # # expenses = Expense.query(Expense.expense_id == expense_id).fetch()
        # # expense = expenses[0]
        # expense.task_id_lst.append(str(task_id))
        # expense.put()
            new_task = Task(task_name = task_name, expense_id = str(expense_id), creater_email = creater_email,
                        candidate_lst = candidate_lst, description = description, photo_blobkey = photo, task_id = str(task_id),
                        finished = False, assigned = False)
            new_task.put()

            self.respond(task_id = str(task_id), status="Success")
示例#18
0
    def get(self):

        expense_id = self.request.get(IDENTIFIER_EXPENSE_ID)

        print "expense_id :" + expense_id

        expenses = Expense.query(Expense.expense_id == expense_id).fetch()
        expense = expenses[0]
        expense_name = expense.expense_name
        items = expense.getAllItems()
        tasks = expense.getAllTasks()
        expected_cost = 0.0
        items_lst = []
        is_paid = expense.is_paid
        expense_user_lst = expense.getUserNickNameLst()
        for item in items:
            expected_cost += item.total_cost
            cur_item = {}
            cur_item['item_cost'] = item.total_cost
            cur_item['is_paid'] = item.is_paid
            cur_item['item_id'] = str(item.item_id)
            cur_item['cover_url'] = item.cover_url
            cur_item['buyer'] = item.getBuyer()
            cur_item['sharer_lst'] = item.getSharersNickName()
            cur_item['sharer_email_lst'] = item.sharer_email_lst
            cur_item['item_name'] = item.item_name
            cur_item[
                'expense_id'] = item.expense_id  # fixed ; there was no expense_id attached here
            cur_item['buyer_email'] = item.buyer_email
            items_lst.append(cur_item)

        finished_tasks_lst = []
        unassigned_tasks_lst = []
        assigned_tasks_lst = []

        for task in tasks:
            cur_task = {}
            cur_task['photo'] = str(task.photo_blobkey)
            cur_task['creater'] = task.getCreaterNickName()
            cur_task['creater_email'] = task.creater_email
            cur_task['task_name'] = task.task_name
            cur_task['task_id'] = str(task.task_id)
            if task.assigned:
                cur_task['person in charge'] = task.getChargerNickName()
                cur_task['person in charge email'] = task.charger_email
                if task.finished:
                    finished_tasks_lst.append(cur_task)
                else:
                    assigned_tasks_lst.append(cur_task)
            else:
                unassigned_tasks_lst.append(cur_task)

        task_info = {}
        task_info['finished_tasks_lst'] = finished_tasks_lst
        task_info['unassigned_tasks_lst'] = unassigned_tasks_lst
        task_info['assigned_tasks_lst'] = assigned_tasks_lst

        user_email_lst = expense.user_email_lst

        self.respond(total_cost=expected_cost,
                     items_lst=items_lst,
                     is_paid=is_paid,
                     expense_name=expense_name,
                     expense_user_lst=expense_user_lst,
                     user_email_lst=user_email_lst,
                     task_info=task_info,
                     status='Success')
示例#19
0
    def get(self):
        expense_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)

        # expense_name = req_json[IDENTIFIER_EXPENSE_NAME ]
        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        # apt_name = req_json[IDENTIFIER_APT_NAME]
        apt_name = self.request.get(IDENTIFIER_APT_NAME)

        user_emails = self.request.get(IDENTIFIER_USER_LIST)
        user_email_lst = user_emails.split(",")

        target_apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        target_apt = None

        for apt in target_apt_lst:
            if user_email in apt.user_email_lst:
                target_apt = apt
                break
        if target_apt == None:
            response = {}
            response['error'] = 'the user: '******' is not valid for apt: ' + apt_name
            return self.respond(**response)


        # user_email_lst.insert(0, user_email)


        # check whether this apt name is valid or not
        expense_lst = Expense.query(Expense.expense_name == expense_name)
        for expense in expense_lst:
            for user in user_email_lst:
                if user in expense.user_email_lst:
                    response = {}
                    response['error'] = 'the apartment name: ' + expense_name + ' has not been used for ' + user
                    return self.respond(**response)

        # check whether all of these email are valid users
        for user in user_email_lst:
            users = User.query(User.user_email == user).fetch()
            if len(users) == 0:
                response = {}
                response['error'] = 'the email: ' + user + ' has not been registered'
                return self.respond(**response)



        cover_url = None
        # if IDENTIFIER_APT_PHOTO in req_json:
        #     cover_url = req_json[IDENTIFIER_APT_PHOTO]


        new_expense = Expense(apt_id = target_apt.apt_id,
                              creater_email = user_email,
                              user_email_lst = user_email_lst,
                              cover_url = cover_url,
                              expense_name = expense_name,
                              total_cost = 0,
                              is_paid = False,
                              expense_id = str(expense_id ))

        target_apt.expense_id_lst.insert(0, str(expense_id))
        new_expense.put()
        target_apt.put()
        self.respond(expense_id = str(expense_id), status="Success")
示例#20
0
        def get(self):

            expense_id = self.request.get(IDENTIFIER_EXPENSE_ID)

            print "expense_id :" + expense_id

            expenses = Expense.query(Expense.expense_id == expense_id).fetch()
            expense = expenses[0]
            expense_name = expense.expense_name
            items = expense.getAllItems()
            tasks = expense.getAllTasks()
            expected_cost = 0.0
            items_lst = []
            is_paid = expense.is_paid
            expense_user_lst = expense.getUserNickNameLst()
            for item in items:
                expected_cost += item.total_cost
                cur_item = {}
                cur_item['item_cost'] = item.total_cost
                cur_item['is_paid'] = item.is_paid
                cur_item['item_id'] = str(item.item_id)
                cur_item['cover_url'] = item.cover_url
                cur_item['buyer'] = item.getBuyer()
                cur_item['sharer_lst'] = item.getSharersNickName()
                cur_item['sharer_email_lst'] = item.sharer_email_lst
                cur_item['item_name'] = item.item_name
                cur_item['expense_id'] = item.expense_id    # fixed ; there was no expense_id attached here
                cur_item['buyer_email'] = item.buyer_email
                items_lst.append(cur_item)

            finished_tasks_lst = []
            unassigned_tasks_lst = []
            assigned_tasks_lst = []

            for task in tasks:
                cur_task = {}
                cur_task['photo'] = str(task.photo_blobkey)
                cur_task['creater'] = task.getCreaterNickName()
                cur_task['creater_email'] = task.creater_email
                cur_task['task_name'] = task.task_name
                cur_task['task_id'] = str(task.task_id)
                if task.assigned:
                    cur_task['person in charge'] = task.getChargerNickName()
                    cur_task['person in charge email'] = task.charger_email
                    if task.finished:
                        finished_tasks_lst.append(cur_task)
                    else:
                        assigned_tasks_lst.append(cur_task)
                else:
                    unassigned_tasks_lst.append(cur_task)

            task_info = {}
            task_info['finished_tasks_lst'] = finished_tasks_lst
            task_info['unassigned_tasks_lst'] = unassigned_tasks_lst
            task_info['assigned_tasks_lst'] = assigned_tasks_lst

            user_email_lst=expense.user_email_lst

            self.respond(total_cost = expected_cost, items_lst = items_lst, is_paid = is_paid,
                         expense_name = expense_name, expense_user_lst = expense_user_lst, user_email_lst=user_email_lst,
                         task_info = task_info, status = 'Success')
示例#21
0
    def get(self):
        expense_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)

        # expense_name = req_json[IDENTIFIER_EXPENSE_NAME ]
        expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        # apt_name = req_json[IDENTIFIER_APT_NAME]
        apt_name = self.request.get(IDENTIFIER_APT_NAME)

        user_emails = self.request.get(IDENTIFIER_USER_LIST)
        user_email_lst = user_emails.split(",")

        target_apt_lst = Apartment.query(
            Apartment.apt_name == apt_name).fetch()

        target_apt = None

        for apt in target_apt_lst:
            if user_email in apt.user_email_lst:
                target_apt = apt
                break
        if target_apt == None:
            response = {}
            response[
                'error'] = 'the user: '******' is not valid for apt: ' + apt_name
            return self.respond(**response)

        # user_email_lst.insert(0, user_email)

        # check whether this apt name is valid or not
        expense_lst = Expense.query(Expense.expense_name == expense_name)
        for expense in expense_lst:
            for user in user_email_lst:
                if user in expense.user_email_lst:
                    response = {}
                    response[
                        'error'] = 'the apartment name: ' + expense_name + ' has not been used for ' + user
                    return self.respond(**response)

        # check whether all of these email are valid users
        for user in user_email_lst:
            users = User.query(User.user_email == user).fetch()
            if len(users) == 0:
                response = {}
                response[
                    'error'] = 'the email: ' + user + ' has not been registered'
                return self.respond(**response)

        cover_url = None
        # if IDENTIFIER_APT_PHOTO in req_json:
        #     cover_url = req_json[IDENTIFIER_APT_PHOTO]

        new_expense = Expense(apt_id=target_apt.apt_id,
                              creater_email=user_email,
                              user_email_lst=user_email_lst,
                              cover_url=cover_url,
                              expense_name=expense_name,
                              total_cost=0,
                              is_paid=False,
                              expense_id=str(expense_id))

        target_apt.expense_id_lst.insert(0, str(expense_id))
        new_expense.put()
        target_apt.put()
        self.respond(expense_id=str(expense_id), status="Success")
示例#22
0
    def get(self):

        photo = None
        # if IDENTIFIER_TASK_PHOTO in req_json:
        #     photo = req_json[IDENTIFIER_TASK_PHOTO]

        task_id = uuid.uuid4()

        # req_json = json.loads(self.request.body)

        # task_name = req_json[IDENTIFIER_TASK_NAME]
        task_name = self.request.get(IDENTIFIER_TASK_NAME)

        # creater_email = req_json[IDENTIFIER_USER_EMAIL]
        creater_email = self.request.get(IDENTIFIER_USER_EMAIL)

        #create a new expense
        expense_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)
        expense_name = "Task_" + task_name

        # candidate_lst= req_json[IDENTIFIER_USER_EMAIL_LIST]
        candidates = self.request.get(IDENTIFIER_USER_EMAIL_LIST)
        candidate_lst = candidates.split(",")

        # description = req_json[IDENTIFIER_DESCRIPTION_NAME]
        description = self.request.get(IDENTIFIER_DESCRIPTION_NAME)

        apt_id = self.request.get(IDENTIFIER_APT_ID)

        target_apt_lst = Apartment.query(Apartment.apt_id == apt_id).fetch()

        if len(target_apt_lst) != 0:
            target_apt = target_apt_lst[0]
            print "Found the target_apt " + target_apt.apt_name
            new_expense = Expense(apt_id=target_apt.apt_id,
                                  creater_email=creater_email,
                                  user_email_lst=candidate_lst,
                                  cover_url=None,
                                  expense_name=expense_name,
                                  total_cost=0,
                                  is_paid=False,
                                  expense_id=str(expense_id))

            target_apt.expense_id_lst.insert(0, str(expense_id))
            new_expense.put()
            target_apt.put()
            task_id_lst = new_expense.task_id_lst
            if not task_id_lst:
                task_id_lst = []
            task_id_lst.append(str(task_id))
            new_expense.task_id_lst = task_id_lst
            new_expense.put()

            # # expenses = Expense.query(Expense.expense_id == expense_id).fetch()
            # # expense = expenses[0]
            # expense.task_id_lst.append(str(task_id))
            # expense.put()
            new_task = Task(task_name=task_name,
                            expense_id=str(expense_id),
                            creater_email=creater_email,
                            candidate_lst=candidate_lst,
                            description=description,
                            photo_blobkey=photo,
                            task_id=str(task_id),
                            finished=False,
                            assigned=False)
            new_task.put()

            self.respond(task_id=str(task_id), status="Success")
示例#23
0
def response():
	action = cgi_get("action", choices=["view", "pay", "service", "commitment", "request", "invite", "expense", "verify", "unverify", "apply", "join", "pod", "membership", "person", "enroll", "manage", "confcode", "mint", "balance", "responsibilities"])
	if action == "view":
		ip = local("response").ip
		user = cgi_get("user", required=False) # key
		if user:
			user = db.get(user)
		else:
			user = Person.query(Person.ip == ip).get()
		if not user:
			user = Person()
			user.ip = ip
			user.put()
		views(user)
	elif action == "mint":
		user = db.get(cgi_get("user"))
		amount = cgi_get("amount")
		user.wallet.get().mint(amount)
	elif action == "balance":
		user = db.get(cgi_get("user"))
		succeed(user.wallet.get().balance())
	elif action == "pay":
		payer = db.get(cgi_get("payer"))
		memship = db.get(cgi_get("membership"))
		person = memship.person.get()
		pod = memship.pod.get()
		pment = Payment()
		pment.membership = memship.key
		pment.payer = payer.key
		pment.amount = cgi_get("amount")
		pment.notes = cgi_get("notes")
		if payer.key.urlsafe() == person.key.urlsafe():
			fail("pay yourself?")
		if payer.wallet.get().outstanding < pment.amount:
			fail("you don't have enough in your account!")
		pment.put()
		pkey = pment.key.urlsafe()
		pment.notify("confirm payment", lambda signer : PAYMENT%(pment.amount,
			person.firstName, pod.name, pment.notes, pkey, signer.urlsafe()))
		succeed(pkey)
	elif action == "service":
		succeed(reg_act(cgi_get("membership"), cgi_get("service"),
			cgi_get("workers"), cgi_get("beneficiaries"), cgi_get("notes")))
	elif action == "commitment":
		comm = Commitment()
		comm.membership = cgi_get("membership")
		comm.service = cgi_get("service")
		comm.estimate = cgi_get("estimate")
		comm.notes = cgi_get("notes")
		comm.put()
		comm.verify(comm.membership.get().person) # (submitter already agrees)
		ckey = comm.key.urlsafe()
		service = comm.service.get()
		memship = comm.membership.get()
		person = memship.person.get()
		pod = memship.pod.get()
		comm.notify("affirm commitment", lambda signer : COMMITMENT%(person.email,
			pod.name, comm.estimate, service.name, comm.notes, ckey, signer.urlsafe()))
		succeed(ckey)
	elif action == "request":
		req = Request()
		req.membership = cgi_get("membership")
		req.change = cgi_get("change")
		req.person = cgi_get("person", required=False)
		req.notes = cgi_get("notes")
		req.put()
		req.remind()
		succeed(req.key.urlsafe())
	elif action == "invite":
		inv = Invitation()
		inv.membership = cgi_get("membership")
		inv.email = cgi_get("email").lower()
		inv.notes = cgi_get("notes")
		inv.put()
		inv.invite()
	elif action == "expense":
		exp = Expense()
		exp.membership = cgi_get("membership")
		exp.executor = cgi_get("executor", required=False)
		exp.variety = cgi_get("variety", choices=["dividend", "reimbursement"])
		exp.amount = cgi_get("amount")
		exp.recurring = cgi_get("recurring")
		exp.notes = cgi_get("notes")
		exp.put()
		memship = exp.membership.get()
		mpmail = memship.person.get().email
		pod = memship.pod.get()
		variety = exp.variety
		amount = exp.amount
		if exp.executor:
			variety = "%s - executor: %s"%(variety, exp.executor.get().email)
		else:
			amount = "%s%%"%(amount * 100,)
		exp.notify("approve expense", lambda signer: EXPENSE%(mpmail, pod.name,
			variety, amount, exp.recurring, exp.notes, signer.urlsafe()))
		succeed(exp.key.urlsafe())
	elif action == "verify":
		verifiable = db.get(cgi_get("verifiable")) # act/request/commitment/expense/appointment
		verifiable.verify(db.KeyWrapper(cgi_get("person")))
		redirect("/comp/pods.html", "you did it!")
	elif action == "unverify": # commitment only!!!!??!
		vkey = cgi_get("verifiable")
		verifiable = db.get(vkey)
		verifiable.unverify()
		service = verifiable.service.get()
		memship = verifiable.membership.get()
		person = memship.person.get()
		pod = memship.pod.get()
		for signer in pod.members():
			send_mail(to=signer.get().email, subject="affirm commitment - estimate adjustment",
				body=COMMITMENT%(person.email, pod.name, verifiable.estimate,
					service.name, vkey, signer.urlsafe()))
	elif action == "apply":
		db.get(cgi_get("request")).apply()
		redirect("/comp/pods.html", "you did it!")
	elif action == "join": # support only
		pod = db.get(cgi_get("pod"))
		if pod.variety != "support":
			fail()
		person = db.get(cgi_get("person"))
		succeed(person.enroll(pod).urlsafe())
	elif action == "pod":
		pod = db.get(cgi_get("pod"))
		succeed({
			"services": [a.data() for a in pod.acts()],
			"requests": [r.data() for r in pod.requests()],
			"proposals": [p.data() for p in db.get_multi(pod.proposals())],
			"commitments": [c.data() for c in pod.commitments()],
			"memberships": [m.data() for m in pod.members(True)],
			"people": [p.data() for p in db.get_multi(pod.members())],
			"codebases": [c.data() for c in pod.codebases()],
			"expenses": [e.data() for e in pod.expenses()]
		})
	elif action == "membership":
		memship = db.get(cgi_get("membership"))
		succeed({
			"content": [c.data() for c in Content.query(Content.membership == memship.key).fetch()],
			"products": [p.data() for p in db.get_multi(memship.products)]
		})
	elif action == "person":
		person = db.get(cgi_get("person"))
		succeed({
			"services": len(person.acts()), # more efficient way?
			"memberships": [m.data() for m in person.memberships()],
			"commitments": sum([c.estimate for c in person.commitments()])
		})
	elif action == "responsibilities":
		person = db.get(cgi_get("person"))
		succeed([t.data() for t in person.tasks()])
	elif action == "enroll":
		succeed(enroll(cgi_get("agent"), cgi_get("pod"), cgi_get("person")).urlsafe())
	elif action == "manage":
		succeed(manage(cgi_get("agent"), cgi_get("membership"), cgi_get("content")).key.urlsafe())
	elif action == "confcode":
		send_mail(to=cgi_get("email"), subject="carecoin confirmation code",
			body=CONFCODE%(cgi_get("code"),))