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"
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"
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
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
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
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
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
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
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
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)
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)
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
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
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
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'))
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'))
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
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
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'))
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)
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
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
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')
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')
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
def count_users(): return query_db('SELECT COUNT(id) AS count FROM users', one=True)['count']
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
def get_all(self): return query_db('SELECT key FROM wiki ORDER BY key ASC')
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