Example #1
0
def add_category():
    error = {}
    val = {}
    if request.method == 'POST':

        title = request.form['title']
        print("here $$$$", title)
        t = slugify(title)

        if title == '':
            error['t_er'] = "no title"
        val['title'] = title

        file_upload = ""
        img_upload = ""
        if request.files:
            file_upload = request.files['image']

        else:
            error['file_upload_error'] = "Image is not selected"
        if file_upload:
            new_file = file_upload.filename.split('.')
            file_upload.filename = "image" + str(
                datetime.now()) + "." + new_file[-1]

            img_upload = file_upload.filename

            f = os.path.join(cat.config['UPLOAD_FOLDER'], file_upload.filename)
            file_upload.save(f)

            print(f)

        if len(error) != 0:
            return render_template('add_category.html', error=error)
        else:
            try:
                print("hellooo this coming")
                country_database.connects()
                sql = "INSERT INTO category_manager(title, image, created_date, modified_date) VALUES (%s, %s, %s, %s)"
                print("hellooo this coming")
                print("i am after sql")
                value = (t, img_upload, str(datetime.now()),
                         str(datetime.now()))

                print(title)
                country_database.cur.execute(sql, value)
                country_database.conn.commit()
                return redirect(url_for('cat_manager.cat_list'))
            except:
                country_database.conn.rollback()
            finally:
                country_database.conn.close()
    else:
        return render_template('add_category.html', error=error, val=val)
    return redirect(url_for('cat_manager.cat_list'))
Example #2
0
def add_page():

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

        slug = request.form['slug']
        s = slugify(slug)

        decs = request.form['decs']
        if title == "":
            error['a'] = "title is required"
        if decs == "":
            error['b'] = "description is required"

        if len(error) == 0:

            try:
                country_database.connects()

                sql = "INSERT INTO page_manager (title, slug, description) VALUES(%s, %s, %s)"
                val = (
                    title,
                    s,
                    decs,
                )

                country_database.cur.execute(sql, val)
                country_database.conn.commit()
                return redirect(url_for('page_manager.list_page'))
            except Exception as err:
                print(err)
                country_database.conn.rollback()
            finally:
                country_database.conn.close()

    return render_template('page_manager.html')
Example #3
0
def add_article():
    error={}
    myresult=""
    fileupload=""
    user_id = session['user']['id']
    print(user_id)
    try:
        country_database.connects()
        sql = "SELECT * FROM category_manager "
        country_database.cur.execute(sql)
        myresult = country_database.cur.fetchall()

    except:
        country_database.conn.rollback()
    finally:
        country_database.conn.close()


    if request.method=="POST":

        title = request.form['title']

        slug=request.form['title']
        s = slugify(slug)
        print(s)
        description = request.form['summernote']
        status = request.form['ck']

        cat_id = request.form['cat_id']

        if title=="":
            error['tt']="title is required"
        if slug=="":
             error['b']="slug is required"
        if description=="":
            error['c'] = "please enter some description"

        if cat_id=='':
            error['e']="select category id"

        print(request.files)
        if request.files:
            # file_upload = request.files['image']


            fileupload = request.files['image']
            if fileupload and allowed_file(fileupload.filename):
                    filename = secure_filename(fileupload.filename)

                    fileupload.save(os.path.join(art.config['UPLOAD_FOLDER'], filename))
                    image=fileupload.filename
        else:
            error['as']="image not selected"
        



        try:
            country_database.connects()
            t = str(datetime.now())

            # y = t.strftime("%y") + "-" + t.strftime("%b") + "-" + t.strftime("%d")
            print("here is date time format")

            print(user_id)
            s=slugify(slug)
            sql = "insert into article_manager(title,slug,description,file,category_id ," \
                  "status ,created_date,modified_date,user_id)" \
                  " value(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
            val=(title, s, description,image,cat_id,status, t,t,user_id,)
            print(val)
            # user_id=session['user'['id']]

            country_database.cur.execute(sql,val)
            country_database.conn.commit()
            return redirect(url_for('article_manager_reg.list_article'))



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

    return render_template("article_manager.html", error=error,myresult=myresult)
Example #4
0
def edit_article():

    myresult=""
    files=""
    error={}
    record=""
    oldimage=""
    id = request.args.get('id')

    record=''
    try:
        print("fsdijdfsjidfsj")
        country_database.connects()
        sql = "SELECT * FROM category_manager "
        country_database.cur.execute(sql)
        myresult = country_database.cur.fetchall()
        country_database.conn.commit()


        sql="SELECT * from article_manager WHERE  id =%s"
        val=(id,)
        country_database.cur.execute(sql,val)

        record=country_database.cur.fetchone()
        print("record ffff", record)
        print("$$$$$$$",record['category_id'], record['id'])
        oldimage=record['file']
        country_database.conn.commit()
    except:
        country_database.conn.rollback()
    finally:
        country_database.conn.close()
    if request.method=='POST':
        flag=0

        title = request.form['title']
        slug = request.form['title']
        s = slugify(slug)
        print(s)
        description = request.form['decs']
        status = request.form['ck']

        cat_id = request.form['cat_id']
        if title=="":
            error['ti']="title is required"

        if description=='':
            error['de_er']="description is required"
        if request.files:
            files = request.files['image']
            if files and allowed_file(files.filename):
                filename = secure_filename(files.filename)

                files.save(os.path.join(art.config['UPLOAD_FOLDER'], filename))


                flag = 1
        if len(error)==0:

            if flag==1:
                try:
                    print("here is flag 1")
                    country_database.connects()

                    # os.remove(art.config['UPLOAD_FOLDER'] + "/" + oldimage)
                    print("here is flag 2")
                    sql="UPDATE article_manager SET title=%s,slug=%s, description=%s, file=%s, category_id=%s,"\
                         "status=%s, modified_date=%s where id=%s"
                    val=(title,s,description,files.filename, cat_id, status, str(datetime.now()),id,)
                    print("val is",val)
                    country_database.cur.execute(sql,val)
                    country_database.conn.commit()
                    flash('Article has been updated successfully!')
                    return redirect(url_for('article_manager_reg.list_article'))
                except Exception as err:
                    print(err)
                    country_database.conn.rollback()
                finally:
                    country_database.conn.close()
                flash('Article has been updated successfully!')
                return render_template('article_manager_list_edit.html', record=record, myresult=myresult, error=error)
            else:
                try:
                    country_database.connects()

                    if 'pt' in request.form and request.form['pt'] == 'on':
                        print("file%%%",oldimage)
                        os.remove(art.config['UPLOAD_FOLDER'] + "/" + oldimage)


                    sql = "UPDATE article_manager SET title=%s, slug=%s, description=%s, category_id=%s," \
                          " status=%s, modified_date=%s where id=%s"
                    val = (title,s,description, cat_id, status,str(datetime.now()), id,)
                    print("val is in flag o side", val)


                    country_database.cur.execute(sql, val)
                    country_database.conn.commit()
                    flash('Article has been updated successfully!')
                    return redirect(url_for('article_manager_reg.list_article'))


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






    return render_template('article_manager_list_edit.html', record=record, myresult=myresult, error=error)
Example #5
0
def edit():
    error = {}
    result1 = ""
    fo = ""
    try:
        result1 = None
        country_database.connects()
        id = request.args.get('id')
        sql1 = "SELECT * from category_manager where id=%s"
        val = (id, )
        country_database.cur.execute(sql1, val)
        result1 = country_database.cur.fetchone()

        fo = result1['image']

        country_database.commit()
    except:
        country_database.conn.rollback()
    finally:
        country_database.conn.close()

    if request.method == 'POST':

        flag = 0
        file = ''
        val = ""
        id = request.args.get('id')

        title = request.form['title']

        if request.files:
            file = request.files['image']
            if file and allowed_file(file.filename):

                filename = secure_filename(file.filename)

                file.save(os.path.join(cat.config['UPLOAD_FOLDER'], filename))

                flag = 1

        if len(error) == 0:

            try:
                if flag == 0:
                    print("here flag 0")
                    country_database.connects()
                    t = slugify(title)
                    if 'ch' in request.form and request.form['ch'] == 'on':
                        print("dsfguydfgjsdgf")
                        os.remove(cat.config['UPLOAD_FOLDER'] + "/" + fo)
                    id = request.args.get('id')
                    sql = "UPDATE category_manager SET title=%s, modified_date=%s WHERE id=%s"
                    val = (t, str(datetime.now()), id)
                    country_database.cur.execute(sql, val)
                    country_database.conn.commit()
                    return redirect(url_for('cat_manager.cat_list'))
                if flag == 1:
                    print("here flag 1")
                    country_database.connects()
                    t = slugify(title)
                    t = slugify(t)
                    if 'ch' in request.form and request.form['ch'] == 'on':
                        print("dsfguydfgjsdgf")
                        os.remove(fo + "/" + filename)
                    sql = "UPDATE category_manager SET title=%s,image=%s, modified_date=%s WHERE id=%s"
                    val = (t, file.filename, str(datetime.now()), id)
                    print(title)

                    print(val)
                    country_database.cur.execute(sql, val)
                    country_database.conn.commit()
                    return redirect(url_for('cat_manager.cat_list'))

            except Exception as err:
                print(err)
                country_database.conn.rollback()
            finally:
                print("ufgdui")
                country_database.conn.close()
    return render_template('cat_list_edit.html', result1=result1)
Example #6
0
def edit_page():

    myresult = ''
    id = request.args.get('id')
    print("before")
    print(id)
    try:
        country_database.connects()
        sql = "SELECT * FROM page_manager  WHERE  id =%s"
        val = (id, )
        country_database.cur.execute(sql, val)
        record = country_database.cur.fetchone()

    except Exception as err:
        print(err)
        country_database.conn.rollback()
    finally:
        country_database.conn.close()
    print("end select")

    error = {}
    if request.method == 'POST':
        print('entry post')
        title = request.form['title']
        decs = request.form['decs']
        slug = request.form['slug']
        s = slugify(slug)
        print("here is slug", s)

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

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

        if slug == "":
            error['slug'] = "Slug is empty"

        if len(error) == 0:
            print('entry without error')

            try:

                country_database.connects()
                print('try')
                print(id)
                sql = "update page_manager set title=%s , slug=%s, description=%s where id = %s"

                val = (title, s, decs, id)
                print("val is", val)

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

                flash('Page has been Updated successfully!')
                return redirect(url_for('page_manager.list_page'))
            except Exception as err:
                print(err)
                country_database.conn.rollback()
            finally:
                country_database.conn.close()

        return render_template('page_manager_list.html',
                               error=error,
                               record=record)
    return render_template('page_manager_edit.html',
                           error=error,
                           record=record)