def stats_restart(request): """ Delete statistics, we do drop table, not the recommended way but damn effective. """ from django.core import management from django.db import connection, models from django.core.management.color import no_style from django.core.management import sql cursor = connection.cursor() logger.info("stats restart") # this tables are not going to be deleted tables = [ "openproximity_bluetoothdongle", "openproximity_campaignfile", "openproximity_marketingcampaign", "openproximity_remotescannerbluetoothdongle", "openproximity_scannerbluetoothdongle", "openproximity_uploaderbluetoothdongle", "openproximity_generalsetting", "openproximity_userprofile", ] model = models.get_app("openproximity") drop = "" drop_table = sql.sql_delete(model, no_style(), connection) for line in drop_table: table_name = line.split()[2].replace('"', "").replace(";", "") if line.startswith("DROP TABLE"): # we don't want to loose settings if table_name not in tables: drop += "DROP TABLE %s;\n" % table_name elif line.find("CREATE INDEX") > -1: drop += "DROP INDEX %s;\n" % table_name try: server = rpyc.connect("localhost", 8010) server.root.Lock() logger.info("database locked") except: pass logger.info("about to drop") for line in drop.splitlines(): try: logger.debug(line) connection.cursor().execute(line) except Exception, err: logger.error("%s failed" % line) logger.exception(err)
def stats_restart(request): ''' Delete statistics, we do drop table, not the recommended way but damn effective. ''' from django.core import management from django.db import connection, models from django.core.management.color import no_style from django.core.management import sql cursor = connection.cursor() logger.info("stats restart") # this tables are not going to be deleted tables = [ 'openproximity_bluetoothdongle', 'openproximity_campaignfile', 'openproximity_marketingcampaign', 'openproximity_remotescannerbluetoothdongle', 'openproximity_scannerbluetoothdongle', 'openproximity_uploaderbluetoothdongle', 'openproximity_generalsetting', 'openproximity_userprofile' ] model = models.get_app('openproximity') drop = "" drop_table = sql.sql_delete(model, no_style(), connection) for line in drop_table: table_name = line.split()[2].replace('"', '').replace(';', '') if line.startswith('DROP TABLE'): # we don't want to loose settings if table_name not in tables: drop += "DROP TABLE %s;\n" % table_name elif line.find('CREATE INDEX') > -1: drop += "DROP INDEX %s;\n" % table_name try: server = rpyc.connect('localhost', 8010) server.root.Lock() logger.info("database locked") except: pass logger.info("about to drop") for line in drop.splitlines(): try: logger.debug(line) connection.cursor().execute(line) except Exception, err: logger.error("%s failed" % line) logger.exception(err)
from flask import Blueprint, render_template, flash, redirect, url_for from flask.globals import request from flask.helpers import send_file from flask_login import login_required, current_user from models import get_app, get_db, User, Follow, Course, Activity, ActivityUpload from module003.forms import * import ntpath import os from werkzeug.utils import secure_filename from flask import send_from_directory module003 = Blueprint("module003", __name__,static_folder="static",template_folder="templates") db = get_db() app = get_app() UPLOAD_FOLDER = 'module003/subidas' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER @module003.route('/', methods=['GET', 'POST']) @login_required def module003_index(): courses = None coursesCreated = Course.query.filter(Course.user_id == current_user.id).all() coursesFollowed = Follow.query.filter(Follow.user_id == current_user.id).all()
def get_app(request): id_app = request.match_info.get('id_app') app = models.get_app(id_app) json_app = str(app) return web.Response(body=json_app.encode('utf-8'))