Пример #1
0
	def errand(self):

		week = datetime.now().isocalendar()[1]

		users = query_db('SELECT * FROM users ORDER BY id ASC')
		number_of_users = len(users)

		user_number = next(index for (index, d) in enumerate(users) if d["id"] == self.id)

		part_list = range(1, number_of_users+1)
		list = []
		list.append(part_list[:])

		for i in xrange(number_of_users-1):
			part_list.append(part_list.pop(0))
			list.append(part_list[:])

		errand_number = list[user_number-1][(week % number_of_users)-1] - 1

		errand_ids = query_db('SELECT id FROM errands ORDER BY id ASC')

		print errand_ids

		errands = []
		for errand_id in errand_ids:
			errand = Errand( errand_id['id'] )
			errands.append(errand)

		try:
			return errands[errand_number]
		except IndexError:
			return "None"
Пример #2
0
    def errand(self):

        week = datetime.now().isocalendar()[1]

        users = query_db('SELECT * FROM users ORDER BY id ASC')
        number_of_users = len(users)

        user_number = next(index for (index, d) in enumerate(users)
                           if d["id"] == self.id)

        part_list = list(range(1, number_of_users + 1))
        other_list = []
        other_list.append(part_list[:])

        for i in range(number_of_users - 1):
            part_list.append(part_list.pop(0))
            other_list.append(part_list[:])

        errand_number = other_list[user_number - 1][(week % number_of_users) -
                                                    1] - 1

        errand_ids = query_db('SELECT id FROM errands ORDER BY id ASC')

        errands = []
        for errand_id in errand_ids:
            errand = Errand(errand_id['id'])
            errands.append(errand)

        try:
            return errands[errand_number]
        except IndexError:
            return "None"
Пример #3
0
	def spending(self):
		try:
			spending_sum = query_db('SELECT SUM(amount) AS sum FROM receipts', one=True)['sum']
			self._spending =  query_db('SELECT SUM(amount) AS sum FROM receipts WHERE user = ?', [self.id], one=True)['sum'] - (spending_sum/count_users())
			return self._spending
		except TypeError:
			return 0
Пример #4
0
    def expenses(self):
        roommates = query_db('SELECT COUNT(*) AS count FROM users', one=True)

        expenses = query_db('SELECT * FROM expenses ORDER BY amount DESC')

        for expense in expenses:
            expense['amount'] = expense['amount'] / (roommates['count'] / 1.00)
        return expenses
Пример #5
0
	def expenses(self):
		roommates = query_db('SELECT COUNT(*) AS count FROM users', one=True)

		expenses = query_db('SELECT * FROM expenses ORDER BY amount DESC')

		for expense in expenses:
			expense['amount'] = expense['amount'] / ( roommates['count'] / 1.00)
		return expenses
Пример #6
0
    def spending(self):
        spending_sum = query_db('SELECT SUM(amount) AS sum FROM receipts',
                                one=True)['sum']
        if spending_sum is None:
            return 0

        spending_user = query_db(
            'SELECT SUM(amount) AS sum FROM receipts WHERE user = ?',
            [self.id],
            one=True)['sum']
        if spending_user is None:
            spending_user = 0

        self._spending = spending_user - (spending_sum / count_users())
        return self._spending
Пример #7
0
	def __init__(self, id):
		purchase = query_db('SELECT * FROM purchases WHERE id = ?', [id], one=True)
		self.id = purchase['id']
		self.title = purchase['title']
		self.amount = purchase['amount']
		self.date = arrow.get(purchase['date'], 'YYYY-MM-DD')
		return None
Пример #8
0
	def __init__(self, id):
		purchase = query_db('SELECT * FROM purchases WHERE id = ?', [id], one=True)
		self.id = purchase['id']
		self.title = purchase['title']
		self.amount = purchase['amount']
		self.date = datetime.strptime(purchase['date'], '%Y-%m-%d')
		return None
Пример #9
0
def list_users():
	user_ids = query_db('SELECT * FROM users ORDER BY id ASC')
	users = []
	for user_id in user_ids:
		user = User(user_id['id'])
		users.append(user)
	return users
Пример #10
0
def list_users():
    user_ids = query_db('SELECT * FROM users ORDER BY id ASC')
    users = []
    for user_id in user_ids:
        user = User(user_id['id'])
        users.append(user)
    return users
Пример #11
0
def users_edit(id):
    if request.method == 'POST':
        if session.get('id') != id:
            flash('You cannot edit this user.')
            return redirect(url_for('users'))
        for key, value in request.form.items():
            if value == '' and key != "password" and key != "confirm":
                flash('Please fill out all the fields.', 'error')
                return render_template('users_edit.html', values=request.form)
        if request.form["password"] or request.form["confirm"]:
            if request.form["password"] == request.form["confirm"]:
                g.db.execute('UPDATE users SET password=? WHERE id=?', [
                    bcrypt.hashpw(request.form["password"].encode('utf-8'),
                                  bcrypt.gensalt()), id
                ])
            else:
                flash('Both passwords do not match', 'error')
                return render_template('users_edit.html', values=request.form)
        g.db.execute('UPDATE users SET name=?, login=?, birthday=? WHERE id=?',
                     [
                         request.form["name"], request.form["login"],
                         request.form["birthday"], id
                     ])
        g.db.commit()
        flash('User "' + request.form['name'] + '" updated.')
        return redirect(url_for('users'))

    else:
        user = query_db('SELECT * FROM users WHERE id = ?', [id], one=True)
        if user:
            return render_template('users_edit.html', values=user)
        else:
            abort(404)
Пример #12
0
def users():
	user_ids = query_db('SELECT id FROM users ORDER BY id ASC')
	users = []
	for user_id in user_ids:
		temp_user = User(user_id['id'])
		users.append(temp_user)
	return render_template('users.html', users = users)
Пример #13
0
 def __init__(self, id):
     purchase = query_db('SELECT * FROM purchases WHERE id = ?', [id],
                         one=True)
     self.id = purchase['id']
     self.title = purchase['title']
     self.amount = purchase['amount']
     self.date = arrow.get(purchase['date'], 'YYYY-MM-DD')
     return None
Пример #14
0
 def __init__(self, id):
     message = query_db('SELECT * FROM messages WHERE id = ?', [id],
                        one=True)
     self.message = message['message']
     self.author = User(message['author'])
     self.datetime = datetime.strptime(message['date'],
                                       '%Y-%m-%d %H:%M:%S.%f')
     return None
Пример #15
0
	def __init__(self, id):
		receipt = query_db('SELECT * FROM receipts WHERE id = ?', [id], one=True)
		self.id = receipt['id']
		self.title = receipt['title']
		self.amount = receipt['amount']
		self.user = User(receipt['user'])
		self.date = datetime.strptime(receipt['date'], '%Y-%m-%d')
		return None
Пример #16
0
 def attached_files(self):
     files = query_db('SELECT id FROM uploads WHERE wiki_id = ?', [self.id])
     if files == None:
         return False
     else:
         files_list = []
         for file in files:
             files_list.append(File(file['id']))
         return files_list
Пример #17
0
def remove_user(id):
    user = query_db('SELECT id from users WHERE id = ?', [id], one=True)
    if user:
        g.db.execute('DELETE FROM users WHERE id = ?', [id])
        g.db.commit()
        flash('The user has been deleted.')
    else:
        flash('No user with this id.', 'error')
    return redirect(url_for('users'))
Пример #18
0
 def __init__(self, id):
     receipt = query_db('SELECT * FROM receipts WHERE id = ?', [id],
                        one=True)
     self.id = receipt['id']
     self.title = receipt['title']
     self.amount = receipt['amount']
     self.user = User(receipt['user'])
     self.date = datetime.strptime(receipt['date'], '%Y-%m-%d')
     return None
Пример #19
0
def remove_user(id):
	user = query_db('SELECT id from users WHERE id = ?', [id], one = True)
	if user:
		g.db.execute('DELETE FROM users WHERE id = ?', [id])
		g.db.commit()
		flash('The user has been deleted.')
	else:
		flash('No user with this id.', 'error')
	return redirect(url_for('users'))
Пример #20
0
	def attached_files(self):
		files = query_db('SELECT id FROM uploads WHERE wiki_id = ?', [self.id])
		if files == None:
			return False
		else:
			files_list = []
			for file in files:
				files_list.append( File(file['id']) )
			return files_list
Пример #21
0
	def __init__(self, param):
		if param == unicode(param):
			key = param
			page = query_db('SELECT * FROM wiki WHERE key = ?', [key], one=True)
		else:
			id = param
			page = query_db('SELECT * FROM wiki WHERE id = ?', [id], one=True)

		if page == None:
			self.exists = False
			return None
		else:
			self.exists = True
			for key, value in page.items():
				setattr(self, key, value)
			self.md_content = self.content
			self.content = markdown(self.content)
		return None
Пример #22
0
def users():
    user_ids = query_db('SELECT id FROM users ORDER BY id ASC')
    users = []
    for user_id in user_ids:
        temp_user = User(user_id['id'])
        users.append(temp_user)
    return render_template('users.html',
                           users=users,
                           current_id=session.get('id'))
Пример #23
0
def index():
	g.user = User(session.get('id'))

	messages_ids = query_db('SELECT id from messages ORDER BY id DESC LIMIT 20')
	messages = []
	for message_id in messages_ids:
		message = Message(message_id['id'])
		messages.append(message)

	users = list_users()

	return render_template('index.html', user=g.user, messages=messages, users=users)
Пример #24
0
def index():
	g.user = User(session.get('id'))

	messages_ids = query_db('SELECT id from messages ORDER BY id DESC LIMIT 20')
	messages = []
	for message_id in messages_ids:
		message = Message(message_id['id'])
		messages.append(message)

	users = list_users()

	return render_template('index.html', user=g.user, messages=messages, users=users)
Пример #25
0
    def reminders(self):
        roommates = query_db('SELECT id FROM users')

        reminders = []

        for roommate in roommates:
            user = User(roommate['id'])
            if user.days_to_birthday() < 30:
                reminder = Reminder()
                reminder.birthday(user)
                reminders.append(reminder)

        return reminders
Пример #26
0
    def __init__(self, param):
        page = query_db('SELECT * FROM wiki WHERE key = ?', [param], one=True)

        if page == None:
            self.exists = False
            return None
        else:
            self.exists = True
            for key, value in page.items():
                setattr(self, key, value)
            self.md_content = self.content
            self.content = markdown(self.content)
        return None
Пример #27
0
	def reminders(self):
		roommates = query_db('SELECT id FROM users')

		reminders = []

		for roommate in roommates:
			user = User(roommate['id'])
			if user.days_to_birthday() < 30:
				reminder = Reminder()
				reminder.birthday(user)
				reminders.append(reminder)

		return reminders
Пример #28
0
def login():
	if request.method == 'POST':
		user = query_db('SELECT * FROM users WHERE login = ?', [request.form['login']], one=True)

		if user is None:
			flash('Login/password incorrect', 'error')
			return render_template('login.html')
		else:
			if bcrypt.hashpw(
				request.form['password'].encode('utf-8'),
				user['password'].decode('utf-8').encode('utf-8')
			) == user['password']:
				session['id'] = user['id']
				flash('You are now logged in.')
				return redirect(url_for('index'))
			else:
				flash('Login/password incorrect', 'error')
				return render_template('login.html')
	else:
		return render_template('login.html')
Пример #29
0
def login():
	if request.method == 'POST':
		user = query_db('SELECT * FROM users WHERE mail = ?', [request.form['mail']], one=True)

		print(type(user))
		print(str(user['password']))

		if user is None:
			flash('Login nicht erfolgreich.', 'error')
			return render_template('login.html')
		else:
			if bcrypt.hashpw(
				request.form['password'].encode('utf-8'),
				user['password'].decode('utf-8').encode('utf-8')
			) == user['password']:
				session['id'] = user['id']
				flash('You are now logged in.')
				return redirect(url_for('index'))
			else:
				flash('Login nicht erfolgreich.', 'error')
				return render_template('login.html')
	else:
		return render_template('login.html')
Пример #30
0
 def __init__(self, id):
     user = query_db('SELECT * FROM users WHERE id = ?', [id], one=True)
     for key, value in user.items():
         setattr(self, key, value)
     return None
Пример #31
0
def count_users():
    return query_db('SELECT COUNT(id) AS count FROM users', one=True)['count']
Пример #32
0
	def __init__(self, id):
		user = query_db('SELECT * FROM users WHERE id = ?', [id], one=True)
		for key, value in user.items():
			setattr(self, key, value)
		return None
Пример #33
0
 def __init__(self, id):
     errand = query_db('SELECT * FROM errands WHERE id = ?', [id], one=True)
     for key, value in errand.items():
         setattr(self, key, value)
     return None
Пример #34
0
 def get_all(self):
     return query_db('SELECT key FROM wiki ORDER BY key ASC')
Пример #35
0
 def __init__(self, id):
     file = query_db('SELECT * FROM uploads WHERE id = ?', [id], one=True)
     for key, value in file.items():
         setattr(self, key, value)
     return None
Пример #36
0
def count_users():
	return query_db('SELECT COUNT(id) AS count FROM users', one=True)['count']
Пример #37
0
	def __init__(self, id):
		message = query_db('SELECT * FROM messages WHERE id = ?', [id], one=True)
		self.message = message['message']
		self.author = User(message['author'])
		self.datetime = datetime.strptime(message['date'], '%Y-%m-%d %H:%M:%S.%f')
		return None
Пример #38
0
	def __init__(self, id):
		file = query_db('SELECT * FROM uploads WHERE id = ?', [id], one=True)
		for key, value in file.items():
			setattr(self, key, value)
		return None
Пример #39
0
	def __init__(self, id):
		errand = query_db('SELECT * FROM errands WHERE id = ?', [id], one=True)
		for key, value in errand.items():
			setattr(self, key, value)
		return None
Пример #40
0
	def get_all(self):
		return query_db('SELECT key FROM wiki ORDER BY key ASC')