class AuctionsManager: def __init__(self, app, database): db = SQLAlchemy(app) db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) self.database = db_session self.items = ItemsService(database=db_session) self.auctions = AuctionsService(database=db_session) def watch_auctions(self): """ Watches for auctions to complete, and marks the highest bid as won """ # Get all services whos ended field is still 0 and their end date has passed services = self.items.get_pending_services() for service in services: try: self.items.mark_service_ended(service.service_id) except: print('failed to update service') if service.winning_bid_id is not None: self.auctions.mark_bid_as_won(service.winning_bid_id) self.database.close() def start(self): schedule.every(5).seconds.do(self.watch_auctions) while True: schedule.run_pending() time.sleep(1)
class AuctionsManager: def __init__(self, app, database): db = SQLAlchemy(app) db_session = scoped_session( sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) self.database = db_session self.items = ItemsService(database=db_session) self.auctions = AuctionsService(database=db_session) def watch_auctions(self): """ Watches for auctions to complete, and marks the highest bid as won """ # Get all services whos ended field is still 0 and their end date has passed services = self.items.get_pending_services() for service in services: try: self.items.mark_service_ended(service.service_id) except: print('failed to update service') if service.winning_bid_id is not None: self.auctions.mark_bid_as_won(service.winning_bid_id) self.database.close() def start(self): schedule.every(5).seconds.do(self.watch_auctions) while True: schedule.run_pending() time.sleep(1)
def __init__(self, app, database): db = SQLAlchemy(app) db_session = scoped_session( sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) self.database = db_session self.items = ItemsService(database=db_session) self.auctions = AuctionsService(database=db_session)
def __init__(self, app, database): db = SQLAlchemy(app) db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db.engine)) self.database = db_session self.items = ItemsService(database=db_session) self.auctions = AuctionsService(database=db_session)
import bcrypt from flask import Blueprint, flash, render_template, redirect, request, session from templatesandmoe import db_session from templatesandmoe.modules.items.models import Item from templatesandmoe.modules.users.models import User from templatesandmoe.modules.users.service import UsersService from templatesandmoe.modules.items.service import ItemsService from templatesandmoe.modules.reporting.service import ReportingService from templatesandmoe.modules.admin.forms.user import UserForm adminModule = Blueprint('admin', __name__, url_prefix='/admin') users_service = UsersService(database=db_session) items_service = ItemsService(database=db_session) reporting_service = ReportingService(database=db_session) @adminModule.before_request def before_request(): # Make sure user is logged in and is an admin if session.get('user_id') and session['permission'] > 0: pass else: return redirect('/') @adminModule.route('/', methods=['GET']) def home(): return render_template('admin/home.html') @adminModule.route('/users', methods=['GET'])