def update(group_id, id): if request.method == 'GET': message = MessageModel.find_by_id(_id=id, group_id=group_id) if message is None: flash( 'The scheduled message is already executed or does not exists.' ) return redirect(url_for('dashboard.index')) group = GroupModel.find_by_id(group_id).json() return render_template('dashboard/update.html', message=message, group_name=group['channel']['group_name']) if request.method == "POST": group_id = int(group_id) schedule = parse(request.form['schedule'] + '+05:30') error = None if schedule < datetime.datetime.now(pytz.timezone('Asia/Kolkata')): error = 'You can not schedule a message in past' if error: flash(error) job = scheduler.get_job(id) message = MessageModel.find_by_id(_id=id, group_id=group_id) if job and message: schedule_msg(request.form['message'], schedule, group_id, job) message.name = request.form['name'] message.message = request.form['message'] message.schedule = request.form['schedule'] + '+05:30' message.save_to_db() return redirect(url_for('dashboard.index')) return render_template('dashboard/schedules.html')
def get(self, team_id): #Get messages based on team_id messages = MessageModel.find_by_id(team_id) if messages.first(): return {'messages': list(map(lambda x: x.json(), messages))} return {'message': 'No messages found'}, 404
def delete(self, message_id): message = MessageModel.find_by_id(message_id) if message: if message.sender == UserModel.find_by_id( get_jwt_identity()).username: message.delete_from_db() return {"info": "Message deleted!"} return {"error": "Message cannot be found in your sent messages"}
def delete(): message = MessageModel.find_by_id(_id=request.form['id'], group_id=request.form['group_id']) job = scheduler.get_job(request.form['id']) if message and job: try: delete_schedule(job) # message.delete_from_db() this should be automatically handled by the trigger on apschedule_jobs table return redirect(url_for('dashboard.index')) except: flash('Unable to delete the message') flash('No scheduled message found for id {}'.format(request.form['id']))
def get(self): id = request.args.get('id', None) user_id = request.args.get('user_id', None) sender_id = request.args.get('user_id', None) data = None if id: data = MessageModel.find_by_id(id) elif user_id: data = MessageModel.find_by_user_id(user_id) else: data = MessageModel.find_by_sender_id(sender_id) if data: if id is None: return {'messages': list(map(lambda x: x.json(), data))}, 200 return data.json() return {'message': 'message not found'}, 404