def create_app(): app = Flask(__name__, static_folder=r_path('static'), template_folder=r_path('templates')) if getattr(sys, 'frozen', False): basedir = os.path.dirname(sys.executable) else: basedir = os.path.abspath(os.path.dirname(__file__)) # bootstrap = Bootstrap(app) pagedown = PageDown(app) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + r_path( 'data.sqlite') # Autoreload if templates change app.config['TEMPLATES_AUTO_RELOAD'] = True # flask_upload settings # app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # Remove Upload limit. FIX ISSUE app.config['UPLOADED_FILES_DEST'] = r_path('static/multimedia') app.config['UPLOADED_FILES_ALLOW'] = mdal app.config['SECRET_KEY'] = os.urandom(24) # Intiating extensions before registering blueprints moment = Moment(app) qrc = QRcode(app) configure_uploads(app, files) login_manager.init_app(app) db.init_app(app) datepicker( app, local=['static/css/jquery-ui.min.css', 'static/jquery-ui.min.js']) colorpicker(app, local=['static/css/spectrum.css', 'static/spectrum.js']) fontpicker(app, local=[ 'static/jquery-ui.min.js', 'static/css/jquery-ui.min.css', 'static/webfont.js', 'static/webfont.select.js', 'static/css/webfont.select.css' ]) lessc(app) minify(app, js=True, cache=True, fail_safe=True, bypass=['/touch/<int:a>', '/serial/<int:t_id>', '/display']) gtts(app=app, route=True) gtranslator.init_app(app) # Register blueprints app.register_blueprint(administrate) app.register_blueprint(core) app.register_blueprint(cust_app) app.register_blueprint(errorsh_app) app.register_blueprint(manage_app) app.jinja_env.add_extension('jinja2.ext.loopcontrols') return app
def s_server(self): mip = self.slchange() self.P = rwser(mip[1].split(',')[1], mip[0], self.app) self.P.setTerminationEnabled(True) if not self.P.isRunning(): try: self.pport = mip[0] self.mbutton.setEnabled(False) self.mbutton2.setEnabled(True) self.sl.setEnabled(False) self.sl2.setEnabled(False) self.ic1 = QIcon(r_path(solve_path('static/images/play.png'))) self.ic1 = self.ic1.pixmap(70, 70, QIcon.Active, QIcon.On) self.l.setPixmap(self.ic1) pp = self.slchange() addr = self.getTrans('10') addr += "<a href='http://" addr += pp[1].split(',')[1] + ":" + pp[0] addr += "'> http://" + pp[1].split(',')[1] + ":" + pp[0] addr += "</a>" self.t.setText(addr) self.t.setFont(self.Arial) self.P.start() self.Runningo = True except: self.eout() else: self.eout()
def set_button(self, glo): hlayout = QHBoxLayout() self.mbutton = QPushButton('Start', self) self.mbutton.clicked.connect(self.s_server) self.mbutton.setFont(self.Arials) self.mbutton.setIcon(QPixmap(r_path(solve_path('static/images/play.png')))) self.mbutton2 = QPushButton('Stop', self) self.mbutton2.clicked.connect(self.st_server) self.mbutton2.setIcon(QPixmap(r_path(solve_path('static/images/pause.png')))) self.mbutton.setToolTip(self.getTrans('4')) self.mbutton2.setToolTip(self.getTrans('6')) self.mbutton2.setEnabled(False) self.mbutton2.setFont(self.Arials) hlayout.addWidget(self.mbutton) hlayout.addWidget(self.mbutton2) glo.addLayout(hlayout)
def csvd(t_name): """ to export tables to .csvd file """ if current_user.role_id != 1: flash('Error: only administrator can access the page', 'danger') return redirect(url_for('core.root')) form = forms.CSV(session.get('lang')) t_ids = ['User', 'Office', 'Task', 'Serial', 'Waiting', 'Roles'] if t_name in t_ids: t_name = eval('data.' + t_name) fn = 'csvd.csv' ffn = r_path(fn) of = open(ffn, 'w+') outcsv = csv.writer(of) outcsv.writerow([ column.name for column in t_name.__mapper__.columns if column.name != 'password_hash' ]) [ outcsv.writerow([ getattr(curr, column.name) for column in t_name.__mapper__.columns if column.name != 'password_hash' ]) for curr in t_name.query.all() ] of.close() return send_file(ffn, mimetype='csv', as_attachment=True) elif t_name != '0': flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if form.validate_on_submit(): return redirect(url_for('administrate.csvd', t_name=form.table.data)) return render_template('csvs.html', navbar='#snb3', ptitle='Export CSV', form=form)
def multi_del(f_id): """ to delete multimedia file """ if current_user.role_id != 1: flash('Error: only administrator can access the page', "danger") return redirect(url_for('core.root')) dire = r_path('static/multimedia/') if data.Media.query.filter_by(used=False).count() <= 0: flash("Error: there is no unused multimedia file to be removed !", "danger") return redirect(url_for('cust_app.multimedia', aa=1)) if f_id == 00: for a in data.Media.query: if not a.used: if os.path.exists(dire + a.name): os.remove(dire + a.name) db.session.delete(a) db.session.commit() flash("Notice: multimedia file been removed.", "info") return redirect(url_for('cust_app.multimedia', aa=1)) mf = data.Media.query.filter_by(id=f_id).first() if mf is not None: if mf.used: flash("Error: there is no unused multimedia file to be removed !", "danger") return redirect(url_for('cust_app.multimedia', aa=1)) if os.path.exists(dire + mf.name): os.remove(dire + mf.name) db.session.delete(mf) db.session.commit() flash("Notice: multimedia file been removed.", "info") return redirect(url_for('cust_app.multimedia', aa=1)) else: flash("Error: there is no unused multimedia file to be removed !", "danger") return redirect(url_for('core.root'))
def Flabel(self, glo): fontt = self.Arial self.ic1 = QIcon(r_path(solve_path('static/images/pause.png'))) self.l = QLabel('Icond', self) self.ic1 = self.ic1.pixmap(70, 70, QIcon.Active, QIcon.On) self.l.setPixmap(self.ic1) self.l.setAlignment(Qt.AlignCenter | Qt.AlignHCenter) self.l.setFont(fontt) self.t = QLabel('Texted', self) self.t.setText(self.getTrans('11')) self.t.setOpenExternalLinks(True) self.t.setAlignment(Qt.AlignCenter | Qt.AlignHCenter) self.t.setFont(fontt) self.t.setToolTip(self.getTrans('9')) self.l.setToolTip(self.getTrans('9')) glo.addStretch() glo.addWidget(self.l) glo.addWidget(self.t) glo.addStretch()
def __init__(self, app=None): super(NewWindow, self).__init__() self.app = app glo = QVBoxLayout(self) icp = r_path(solve_path('static/images/favicon.png')) # need to used objective message boxs instead of functions to set font self.Arial = QFont("", 12, QFont.Bold) self.Arials = QFont("", 10, QFont.Bold) # Language support variable self.Language = 'en' self.Runningo = False icon = QIcon(icp) self.SelfIinit(icon) self.center() self.langsList(glo) self.set_Abutton(icp, glo) self.Lists(glo) self.Flabel(glo) self.set_button(glo) self.setLayout(glo) mip = self.slchange() self.P = rwser(mip[1].split(',')[1], mip[0], self.app) self.activateWindow() self.show()
def printit_ar(pname, ti, ofc, tnu, tas, cticket): def fsizeit(text, t, f): ltxt = "A" * len(t) return f.getsize(t) def center(text, t, f): fs1, fs2 = fsizeit(text, t, f) return ((text.size[0] - fs1) / 2, (text.size[1] - fs2) / 2) if name == 'nt': fpath = r_path('static\\gfonts\\arial.ttf') else: fpath = r_path('static/gfonts/arial.ttf') fonts = [ ImageFont.truetype(fpath, 50), ImageFont.truetype(fpath, 30), ImageFont.truetype(fpath, 25) ] logo = 'FQM ' + version[:4] title = u'نظام إدارة الحشود الحر' title = arabic_reshaper.reshape(title) title = get_display(title) link = 'http://fqms.github.io' border = "#" * 20 ticket = str(ti) officet = u'المكتب : ' + ofc office = arabic_reshaper.reshape(officet) office = get_display(office) try: taskt = u'المهمة : ' + tas except: taskt = tas task = arabic_reshaper.reshape(taskt) task = get_display(task) datet = u'الوقت : ' datet += str(datetime.now())[:-7] date = arabic_reshaper.reshape(datet) date = get_display(date) aheadt = u'تذاكر قبلك : ' aheadt += str(tnu) ahead = arabic_reshaper.reshape(aheadt) ahead = get_display(ahead) cutit = u'التذكرة الحالية : ' cutit += str(cticket) cuti = arabic_reshaper.reshape(cutit) cuti = get_display(cuti) w = 400 bt_1 = Image.new('RGB', (w, 60), "white") bt_2 = Image.new('RGB', (w, 60), "white") bt_3 = Image.new('RGB', (w, 60), "white") st_1 = Image.new('RGB', (w, 50), "white") st_2 = Image.new('RGB', (w, 50), "white") st_3 = Image.new('RGB', (w, 50), "white") st_4 = Image.new('RGB', (w, 50), "white") st_5 = Image.new('RGB', (w, 50), "white") st_6 = Image.new('RGB', (w, 50), "white") st_7 = Image.new('RGB', (w, 50), "white") st_8 = Image.new('RGB', (w, 50), "white") tt = 50 * 8 tt += 60 * 3 mt = Image.new('RGB', (w, tt), "white") bd_1 = ImageDraw.Draw(bt_1) bd_2 = ImageDraw.Draw(bt_2) bd_3 = ImageDraw.Draw(bt_3) sd_1 = ImageDraw.Draw(st_1) sd_2 = ImageDraw.Draw(st_2) sd_3 = ImageDraw.Draw(st_3) sd_4 = ImageDraw.Draw(st_4) sd_5 = ImageDraw.Draw(st_5) sd_6 = ImageDraw.Draw(st_6) sd_7 = ImageDraw.Draw(st_7) sd_8 = ImageDraw.Draw(st_8) md = ImageDraw.Draw(mt) b = "black" bd_1.text(center(bt_1, logo, fonts[0]), logo, font=fonts[0], fill=b) bd_2.text(center(bt_2, title, fonts[1]), title, font=fonts[1], fill=b) bd_3.text(center(bt_3, ticket, fonts[0]), ticket, font=fonts[0], fill=b) sd_1.text(center(st_1, link, fonts[2]), link, font=fonts[2], fill=b) sd_2.text(center(st_2, border, fonts[2]), border, font=fonts[2], fill=b) sd_3.text(center(st_3, border, fonts[2]), border, font=fonts[2], fill=b) sd_4.text(center(st_4, office, fonts[2]), office, font=fonts[2], fill=b) sd_5.text(center(st_5, task, fonts[2]), task, font=fonts[2], fill=b) sd_6.text(center(st_6, date, fonts[2]), date, font=fonts[2], fill=b) sd_7.text(center(st_7, ahead, fonts[2]), ahead, font=fonts[2], fill=b) sd_8.text(center(st_8, cuti, fonts[2]), cuti, font=fonts[2], fill=b) tts = 0 mt.paste(bt_1, (0, 0)) tts += bt_1.size[1] mt.paste(bt_2, (0, tts)) tts += bt_2.size[1] mt.paste(st_1, (0, tts)) tts += st_1.size[1] mt.paste(st_2, (0, tts)) tts += st_2.size[1] mt.paste(bt_3, (0, tts)) tts += bt_3.size[1] mt.paste(st_3, (0, tts)) tts += st_3.size[1] mt.paste(st_4, (0, tts)) tts += st_4.size[1] mt.paste(st_8, (0, tts)) tts += st_8.size[1] mt.paste(st_7, (0, tts)) tts += st_7.size[1] mt.paste(st_5, (0, tts)) tts += st_5.size[1] mt.paste(st_6, (0, tts)) iname = 'dummy.jpg' finame = path.join(getcwd(), iname) mt.save(iname, format="JPEG") pname.image(iname, fragment_height=tt, high_density_vertical=True) pname.cut() pname.close() if path.isfile(finame): remove(finame)
def multimedia(aa): """ uploading multimedia files """ # Number of files limit nofl = 300 # size folder limit in MB sfl = 2000 # Fix limited upload folder size if current_user.role_id != 1: flash('Error: only administrator can access the page', "danger") return redirect(url_for('core.root')) ex_functions.mse() dire = r_path('static/multimedia/') pf = data.Media.query.order_by(data.Media.id.desc()).first() if pf is not None: pf = pf.name if aa == 0: if data.Media.query.count() >= nofl: flash( "Error: you have reached the amount limit of multimedia files " + str(nofl), "danger") return redirect(url_for('cust_app.multimedia', aa=1)) else: flash( "Notice: if you followed the rules, it should be uploaded ..", "success") elif aa != 1: flash('Error: wrong entry, something went wrong', "danger") return redirect(url_for("core.root")) mmm = data.Media.query page = request.args.get('page', 1, type=int) if page > int(data.Media.query.count() / 10) + 1: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('cust_app.multimedia', aa=1)) pagination = data.Media.query.paginate(page, per_page=10, error_out=False) form = forms.Multimedia(session.get('lang')) if mmm.count() >= 1: from sqlalchemy.sql import or_ for me in mmm: if os.path.isfile(dire + me.name): dl = [ data.Display_store.query.filter( or_(data.Display_store.ikey == me.id, data.Display_store.akey == me.id)).first(), data.Touch_store.query.filter( or_(data.Touch_store.ikey == me.id, data.Touch_store.akey == me.id)).first(), data.Slides.query.filter_by(ikey=me.id).first(), data.Vid.query.filter_by(vkey=me.id).first() ] me.used = False for d in dl: if d is not None: me.used = True break db.session.add(me) db.session.commit() else: if me.img or me.audio or me.vid: for t in [ data.Touch_store, data.Display_store, data.Slides ]: t = t.query.filter_by( or_(data.Display_store.ikey == me.id, data.Display_store.vkey == me.id)).first() if me.img or me.vid and t is not None: if me.img: t.ikey = None if me.vid: t.vid = None if t != data.Slides: t.bgcolor = "bg-danger" else: t.bgname = "bg-danger" db.session.add(t) ttt = t.query.filter_by(akey=me.id).first() if me.audio and ttt is not None: if t != data.Slides: t.akey = None t.audio = "false" db.session.add(t) db.session.delete(me) db.session.commit() if form.validate_on_submit(): ff = form.mf.data ffn = secure_filename(ff.filename) dc = data.Media.query.count() # FIX ISSUE Remove folder size limitation # if int(ex_functions.getFolderSize(dire)) >= sfl or dc >= nofl: # return redirect(url_for('cust_app.multimedia', aa=1)) e = ffn[-3:len(ffn)] if e in mdal[0]: files.save(request.files['mf'], name=ffn) if imghdr.what(dire + ffn) is None: os.remove(dire + ffn) return redirect(url_for("cust_app.multimedia", aa=1)) db.session.add(data.Media(False, False, True, False, ffn)) db.session.commit() return redirect(url_for("cust_app.multimedia", aa=1)) elif e in mdal[1]: files.save(request.files['mf'], name=ffn) if sndhdr.what(dire + ffn) is None: os.remove(dire + ffn) return redirect(url_for("cust_app.multimedia", aa=1)) db.session.add(data.Media(False, True, False, False, ffn)) db.session.commit() return redirect(url_for("cust_app.multimedia", aa=1)) elif e in mdal[2]: files.save(request.files['mf'], name=ffn) db.session.add(data.Media(True, False, False, False, ffn)) db.session.commit() return redirect(url_for("cust_app.multimedia", aa=1)) else: flash('Error: wrong entry, something went wrong', "danger") return redirect(url_for("cust_app.multimedia", aa=1)) return render_template("multimedia.html", ptitle="Multimedia", navbar="#snb2", form=form, hash="#da1", mmm=mmm, len=len, ml=mdal, mmmp=pagination.items, pagination=pagination, tc=data.Touch_store.query, sl=data.Slides.query, dc=data.Display_store.query, fs=int(ex_functions.getFolderSize(dire)), nofl=nofl, sfl=sfl, vtrue=data.Vid.query.first().enable, strue=data.Slides_c.query.first().status)