def add_own_item(): form = AddForm() if form.validate_on_submit(): db_sess = db_session.create_session() new_item = Items(name=form.name.data, description=form.description.data, count=form.count.data, owner_id=current_user.id) db_sess.add(new_item) db_sess.commit() return redirect('own_items') return render_template('add_items.html', form=form)
def post(self): args = self.parser.parse_args() session = db_session.create_session() items = Items( title=args['title'], content=args['content'], user_id=args['user_id'], is_published=args['is_published'], is_private=args['is_private'] ) session.add(items) session.commit() return jsonify({'success': 'OK'})
def __init__(self, s_bar, root): self.rt = root self.sb = s_bar self.ntb = ttk.Notebook(self.rt) self.items_inst = Items() self.sales_inst = Sales() self.purchases_inst = Purchases() self.acc_inst = Accounts() self.management = Management() self.insts = { 'items': self.items_inst, 'sales': self.sales_inst, 'purchases': self.purchases_inst, 'accounts': self.acc_inst, 'management': self.management } # tabs self.t_home = THome(self.ntb, self.sb, self.insts) self.t_items = TItems(self.ntb, self.sb, self.insts) self.t_sales = TSales(self.ntb, self.sb, self.insts) self.t_purchases = TPurchases(self.ntb, self.sb, self.insts) self.t_accounts = TAccounts(self.ntb, self.sb, self.insts) self.t_graphs = TGraphs(self.ntb, self.sb, self.insts) self.tabs_inst = { 'main': self.ntb, 'home': self.t_home, 'items': self.t_items, 'sales': self.t_sales, 'purchases': self.t_purchases, 'accounts': self.t_accounts, 'graphs': self.t_graphs } self.t_management = TManagement(self.ntb, self.sb, self.insts, self.tabs_inst) self.ntb_w()
def add_items(): db_sess = db_session.create_session() if len(db_sess.query(Items).all()) != 0: return # Загружаем информацию о товарах из json файла with open('storage.json', 'r') as file: data = json.load(file) for i in data: item = Items() item.name = i['name'] item.description = i['description'] item.number = i['number'] item.price = i['price'] item.category_id = i['category_id'] db_sess.add(item) db_sess.commit()
def add_item(): if current_user.is_admin or current_user.is_approved: form = ItemsForm() if request.method == "POST": db_sess = db_session.create_session() db_sess.expire_on_commit = False item = Items() item.title = form.title.data item.content = form.content.data item.user = current_user item.need_upload = form.need_upload.data item.is_file = form.is_file.data item.is_private = form.is_private.data if form.need_upload.data and form.is_file.data and not form.uploaded.data: filename = form.uploaded_file.data.filename sfilename = secure_filename(filename) thread_id = None while True: thread_id = str(random.randint(0, 100000)) if not is_dict(exporting_threads, thread_id): break exporting_threads[thread_id] = Uploader( sfilename, form.uploaded_file.data.stream.read(), form.uploaded_file.data.stream.tell(), drive, app) exporting_threads[thread_id].start() form.uploaded_file.data.stream.close() item.uploaded_file_secured_name = sfilename item.uploaded_file_name = filename current_user.items.append(item) db_sess.merge(current_user) db_sess.commit() return thread_id elif form.need_upload.data and not form.is_file.data: item.file_link = form.file_link.data elif form.need_upload.data: filename = form.uploaded_filename.data sfilename = secure_filename(filename) item.uploaded_file_secured_name = sfilename item.uploaded_file_name = filename current_user.items.append(item) db_sess.merge(current_user) db_sess.commit() return render_template('add_item.html', title=_('Добавление записи'), form=form) else: abort(404)
class NtBook: def __init__(self, s_bar, root): self.rt = root self.sb = s_bar self.ntb = ttk.Notebook(self.rt) self.items_inst = Items() self.sales_inst = Sales() self.purchases_inst = Purchases() self.acc_inst = Accounts() self.management = Management() self.insts = { 'items': self.items_inst, 'sales': self.sales_inst, 'purchases': self.purchases_inst, 'accounts': self.acc_inst, 'management': self.management } # tabs self.t_home = THome(self.ntb, self.sb, self.insts) self.t_items = TItems(self.ntb, self.sb, self.insts) self.t_sales = TSales(self.ntb, self.sb, self.insts) self.t_purchases = TPurchases(self.ntb, self.sb, self.insts) self.t_accounts = TAccounts(self.ntb, self.sb, self.insts) self.t_graphs = TGraphs(self.ntb, self.sb, self.insts) self.tabs_inst = { 'main': self.ntb, 'home': self.t_home, 'items': self.t_items, 'sales': self.t_sales, 'purchases': self.t_purchases, 'accounts': self.t_accounts, 'graphs': self.t_graphs } self.t_management = TManagement(self.ntb, self.sb, self.insts, self.tabs_inst) self.ntb_w() def ntb_w(self): self.ntb.grid(column=0, row=0, sticky='NESW') self.ntb.bind("<<NotebookTabChanged>>", self._tabchanged) def select_tab(self, index): self.ntb.select(index) def _tabchanged(self, event=None): sel_tb = self.ntb.tab('current') self.sb.lb_left['text'] = "Current Tab: " + sel_tb['text'] _name = sel_tb['text'] if _name == 'Home': self.t_home.i_c.set_items(self.items_inst.get_all()) self.t_home.i_c.clear_all_items() elif _name == 'Items': self.t_items.i_main.all_items_works() elif _name == 'Sales': focus(self.t_sales.sales_main) elif _name == 'Purchases': focus(self.t_purchases.p_main) elif _name == 'Accounts': self.t_accounts.a_main.acc_ntb.select(0) self.t_accounts.a_main.t_assets.mf_ntb.select(0) focus(self.t_accounts.a_main.t_assets.t_debtors.debtors_main) elif _name == 'Graphs': self.t_graphs.g_main.selection() self.t_graphs.g_main.graph_it()
from flask import Flask, render_template, request, redirect from data import db_session from data.users import User from data.items import Items from flask_login import LoginManager, login_user, current_user from form.user import RegisterForm, LoginForm from form.items import AddForm, DelForm, AddRentForm app = Flask(__name__) app.config['SECRET_KEY'] = 'storage_yandex_secret_key' db_session.global_init("db/storage.db") login_manager = LoginManager() login_manager.init_app(app) items = Items() @login_manager.user_loader def load_user(user_id): db_sess = db_session.create_session() return db_sess.query(User).get(user_id) @app.route('/') @app.route('/index') def index(): return render_template('main.html') @app.route('/about') def about(): return render_template('about.html')