def initUI(self): self.setLayout( HorizontalBoxLayout(self, "main", margins=(0,0,0,0), contents=[ HorizontalSplitter(owner=self, name="viewSplitter", contents=[ Custom( owner=self, name="imageViewer", widget=ImageView() ), ScrollArea( owner=self, name="controlPanel", horizontalScrollBarPolicy=QtCore.Qt.ScrollBarAlwaysOff, verticalScrollBarPolicy=QtCore.Qt.ScrollBarAsNeeded, widgetIsResizable=True, innerWidget= StackedWidget(owner=self, name="editPanel", widgets=[ Custom( owner=self, name="EditPanelGlobalView", widget=EditPanelGlobalView(self) ), Custom( owner=self, name="EditPanelLeadView", widget=EditPanelLeadView(self) ) ]) ) ]) ]) ) self.viewSplitter.setCollapsible(0,False) self.viewSplitter.setCollapsible(1,False) self.viewSplitter.setSizes([2,1]) self.editPanel.setCurrentIndex(0) # Constraint the width of the adjustable side panel on the right of the editor self.controlPanel.setMinimumWidth(250) self.controlPanel.setMaximumWidth(450)
@login_manager.user_loader def load_user(user_id): return db.session.query(User).get(user_id) # Initialize flask-login init_login() admin = Admin(app, name='Юг Строй Окно', index_view=MyAdminIndexView(), base_template='home.html') admin.add_view(MyModelView(Contact, db.session, 'Контакты')) admin.add_view(MyModelView(ProductCategory, db.session, 'Категории')) admin.add_view(ImageView(Product, db.session, 'Товары')) db.init_app(app) if __name__ == '__main__': app.run() @listens_for(Product, 'after_delete') def del_image(mapper, connection, target): if target.path: # Delete image try: os.remove(op.join(file_path, target.path)) except OSError: pass
def create_app(): app = Flask(__name__) app.config.from_pyfile('settings.py') db.init_app(app) admin = Admin(app, name='Giwangan', template_mode='bootstrap3', index_view=SecuredHomeView()) admin.add_view(PageModelView(Page, db.session)) admin.add_view(MenuModelView(Menu, db.session)) admin.add_view(UserModelView(User, db.session)) admin.add_view(RoleModelView(Role, db.session)) admin.add_view(SiteConfigurationView(SiteConfiguration, db.session)) admin.add_view(ImageView(Image, db.session)) admin.add_view(ModelView(AdsenseType, db.session)) admin.add_view(ModelView(AdsenseCode, db.session)) admin.add_view(ModelView(PageState, db.session)) user_datastore = SQLAlchemyUserDatastore(db, User, Role) security = Security(app, user_datastore) @app.before_first_request def init_vars(): #TODO improve for multisite siteconfiguration = SiteConfiguration.query.filter_by(id=1).first() if siteconfiguration is not None: global_vars.SITE_NAME = siteconfiguration.name global_vars.SITE_TAGLINE = siteconfiguration.tagline global_vars.SHOW_REGISTRATION_MENU = siteconfiguration.show_registration_menu global_vars.YOUTUBE_LINK = siteconfiguration.youtube_link global_vars.GA_TRACKING_CODE = siteconfiguration.ga_tracking_code global_vars.DESCRIPTION = siteconfiguration.description #page level ads ads = db.session.query(AdsenseCode).join(AdsenseType).filter( AdsenseType.name == 'Page-level Ads').first() if ads is not None: global_vars.ADSENSE_PAGELEVEL_CODE = ads.code #inapp ads ads = db.session.query(AdsenseCode).join(AdsenseType).filter( AdsenseType.name == 'In-article Ads').first() if ads is not None: global_vars.ADSENSE_INAPP_ARTICLE_CODE = ads.code # infeed ads = db.session.query(AdsenseCode).join(AdsenseType).filter( AdsenseType.name == 'In-feed Ads').first() if ads is not None: global_vars.ADSENSE_INFEED_CODE = ads.code # header ads = db.session.query(AdsenseCode).join(AdsenseType).filter( AdsenseType.name == 'Header Ads').first() if ads is not None: global_vars.ADSENSE_HEADER = ads.code # footer ads = db.session.query(AdsenseCode).join(AdsenseType).filter( AdsenseType.name == 'Footer Ads').first() if ads is not None: global_vars.ADSENSE_FOOTER = ads.code @app.route('/') @app.route('/<uri>') def index(uri=None): import importlib if uri is None: page = Page.query.filter_by(is_homepage=True).first() else: page = Page.query.filter(Page.url == uri).first() menus = Menu.query.order_by('order') if page is None: return uri else: views_ = importlib.import_module('web_app.apps.{}.views'.format( page.subtype)) content = views_.process(page) og = views_.get_og(page) return render_template('index.html', global_vars=global_vars, content=content, menus=menus, og=og, page=page) @app.route('/register', methods=['GET', 'POST']) @anonymous_user_required def register(): return flask_security.views.register() @app.template_filter('friendly_time') def friendly_time(date): # humanize.i18n.activate('in_ID') return humanize.naturaltime(date) @app.template_filter('friendly_number') def friendly_number(n): return number.intword(n) return app