From 5d77906331243354710712ddf45b8bcb2152dacc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 29 Jan 2018 15:37:45 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cgi-bin/.add.html.un~ | Bin 88954 -> 0 bytes cgi-bin/.add.py.swp | Bin 12288 -> 0 bytes cgi-bin/.add.py.un~ | Bin 28657 -> 0 bytes cgi-bin/.conf.ini.un~ | Bin 4882 -> 0 bytes cgi-bin/.conf.py.un~ | Bin 2234 -> 0 bytes cgi-bin/.config.py.un~ | Bin 31412 -> 0 bytes cgi-bin/.img.py.swp | Bin 12288 -> 0 bytes cgi-bin/.img.py.un~ | Bin 10922 -> 0 bytes cgi-bin/.imgs.py.un~ | Bin 117919 -> 0 bytes cgi-bin/.issue.html.swp | Bin 12288 -> 0 bytes cgi-bin/.issue.html.un~ | Bin 26503 -> 0 bytes cgi-bin/.issue.py.swp | Bin 12288 -> 0 bytes cgi-bin/.issue.py.un~ | Bin 90754 -> 0 bytes cgi-bin/.issue_unit.html.un~ | Bin 20181 -> 0 bytes cgi-bin/.page.html.swp | Bin 12288 -> 0 bytes cgi-bin/.page.html.un~ | Bin 8323 -> 0 bytes cgi-bin/.page.py.swp | Bin 12288 -> 0 bytes cgi-bin/.page.py.un~ | Bin 198461 -> 0 bytes cgi-bin/.path.py.swp | Bin 12288 -> 0 bytes cgi-bin/.path.py.un~ | Bin 14735 -> 0 bytes cgi-bin/.tag_unit.html.un~ | Bin 4962 -> 0 bytes cgi-bin/.tags.py.un~ | Bin 26004 -> 0 bytes cgi-bin/add.html | 26 +++++++++++++++++++ cgi-bin/add.py | 16 +++++------- cgi-bin/insert.py | 59 +++++++++++++++++++++++++++++++++++++++++++ cgi-bin/issue.py | 3 +++ cgi-bin/page.html | 2 +- cgi-bin/page.py | 26 ++++++++++--------- 28 files changed, 109 insertions(+), 23 deletions(-) delete mode 100644 cgi-bin/.add.html.un~ delete mode 100644 cgi-bin/.add.py.swp delete mode 100644 cgi-bin/.add.py.un~ delete mode 100644 cgi-bin/.conf.ini.un~ delete mode 100644 cgi-bin/.conf.py.un~ delete mode 100644 cgi-bin/.config.py.un~ delete mode 100644 cgi-bin/.img.py.swp delete mode 100644 cgi-bin/.img.py.un~ delete mode 100644 cgi-bin/.imgs.py.un~ delete mode 100644 cgi-bin/.issue.html.swp delete mode 100644 cgi-bin/.issue.html.un~ delete mode 100644 cgi-bin/.issue.py.swp delete mode 100644 cgi-bin/.issue.py.un~ delete mode 100644 cgi-bin/.issue_unit.html.un~ delete mode 100644 cgi-bin/.page.html.swp delete mode 100644 cgi-bin/.page.html.un~ delete mode 100644 cgi-bin/.page.py.swp delete mode 100644 cgi-bin/.page.py.un~ delete mode 100644 cgi-bin/.path.py.swp delete mode 100644 cgi-bin/.path.py.un~ delete mode 100644 cgi-bin/.tag_unit.html.un~ delete mode 100644 cgi-bin/.tags.py.un~ create mode 100644 cgi-bin/add.html create mode 100644 cgi-bin/insert.py (limited to 'cgi-bin') diff --git a/cgi-bin/.add.html.un~ b/cgi-bin/.add.html.un~ deleted file mode 100644 index 57c1714..0000000 Binary files a/cgi-bin/.add.html.un~ and /dev/null differ diff --git a/cgi-bin/.add.py.swp b/cgi-bin/.add.py.swp deleted file mode 100644 index 465de26..0000000 Binary files a/cgi-bin/.add.py.swp and /dev/null differ diff --git a/cgi-bin/.add.py.un~ b/cgi-bin/.add.py.un~ deleted file mode 100644 index 6547452..0000000 Binary files a/cgi-bin/.add.py.un~ and /dev/null differ diff --git a/cgi-bin/.conf.ini.un~ b/cgi-bin/.conf.ini.un~ deleted file mode 100644 index 3d1e5b5..0000000 Binary files a/cgi-bin/.conf.ini.un~ and /dev/null differ diff --git a/cgi-bin/.conf.py.un~ b/cgi-bin/.conf.py.un~ deleted file mode 100644 index ea49443..0000000 Binary files a/cgi-bin/.conf.py.un~ and /dev/null differ diff --git a/cgi-bin/.config.py.un~ b/cgi-bin/.config.py.un~ deleted file mode 100644 index 9271503..0000000 Binary files a/cgi-bin/.config.py.un~ and /dev/null differ diff --git a/cgi-bin/.img.py.swp b/cgi-bin/.img.py.swp deleted file mode 100644 index 82da003..0000000 Binary files a/cgi-bin/.img.py.swp and /dev/null differ diff --git a/cgi-bin/.img.py.un~ b/cgi-bin/.img.py.un~ deleted file mode 100644 index d15ae3a..0000000 Binary files a/cgi-bin/.img.py.un~ and /dev/null differ diff --git a/cgi-bin/.imgs.py.un~ b/cgi-bin/.imgs.py.un~ deleted file mode 100644 index a86dd44..0000000 Binary files a/cgi-bin/.imgs.py.un~ and /dev/null differ diff --git a/cgi-bin/.issue.html.swp b/cgi-bin/.issue.html.swp deleted file mode 100644 index 8a34f7e..0000000 Binary files a/cgi-bin/.issue.html.swp and /dev/null differ diff --git a/cgi-bin/.issue.html.un~ b/cgi-bin/.issue.html.un~ deleted file mode 100644 index 1981975..0000000 Binary files a/cgi-bin/.issue.html.un~ and /dev/null differ diff --git a/cgi-bin/.issue.py.swp b/cgi-bin/.issue.py.swp deleted file mode 100644 index 2d89ae4..0000000 Binary files a/cgi-bin/.issue.py.swp and /dev/null differ diff --git a/cgi-bin/.issue.py.un~ b/cgi-bin/.issue.py.un~ deleted file mode 100644 index b3bc373..0000000 Binary files a/cgi-bin/.issue.py.un~ and /dev/null differ diff --git a/cgi-bin/.issue_unit.html.un~ b/cgi-bin/.issue_unit.html.un~ deleted file mode 100644 index fa271bd..0000000 Binary files a/cgi-bin/.issue_unit.html.un~ and /dev/null differ diff --git a/cgi-bin/.page.html.swp b/cgi-bin/.page.html.swp deleted file mode 100644 index 3632958..0000000 Binary files a/cgi-bin/.page.html.swp and /dev/null differ diff --git a/cgi-bin/.page.html.un~ b/cgi-bin/.page.html.un~ deleted file mode 100644 index e28b9b7..0000000 Binary files a/cgi-bin/.page.html.un~ and /dev/null differ diff --git a/cgi-bin/.page.py.swp b/cgi-bin/.page.py.swp deleted file mode 100644 index 4c9b355..0000000 Binary files a/cgi-bin/.page.py.swp and /dev/null differ diff --git a/cgi-bin/.page.py.un~ b/cgi-bin/.page.py.un~ deleted file mode 100644 index 8128fc8..0000000 Binary files a/cgi-bin/.page.py.un~ and /dev/null differ diff --git a/cgi-bin/.path.py.swp b/cgi-bin/.path.py.swp deleted file mode 100644 index 298517e..0000000 Binary files a/cgi-bin/.path.py.swp and /dev/null differ diff --git a/cgi-bin/.path.py.un~ b/cgi-bin/.path.py.un~ deleted file mode 100644 index 85f7f9f..0000000 Binary files a/cgi-bin/.path.py.un~ and /dev/null differ diff --git a/cgi-bin/.tag_unit.html.un~ b/cgi-bin/.tag_unit.html.un~ deleted file mode 100644 index ff82ead..0000000 Binary files a/cgi-bin/.tag_unit.html.un~ and /dev/null differ diff --git a/cgi-bin/.tags.py.un~ b/cgi-bin/.tags.py.un~ deleted file mode 100644 index 9184da7..0000000 Binary files a/cgi-bin/.tags.py.un~ and /dev/null differ diff --git a/cgi-bin/add.html b/cgi-bin/add.html new file mode 100644 index 0000000..378d58a --- /dev/null +++ b/cgi-bin/add.html @@ -0,0 +1,26 @@ + + +添加issue + + +
+ +
+ + +
+ 标题: +
+ 标签(用空格分割): + 问题描述: + + 解决方案: + + +
+
+ + + diff --git a/cgi-bin/add.py b/cgi-bin/add.py index 440b67f..0f7c13d 100644 --- a/cgi-bin/add.py +++ b/cgi-bin/add.py @@ -7,16 +7,12 @@ import issuedb from issuedb import IssueDBFactory sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) -db = IssueDBFactory.produce() -cursor = db.cursor() +add_html_file = open("add.html", 'r', encoding='utf8') +add_html = add_html_file.read() print("Content-type:text/html\n") -redirect = """ - - - - - -""".format(1) -print(redirect) +print(add_html) + +add_html_file.close() + diff --git a/cgi-bin/insert.py b/cgi-bin/insert.py new file mode 100644 index 0000000..61f5cd9 --- /dev/null +++ b/cgi-bin/insert.py @@ -0,0 +1,59 @@ +#!C:\Python364\python3.exe +# -*- coding: utf-8 -*- +import sys, codecs +import cgi, cgitb +import pymysql +import issuedb +import time +from issuedb import IssueDBFactory +sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) + +db = IssueDBFactory.produce() +cursor = db.cursor() + +form = cgi.FieldStorage() +title = form.getvalue('issue_title') + +tags = form.getvalue('issue_tags') +issue_desc = form.getvalue('issue_description') +issue_solve = form.getvalue('issue_solve') +tag_list = None +if tags != None: + tag_list = tags.split() + +query = "insert into issue (issueTitle, issueDesc, issueSolve, issueTime) values ('{0}', '{1}', '{2}', '{3}');".format(pymysql.escape_string(title), pymysql.escape_string(issue_desc), pymysql.escape_string(issue_solve), str(time.time())) + +cursor.execute(query) +db.commit() +issueId = cursor.lastrowid + +for tag in tag_list: + cursor.execute("select tagId from tag where tagName = '{0}'".format(tag)) + tagId = cursor.fetchone() + if tagId == None: + cursor.execute("insert into tag (tagName) values ('{0}');".format(tag)) + db.commit() + tagId = cursor.lastrowid + else: + tagId = tagId[0] + cursor.execute("select relationId from relation where tagId ='{0}' and issueId = '{1}'".format(tagId, issueId)) + relationId = cursor.fetchone() + if relationId == None: + cursor.execute("insert into relation (tagId, issueId) values ('{0}', '{1}')".format(tagId, issueId)) + db.commit() + +print("Content-type:text/html\n") +redirect = """ + + + + + +""".format(issueId) +print(redirect) + +cursor.close() +db.close() + + + diff --git a/cgi-bin/issue.py b/cgi-bin/issue.py index 19a5414..0c694e0 100644 --- a/cgi-bin/issue.py +++ b/cgi-bin/issue.py @@ -47,3 +47,6 @@ try: except: print("Error: unable to fetch data \n" + e.message) +cursor.close() +db.close() + diff --git a/cgi-bin/page.html b/cgi-bin/page.html index e2609f6..f5a5641 100644 --- a/cgi-bin/page.html +++ b/cgi-bin/page.html @@ -9,7 +9,7 @@ 标签 - 添加 + 添加
diff --git a/cgi-bin/page.py b/cgi-bin/page.py index 8bdbc0a..ac5e89b 100644 --- a/cgi-bin/page.py +++ b/cgi-bin/page.py @@ -10,7 +10,6 @@ from config import Config sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer) -print("Content-type:text/html\n") db = IssueDBFactory.produce() cursor = db.cursor() @@ -28,8 +27,20 @@ tag_unit_html_file.close() issues_list = "" issues_count = Config.get("config", "issues_count") +issues_count = int(issues_count) +#处理页号 +form = cgi.FieldStorage() + +pagen = form.getvalue('p') +if pagen == None: + pagen = 0 +pageprev = int(pagen) - 1 +if pageprev < 0: + pageprev = 0 +pagenext = int(pagen) + 1 + try: - cursor.execute("select * from issue limit 0, 10") + cursor.execute("select * from issue ORDER BY issueId DESC LIMIT {0}, {1}".format(pagen*issues_count, issues_count)) issues_rows = cursor.fetchall() odd = True for row in issues_rows: @@ -56,16 +67,6 @@ try: except: print("Error: unable to fetch data") -#处理页号 -form = cgi.FieldStorage() -pagen = form.getvalue('p') -if pagen == None: - pagen = 0 -pageprev = pagen - 1 -if pageprev < 0: - pageprev = 0 -pagenext = pagen + 1 - page = page_html.format(\ issues = issues_list, \ page_prev = pageprev, \ @@ -73,6 +74,7 @@ page = page_html.format(\ ) # HTTP header +print("Content-type:text/html\n") print(page) db.commit() -- cgit v1.1-26-g67d0