Beispiel #1
0
def nsdashimage():
    template_return_dict = {}
    image_info_dict = {}
    category_info_dict = {}
    image_path_info_query = "SELECT i.id, i.image_name, ic.image_for FROM image i INNER JOIN image_category ic on i.image_for=ic.id"
    image_category_info_query = "SELECT id, image_for FROM image_category"
    try:
        cursor, conn = get_connection_to(db_name='nsi')
        # getting image paths
        image_path_info_obj = cursor.execute(image_path_info_query)
        if image_path_info_obj:
            data = cursor.fetchall()
            image_info_dict = {
                id: (path, image_for)
                for (id, path, image_for) in data
            }
        # getting image categories
        image_category_info_obj = cursor.execute(image_category_info_query)
        if image_category_info_obj:
            data = cursor.fetchall()
            category_info_dict = {id: image_for for id, image_for in data}
    except Exception as e:
        image_info_dict = {}
        category_info_dict = {}
    template_return_dict['image_info'] = image_info_dict
    template_return_dict['category_info'] = category_info_dict
    return render_template('dashpages/nsinteriors/image.html',
                           template_info=template_return_dict)
Beispiel #2
0
def delete_image():
    image_name = request.form.get('image_name', None)
    image_id = int(request.form.get('image_id', None))

    if image_name and image_id:
        try:
            cursor, conn = get_connection_to('nsi')
            delete_query = "DELETE FROM image WHERE id=%s"
            args = (image_id, )
            cursor.execute(delete_query, args)
            conn.commit()
        except Exception as e:
            return json.dumps({"status": str(traceback.format_exc())})
        else:
            dash_path_string = "/media/ajin/Drive/MX-Work/Dashboard/static/images"
            ns_path_string = "/media/ajin/Drive/MX-Work/NSInterios/static/images"
            # dash_path_string = "/home/mxp/projects/Dashboard/static/images"
            # ns_path_string = "/home/mxp/projects/NSInteriors/static/images"
            try:
                os.remove("{0}/{1}".format(dash_path_string, image_name))
                os.remove("{0}/{1}".format(ns_path_string, image_name))
            except Exception as e:
                return json.dumps({"status": str(traceback.format_exc())})

    return json.dumps({"status": "OK"})
Beispiel #3
0
def upload_image():

    file_to_upload = request.files.get('image_files', None)
    image_for = request.form.get('image_category', None)
    if file_to_upload:
        filename = file_to_upload.filename.replace(" ", "")
        try:
            cursor, conn = get_connection_to('nsi')
            insert_query = "INSERT INTO image (image_name, image_for) VALUES (%s,%s)"
            args = (filename, int(image_for))
            cursor.execute(insert_query, args)
            conn.commit()
            # dash_path_string = "/media/ajin/Drive/MX-Work/Dashboard/static/images"
            # ns_path_string = "/media/ajin/Drive/MX-Work/NSInterios/static/images"
            dash_path_string = "/home/mxp/projects/Dashboard/static/images"
            ns_path_string = "/home/mxp/projects/NSInteriors/static/images"
            try:
                # uploading files to server
                file_to_upload.save(os.path.join(dash_path_string, filename))
                file_name_string = "{0}/{1}".format(dash_path_string, filename)
                # resizing image with python
                image_obj = Image.open(file_name_string)
                quality_val = 90
                image_obj.save(file_name_string, 'JPEG', quality=quality_val)
                shutil.copy(file_name_string, ns_path_string)
            except Exception as e:
                pass
        except Exception as e:
            pass
    return json.dumps({"status": "OK"})
Beispiel #4
0
def shadowdash():
    comment_count_query = "SELECT count(*) FROM user"
    try:
        cursor, conn = get_connection_to(db_name='sf')
        comment_count_obj = cursor.execute(comment_count_query)
        if comment_count_obj:
            ((signup_user_count, ), ) = cursor.fetchall()
    except Exception as e:
        pass

    template_dict = {"signup_count": signup_user_count}
    return render_template('dashpages/shadowfashion/index.html',
                           template_data=template_dict)
Beispiel #5
0
def nsdashquery():
    query_dict = {}
    comment_query = "SELECT id, name, email, query FROM query"
    try:
        cursor, conn = get_connection_to(db_name='nsi')
        comment_data_obj = cursor.execute(comment_query)
        if comment_data_obj:
            data = cursor.fetchall()
            query_dict = {
                id: (name, email, query)
                for (id, name, email, query) in data
            }
    except Exception as e:
        query_dict = {}
    return render_template('dashpages/nsinteriors/query.html',
                           queries_received=query_dict)
Beispiel #6
0
def nsdashcomments():
    comment_dict = {}
    comment_query = "SELECT id, name, email, message FROM comments"
    try:
        cursor, conn = get_connection_to(db_name='nsi')
        comment_data_obj = cursor.execute(comment_query)
        if comment_data_obj:
            data = cursor.fetchall()
            comment_dict = {
                id: (name, email, comment)
                for (id, name, email, comment) in data
            }
    except Exception as e:
        comment_dict = {}
    return render_template('dashpages/nsinteriors/comment.html',
                           comment_received=comment_dict)
Beispiel #7
0
def nsdash():
    comment_count_query = "SELECT count(*) FROM comments"
    query_count_query = "SELECT count(*) FROM query"
    try:
        cursor, conn = get_connection_to(db_name='nsi')
        comment_count_obj = cursor.execute(comment_count_query)
        if comment_count_obj:
            ((comment_count, ), ) = cursor.fetchall()
        query_count_obj = cursor.execute(query_count_query)
        if query_count_obj:
            ((query_count, ), ) = cursor.fetchall()
    except Exception as e:
        pass

    template_dict = {
        "comment_count": comment_count,
        "query_count": query_count
    }
    return render_template('dashpages/nsinteriors/index.html',
                           template_data=template_dict)
Beispiel #8
0
def login():
    template_data_dict = {}
    user_or_email = request.form.get('uname_or_email', None)
    password = request.form.get('account_password', None)

    select_query = "SELECT id, username FROM admin_users WHERE username=%s AND password=%s"
    args = (user_or_email, password)
    try:
        cursor, conn = get_connection_to(db_name='sfdash')
        cursor.execute(select_query, args)
        rows = cursor.fetchall()
        if rows:
            ((id, user_name), ) = rows
            session['user_name'] = user_name
            session['login'] = True
            return redirect(url_for('shadowdash'))
        else:
            template_data_dict['error'] = True
    except Exception as e:
        template_data_dict['error'] = True
    return render_template('dashpages/shadowfashion/login.html',
                           template_data=template_data_dict)