예제 #1
0
    def post(self):
        if self.request.get('minAmount') != '' and self.request.get('maxAmount') != '':
            expenses = Expense.query(Expense.amount >= int(self.request.get('minAmount')) * 100,
                Expense.amount <= int(self.request.get('maxAmount')) * 100)
        elif self.request.get('minAmount') == '' and self.request.get('maxAmount') == '':
            self.response.out.write(json.dumps([]))
            self.response.out.http_status_message(200)
            return
        elif self.request.get('minAmount') == '':
            expenses = Expense.query(Expense.amount <= int(self.request.get('maxAmount')) * 100)
        elif self.request.get('maxAmount') == '':
            expenses = Expense.query(Expense.amount >= int(self.request.get('minAmount')) * 100)

        jArray = []
        for expense in expenses:
            j = {
                'amount': "{0:.2f}".format(expense.amount * 1.0/100),
                'desc': expense.desc,
                'date': str(expense.date),
                'tags': expense.tags,
                'keyId': int(expense.key.id()),
            }
            jArray.append(j)

        self.response.out.write(json.dumps(jArray))
        self.response.out.http_status_message(200)
예제 #2
0
    def post(self):
        if self.request.get('from') != '' and self.request.get('to') != '':
            fromDate = datetime.datetime.strptime(self.request.get('from'), '%m/%d/%Y').date()
            toDate = datetime.datetime.strptime(self.request.get('to'), '%m/%d/%Y').date()
            expenses = Expense.query(Expense.date >= fromDate, Expense.date <= toDate).fetch()
        elif self.request.get('from') == '' and self.request.get('to') == '':
            self.response.out.write(json.dumps([]))
            self.response.out.http_status_message(200)
            return
        elif self.request.get('from') == '':
            toDate = datetime.datetime.strptime(self.request.get('to'), '%m/%d/%Y').date()
            expenses = Expense.query(Expense.date <= toDate).fetch()
        elif self.request.get('to') == '':
            fromDate = datetime.datetime.strptime(self.request.get('from'), '%m/%d/%Y').date()
            expenses = Expense.query(Expense.date >= fromDate).fetch()

        jArray = []
        for expense in expenses:
            j = {
                'amount': "{0:.2f}".format(expense.amount * 1.0/100),
                'desc': expense.desc,
                'date': str(expense.date),
                'tags': expense.tags,
                'keyId': int(expense.key.id()),
            }
            jArray.append(j)

        self.response.out.write(json.dumps(jArray))
        self.response.out.http_status_message(200)
예제 #3
0
    def get(self):
        user = users.get_current_user()

        if user:
            expenses = Expense.query(Expense.userID == user.user_id()).fetch()
            
            for expense in expenses:
                expense.tags = map(str, expense.tags)

            jArray = []
            for expense in expenses:
                j = {
                    'amount': "{0:.2f}".format(expense.amount * 1.0/100),
                    'desc': expense.desc,
                    'date': str(expense.date),
                    'tags': expense.tags,
                    'keyId': int(expense.key.id())
                }
                jArray.append(j)

            template_values = {
                'expenses': jArray,
            }


            template = jinja_environment.get_template('history.html')
            self.response.write(template.render(template_values))
        else:
            template = jinja_environment.get_template('login.html')
            self.response.write(template.render())
예제 #4
0
    def post(self):
        tags = map(str,self.request.get('tags').split(','))

        if len(tags) == 0:
            self.response.out.write(json.dumps([]))
            self.response.out.http_status_message(200)
            return
        else:
            query = Expense.query(Expense.userID == users.get_current_user().user_id())

            for i, tag in enumerate(tags):
                query = query.filter(Expense.tags == tag)         

            expenses = query.fetch()

        jArray = []
        for expense in expenses:
            j = {
                'amount': "{0:.2f}".format(expense.amount * 1.0/100),
                'desc': expense.desc,
                'date': str(expense.date),
                'tags': expense.tags,
                'keyId': int(expense.key.id()),
            }
            jArray.append(j)

        self.response.out.write(json.dumps(jArray))
        self.response.out.http_status_message(200)
예제 #5
0
    def get(self):
        user = users.get_current_user()

        if user:
            current = datetime.datetime.strptime("01/" + str(datetime.datetime.now().strftime("%m/%Y")), '%m/%d/%Y').date()
            expenses = Expense.query(Expense.userID == user.user_id(), Expense.date >= current).fetch()
            total = sum([expense.amount for expense in expenses])

            template_values = {
                'totalThisMonth': "{0:.2f}".format(total * 1.0/100)
            }

            template = jinja_environment.get_template('index.html')
            self.response.write(template.render(template_values))
        else:
            template = jinja_environment.get_template('login.html')
            self.response.write(template.render())
예제 #6
0
    def get(self):
        user = users.get_current_user()

        if user:
            expenses = Expense.query(Expense.userID == user.user_id()).fetch()
            
            for expense in expenses:
                expense.tags = map(str, expense.tags)

            template_values = {
                'expenses': expenses,
            }

            template = jinja_environment.get_template('stats.html')
            self.response.write(template.render(template_values))

        else:
            template = jinja_environment.get_template('login.html')
            self.response.write(template.render())
예제 #7
0
    def post(self):
        user = users.get_current_user()

        if user:            
            json_data = self.request.body
            data = json.loads(json_data) 
            localExps = data['localDB'] 

            expenses = Expense.query(Expense.userID == user.user_id()).fetch()

            deletedExpenses = []
            newExpenses = []
            expensesEIDs = []

            for expense in expenses:
                expensesEIDs.append(int(expense.key.id()))
                if int(expense.key.id()) not in localExps:
                    j = {
                        'amount': expense.amount,
                        'desc': expense.desc,
                        'date': str(expense.date),
                        'tags': expense.tags,
                        'keyId': long(expense.key.id())
                    }
                    newExpenses.append(j)

            for eid in localExps:
                if eid not in expensesEIDs:
                    deletedExpenses.append(eid)

            data = {
                'newExpenses' : newExpenses,
                'deletedExpenses' : deletedExpenses
            }
                
            self.response.write(json.dumps(data))