def ApiEventAddNew(): if request.method == 'POST': users = User.all_user() if 'username' in session: cuser = User.get_user('username', session['username']) if cuser: if not (request.form['title'] or not request.form['description'] or not request.form['image'] or not request.form['date'] or not request.form['time'] or not request.form['descriptionshort']): # TODO: download and upload image Event.create_event(request.form['title'], request.form['description'], request.form['image'], request.form['date'].replace('.', '-'), request.form['time'], request.form['descriptionshort']) else: return render_template( 'eventAdd.html', data={ "username": f'{cuser.username}', "error": 'All field must be zapolneni blyat!' }) return redirect(url_for('login'))
def ApiEventDelete(): if request.method == 'GET': users = User.all_user() if 'username' in session: cuser = User.get_user('username', session['username']) if cuser: event = Event.get_event('id', f"{request.args.get('id')}") event.delete_event() return redirect(url_for('login'))
def users(): users = User.all_user() if 'username' in session: cuser = User.get_user('username', session['username']) if cuser: return render_template('users.html', username=f'{cuser.username}', users=users) return redirect(url_for('login'))
def ApiUserDelete(): if request.method == 'GET': users = User.all_user() if 'username' in session: cuser = User.get_user('username', session['username']) if cuser: for user in users: if f"{user.chat_id}" == f"{request.args.get('chat_id')}": user.delete_user() return redirect(url_for('login'))
def sendtoall(): if request.method == 'POST': if request.form['text']: users = User.all_user() for user in users: bot.send_message(user.chat_id, f"{request.form['text']}") if 'username' in session: cuser = User.get_user('username', session['username']) if (cuser != None): return render_template('sendtoall.html', username=f'{cuser.username}') return redirect(url_for('login'))
def render_main_page(username): data = {} try: total_users = len(User.all_user()) except: total_users = 0 try: total_events = len(Event.all_event()) except: total_events = 0 data['total_users'] = total_users data['total_events'] = total_events data['username'] = username return render_template('index.html', data=data)
def ApiEventEdit(): if request.method == 'POST': users = User.all_user() if 'username' in session: cuser = User.get_user('username', session['username']) if cuser: if not (request.form['title'] or not request.form['description'] or not request.form['image'] or not request.form['date'] or not request.form['time'] or not request.form['descriptionshort']): event = Event.get_event('id', f"{request.args.get('id')}") event.name = request.form['name'] event.title = request.form['title'] event.description = request.form['description'] event.shortdescription = request.form['shortdescription'] event.photo = request.form['image'] event.date = request.form['date'] event.time = request.form['time'] event.update() return redirect(url_for('login'))