def index(text=None): current_date = datetime.datetime.now().date().strftime('%B %d, %Y') likes = Format.human_format(likes_counter.value) current_year = datetime.datetime.now().year.__str__() question_data = survey.read('key1') login = None if 'auth_token' in session: try: login = UserDAO.get( Authentication.decode_auth_token( current_app.config['SECRET_KEY'], session['auth_token'])).login.split('@')[0] except Exception as e: session.pop('auth_token', None) return redirect( url_for('home_controller.index', text=['warning', e.__str__()])) if text: text = ast.literal_eval(text) return render_template('index.html', date=current_date, year=current_year, user=login, likes=likes, question_data=question_data, text=text)
def get_file(name): try: user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) file = FileDAO.read(name, user.id) return jsonify({'name': file.name, 'added_on': file.added_on.__str__()}), 200 except Exception as e: return jsonify({'error': e.__str__()}), 500
def get_status(task_id): with Connection(redis.from_url(current_app.config['REDIS_URL'])): q = Queue() task = q.fetch_job(task_id) if task: response_object = { 'status': 'success', 'data': { 'task_id': task.get_id(), 'task_status': task.get_status(), 'task_result': task.result, } } if task.result == 0: try: user = UserDAO.get( Authentication.decode_auth_token( current_app.config['SECRET_KEY'], session['auth_token'])) FileDAO.create(task.meta['task_name'] + '.mp4', user, True) response_object.update({'home_catalog': user.home_catalog}) return jsonify(response_object), 200 except UserException as e: logging.getLogger('logger').warning(e) return jsonify(response_object), 200 except Exception as e: return jsonify({'error': e.__str__()}), 500 else: response_object = {'status': 'error'} return jsonify(response_object)
def add_file(): file = request.files['file'] try: user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) new_file = FileDAO.create(file, user) return jsonify({'name': new_file.name, 'added_on': new_file.added_on.__str__()}), 201 except Exception as e: return jsonify({'error': e.__str__()}), 500
def add_file(): file = request.files['filePath'] try: user = UserDAO.get( Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) FileDAO.create(file, user) return redirect(url_for('user_controller.index')) except Exception as e: return redirect(url_for('user_controller.index', error=e))
def delete_files(): try: data = json.loads(request.get_data().decode('utf-8')) user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) data_entities = [] for name in data: data_entities.append(FileDAO.read(name, user.id)) FileDAO.delete(data_entities, user.home_catalog) return jsonify({'deleted_files': data}), 200 except Exception as e: return jsonify({'error': e.__str__()}), 500
def change_file(name): try: data = json.loads(request.get_data().decode('utf-8')) user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) file_to_update = FileDAO.read(name, user.id) file_to_update.name = data[0] FileDAO.update(file_to_update, user, 'File name: ' + name + ' to ' + data[0] + ' updated') return jsonify({'old_name': name, 'new_name': data[0]}), 200 except Exception as e: print(e) return jsonify({'error': e.__str__()}), 500
def get_files(): try: user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) files = FileDAO.get_all(user.id) file_list = [] for file in files: file_list.append({'name': file.name, 'added_on': file.added_on.__str__()}) return jsonify({'files': file_list}), 200 except Exception as e: return jsonify({'error': e.__str__()}), 500
def index(text=None): user = UserDAO.get(Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) try: login = user.login.split('@')[0] files = FileDAO.get_all(user.id) current_year = datetime.datetime.now().year.__str__() if text: text = ast.literal_eval(text) return render_template('userPanel.html', user=login, home_catalog=user.home_catalog, files=files, year=current_year, text=text) except Exception as e: return redirect(url_for('home_controller.logout', text=['warning', e.__str__()]))
def delete_files(): try: data = json.loads( urllib.parse.unquote(request.get_data('files').decode('utf-8'))) user = UserDAO.get( Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) data_entities = [] for name in data: data_entities.append(FileDAO.read(name, user.id)) FileDAO.delete(data_entities, user.home_catalog) return redirect(url_for('user_controller.index')) except Exception as e: return redirect(url_for('user_controller.index', error=e))
def index(error): user = UserDAO.get( Authentication.decode_auth_token(current_app.config['SECRET_KEY'], session['auth_token'])) try: login = user.login.split('@')[0] catalog = user.home_catalog files = FileDAO.get_all(user.id) current_year = datetime.datetime.now().year.__str__() return render_template('userPanel.html', user=login, home=catalog, files=files, year=current_year, error=error) except Exception as e: return redirect(url_for('home_controller.logout', error=e))
def queue_task(): try: user_id = Authentication.decode_auth_token( current_app.config['SECRET_KEY'], session['auth_token']) user = UserDAO.get(user_id) directory = os.path.join('Project/Client/static/DATA', user.home_catalog) task_name = secure_filename(request.form['taskName']) resolution = ast.literal_eval(request.form['resolutionSelect']) file = request.form['fileSelect'] if not any(x in os.listdir(directory) for x in [task_name, task_name + '.mp4']): with Connection(redis.from_url(current_app.config['REDIS_URL'])): q = Queue(default_timeout=3600) task = q.enqueue(raytracing_task, directory, resolution, file, task_name, result_ttl=86400) task.meta['task_name'] = task_name task.meta['file_name'] = file task.meta['token'] = Authentication.decode_auth_token( current_app.config['SECRET_KEY'], session['auth_token']) task.save_meta() response_object = { 'status': 'success', 'data': { 'task_id': task.get_id(), 'task_name': task_name, 'task_file': file } } return jsonify(response_object), 202 else: logging.getLogger('logger').warning('Filename already exists.') return jsonify('Filename already exists.'), 500 except Exception as e: logging.getLogger('error_logger').exception(e) return jsonify({'error': e.__str__()}), 500
def index(error): current_date = datetime.datetime.now().date().strftime('%B %d, %Y') likes = Format.human_format(likes_counter.value) current_year = datetime.datetime.now().year.__str__() login = None if 'auth_token' in session: error = None try: login = UserDAO.get( Authentication.decode_auth_token( current_app.config['SECRET_KEY'], session['auth_token'])).login.split('@')[0] except Exception as e: session.pop('auth_token', None) return redirect(url_for('home_controller.index', error=e)) return render_template('index.html', date=current_date, year=current_year, user=login, likes=likes, error=error)