Esempio n. 1
0
def add_category():
    if 'username' in session:
        error = {}
        val = {}
        if request.method == 'POST':

            title = request.form['title']
            val['title'] = title
            file_uploads = ''
            if title == "":
                error['h'] = "title is empty"

            if request.files:
                file_uploads = request.files['image']

            else:
                error['file_error'] = "Image is empty"
            if len(error) == 0:
                name = ""
                if file_uploads:
                    name = file_upload(cat.config['UPLOAD_FOLDER'],
                                       file_uploads)
                    print(name)
                try:
                    my_db.connection()
                    sql = "insert into category_tbl(title,image,created_date,modified_date) value(%s,%s,%s,%s)"
                    val = (
                        title,
                        name,
                        str(datetime.now()),
                        str(datetime.now()),
                    )
                    my_db.cur.execute(sql, val)
                    my_db.conn.commit()

                    flash('Category has been added successfully!')
                    return redirect(url_for('cat_manager.category_list'))
                except Exception as err:
                    print(err)
                    my_db.conn.rollback()
                finally:
                    my_db.conn.close()

        return render_template('category-manager/add-category.html',
                               sec=session['username'],
                               error=error,
                               val=val)
    return render_template('homepages/login.htm')
Esempio n. 2
0
def add_slider():
    if 'username' in session:
        error = {}
        val = {}
        if request.method == 'POST':
            title = request.form['title']
            ck = request.form['ck']
            val['title'] = title
            fileupload = ''

            if title == "":
                error['h'] = "Title is empty"

            if request.files:
                fileupload = request.files['image']
            else:
                error['im']="Images is empty"

            if len(error) == 0:
                image = ""
               
                if fileupload:
                    image = file_upload(sld.config['UPLOAD_FOLDER'], fileupload)

                try:

                    my_db.connection()
                    sql = "insert into slider_tbl(title,image,status," \
                          "created_date,modified_date)" \
                          " value(%s,%s,%s,%s,%s)"
                    val = (title,  image, ck,  str(datetime.now()), str(datetime.now()),)
                    my_db.cur.execute(sql, val)
                    my_db.conn.commit()

                    flash('Slider has been added successfully!')
                    return redirect(url_for('sld_manager.silder_list'))

                except mysql.connector.Error as err:
                    print(err)
                    my_db.conn.rollback()
                finally:
                    my_db.conn.close()
        return render_template('/slider-manager/add-slider.html', error=error,
                               sec=session['username'], val=val)
    return render_template('homepages/login.htm')
Esempio n. 3
0
def add_article():
    if 'username' in session:
        myresult = category()
        error = {}
        val = {}
        if request.method == 'POST':
            title = request.form['title']
            ck = request.form['ck']
            decs = request.form['decs']
            cat_id = request.form['cat_id']

            val['title'] = title
            val['decs'] = decs

            fileupload = ''
            files = ""

            if title == "":
                error['h'] = "Title is empty"
            if decs == "":
                error['decs'] = "Description is empty"

            if 'image' in request.files:
                fileupload = request.files['image']

            else:
                error['img_error'] = "Image is empty"

            if 'f_load' in request.files:
                files = request.files['f_load']
            else:
                error['file_error'] = "File is empty"

            if len(error) == 0:
                image = ""
                file = ""
                if fileupload:
                    image = file_upload(art.config['UPLOAD_FOLDER'],
                                        fileupload)

                if files:
                    file = file_upload(art.config['UPLOAD_FOLDER'], files)

                try:

                    my_db.connection()
                    sql = "insert into article_tbl(title,description,image,status," \
                          "created_date,modified_date,file_upload, categary_id)" \
                          " value(%s,%s,%s,%s,%s,%s,%s,%s)"
                    val = (title, decs, image, ck, str(datetime.now()),
                           str(datetime.now()), file, cat_id)
                    my_db.cur.execute(sql, val)

                    my_db.conn.commit()
                    flash('Article has been added successfully!')
                    return redirect(url_for('art_manager.article_list'))

                except Exception as err:
                    print(err)
                    my_db.conn.rollback()
                finally:
                    my_db.conn.close()

        return render_template('/article-manager/add-article.html',
                               error=error,
                               myresults=myresult,
                               sec=session['username'],
                               val=val)
    return render_template('homepages/login.htm')
Esempio n. 4
0
def edit():
    if 'username' in session:

        id = request.args.get('id')
        myresult = ''
        old_image = ''
        old_file = ''
        try:
            my_db.connection()
            sql = "SELECT * FROM article_tbl WHERE  id =%s"
            val = (id, )
            my_db.cur.execute(sql, val)
            myresult = my_db.cur.fetchone()
            if myresult is not None:
                old_image = myresult['image']
                old_file = myresult['file_upload']

            my_db.conn.commit()
        except Exception as err:
            print(err)
            my_db.conn.rollback()

        finally:
            my_db.conn.close()

        error = {}
        if request.method == 'POST':

            title = request.form['title']
            ck = request.form['ck']
            decs = request.form['decs']
            cat_id = request.form['cat_id']
            flag = False
            flag_file = False
            fileuploads = ''
            files_doc = ""

            if title == "":
                error['title'] = "Title is empty"

            if decs == "":
                error['decs'] = "Description is empty"
            if request.files:
                for d in request.files:
                    if d == 'image':
                        fileuploads = request.files['image']
                        flag = True
                    if d == 'f_load':
                        files_doc = request.files['f_load']
                        flag_file = True

            if len(error) == 0:
                image = ""
                file_name = ""
                if fileuploads and flag:
                    image = file_upload(art.config['UPLOAD_FOLDER'],
                                        fileuploads)

                if files_doc and flag:
                    file_name = file_upload(art.config['UPLOAD_FOLDER'],
                                            files_doc)

                try:
                    my_db.connection()
                    if flag and not flag_file:

                        sql = "update article_tbl set title=%s ,image=%s, description=%s, status=%s, " \
                            "modified_date=%s, categary_id=%s where id=%s"
                        val = (
                            title,
                            image,
                            decs,
                            ck,
                            str(datetime.now()),
                            cat_id,
                            id,
                        )
                        delete(art.config['UPLOAD_FOLDER'], old_image)

                    elif flag_file and not flag:

                        sql = "update article_tbl set title=%s , description=%s, status=%s, modified_date=%s ," \
                            " file_upload=%s,categary_id=%s where id=%s"
                        val = (
                            title,
                            decs,
                            ck,
                            str(datetime.now()),
                            file_name,
                            cat_id,
                            id,
                        )
                        delete(art.config['UPLOAD_FOLDER'], old_file)

                    elif flag and flag_file:

                        sql = "update article_tbl set title=%s , description=%s,image=%s, status=%s," \
                            " modified_date=%s, file_upload=%s,categary_id=%s where id=%s"
                        val = (
                            title,
                            decs,
                            image,
                            ck,
                            str(datetime.now()),
                            file_name,
                            cat_id,
                            id,
                        )
                        delete(art.config['UPLOAD_FOLDER'], old_image)
                        delete(art.config['UPLOAD_FOLDER'], old_file)

                    else:
                        if 'pt' in request.form and request.form['pt'] == 'on':

                            delete(art.config['UPLOAD_FOLDER'], old_image)
                        if 'pt_file' in request.form and request.form[
                                'pt_file'] == 'on':

                            delete(art.config['UPLOAD_FOLDER'], old_file)


                        sql = "update article_tbl set title=%s , description=%s, status=%s, " \
                            "modified_date=%s, categary_id=%s where id=%s"
                        val = (
                            title,
                            decs,
                            ck,
                            str(datetime.now()),
                            cat_id,
                            id,
                        )

                    my_db.cur.execute(sql, val)
                    my_db.conn.commit()

                    flash('Article has been updated successfully!')
                    return redirect(url_for('art_manager.article_list'))
                except Exception as err:
                    print(err)
                    my_db.conn.rollback()
                finally:
                    my_db.conn.close()
        return render_template('/article-manager/edit-article.html',
                               error=error,
                               sec=session['username'],
                               category=category(),
                               myresults=myresult)
    return render_template('homepages/login.htm')
Esempio n. 5
0
def edit():
    if 'username' in session:
        id = request.args.get('id')
        myresult = ""
        old_image = ""
        try:
            my_db.connection()
            sql = "SELECT * FROM category_tbl  WHERE  id =%s"
            val = (id, )
            my_db.cur.execute(sql, val)
            myresult = my_db.cur.fetchone()
            if myresult is not None:
                old_image = myresult['image']

        except ValueError as err:
            print(err)
            my_db.conn.rollback()
        finally:
            my_db.conn.close()

        error = {}
        if request.method == 'POST':
            error = {}
            flag = False

            title = request.form['title']

            file_uploads = ''
            if title == "":
                error['h'] = "title is empty"

            if request.files:
                file_uploads = request.files['image']
                flag = True

            if len(error) == 0:
                name = ""
                if file_uploads:
                    name = file_upload(cat.config['UPLOAD_FOLDER'],
                                       file_uploads)
                try:
                    my_db.connection()
                    if flag:

                        sql = "update category_tbl set title=%s,image=%s,modified_date=%s WHERE  id =%s"
                        val = (
                            title,
                            name,
                            str(datetime.now()),
                            id,
                        )
                        delete(cat.config['UPLOAD_FOLDER'], old_image)
                    else:

                        if 'pt' in request.form and request.form['pt'] == 'on':
                            delete(cat.config['UPLOAD_FOLDER'], old_image)

                        sql = "update category_tbl set title=%s,image=%s,modified_date=%s WHERE  id =%s"
                        val = (
                            title,
                            name,
                            str(datetime.now()),
                            id,
                        )
                        if request.form['pt']:

                            delete(cat.config['UPLOAD_FOLDER'], old_image)

                        else:
                            sql = "update category_tbl set title=%s,modified_date=%s WHERE  id =%s"
                            val = (
                                title,
                                str(datetime.now()),
                                id,
                            )

                    my_db.cur.execute(sql, val)
                    my_db.conn.commit()

                    flash('Category has been added successfully!')
                    return redirect(url_for('cat_manager.category_list'))
                except Exception as err:
                    print(err)
                    my_db.conn.rollback()
                finally:
                    my_db.conn.close()
        return render_template('category-manager/edit-category.html',
                               sec=session['username'],
                               error=error,
                               myresults=myresult)
    return render_template('homepages/login.htm')
Esempio n. 6
0
 def upload(self, usr, group, file_name, txt):
     info = file_upload(usr, group, file_name, txt)
     return info
Esempio n. 7
0
def edit():
    if 'username' in session:

        id = request.args.get('id')
        myresult = ''
        old_image = ''
        try:
            my_db.connection()
            sql = "SELECT * FROM slider_tbl WHERE  id =%s"
            val = (id,)
            my_db.cur.execute(sql, val)

            myresult = my_db.cur.fetchone()
            if myresult is not None:
                old_image = myresult['image']
            my_db.conn.commit()

        except mysql.connector.Error as err:
            print(err)
            my_db.conn.rollback()

        finally:
            my_db.conn.close()

        error = {}
        if request.method == 'POST':
            
            title = request.form['title']
            ck = request.form['ck']
            flag = False

            fileuploads = ''

            if title == "":
                error['title'] = "Title is empty"

            if request.files:
                fileuploads = request.files['image']
                flag = True
            
            if len(error) == 0:
                image = ""
              
                if fileuploads and flag:
                    
                    image = file_upload(sld.config['UPLOAD_FOLDER'], fileuploads)
                try:
                    my_db.connection()
                   
                    if flag:
                        
                        sql = "update slider_tbl set title=%s ,image=%s, status=%s, " \
                            "modified_date=%s where id=%s"
                        val = (title, image,  ck, str(datetime.now()), id,)
                        delete(sld.config['UPLOAD_FOLDER'],old_image)

                    else:

                        if 'pt' in request.form and request.form['pt'] == 'on':
                            delete(sld.config['UPLOAD_FOLDER'], old_image)

                        sql = "update slider_tbl set title=%s , status=%s, " \
                            "modified_date=%s where id=%s"
                        val = (title,  ck, str(datetime.now()),  id,)

                    my_db.cur.execute(sql, val)
                    my_db.conn.commit()

                    flash('Slider has been updated successfully!')
                    return redirect(url_for('sld_manager.silder_list'))
                except mysql.connector.Error as err:
                    print(err)
                    my_db.conn.rollback()
                finally:
                    my_db.conn.close()
            print(len(myresult))
        return render_template('/slider-manager/edit-slider.html', error=error, sec=session['username'],
                               myresults=myresult)
    return render_template('homepages/login.htm')
Esempio n. 8
0
 def upload(self, username, file_name, txt):
     info = file_upload(username, file_name, txt)
     return info