diff options
author | chai <chaifix@163.com> | 2018-01-29 15:37:45 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-01-29 15:37:45 +0800 |
commit | 5d77906331243354710712ddf45b8bcb2152dacc (patch) | |
tree | 28319897afc0d22fde2e42e834885f16834a6db6 /cgi-bin | |
parent | 07704199616228849c17302f21dd5a5a30dbea66 (diff) |
*修改
Diffstat (limited to 'cgi-bin')
-rw-r--r-- | cgi-bin/.add.html.un~ | bin | 88954 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.add.py.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.add.py.un~ | bin | 28657 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.conf.ini.un~ | bin | 4882 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.conf.py.un~ | bin | 2234 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.config.py.un~ | bin | 31412 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.img.py.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.img.py.un~ | bin | 10922 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.imgs.py.un~ | bin | 117919 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.issue.html.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.issue.html.un~ | bin | 26503 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.issue.py.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.issue.py.un~ | bin | 90754 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.issue_unit.html.un~ | bin | 20181 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.page.html.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.page.html.un~ | bin | 8323 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.page.py.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.page.py.un~ | bin | 198461 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.path.py.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.path.py.un~ | bin | 14735 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.tag_unit.html.un~ | bin | 4962 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/.tags.py.un~ | bin | 26004 -> 0 bytes | |||
-rw-r--r-- | cgi-bin/add.html | 26 | ||||
-rw-r--r-- | cgi-bin/add.py | 16 | ||||
-rw-r--r-- | cgi-bin/insert.py | 59 | ||||
-rw-r--r-- | cgi-bin/issue.py | 3 | ||||
-rw-r--r-- | cgi-bin/page.html | 2 | ||||
-rw-r--r-- | cgi-bin/page.py | 26 |
28 files changed, 109 insertions, 23 deletions
diff --git a/cgi-bin/.add.html.un~ b/cgi-bin/.add.html.un~ Binary files differdeleted file mode 100644 index 57c1714..0000000 --- a/cgi-bin/.add.html.un~ +++ /dev/null diff --git a/cgi-bin/.add.py.swp b/cgi-bin/.add.py.swp Binary files differdeleted file mode 100644 index 465de26..0000000 --- a/cgi-bin/.add.py.swp +++ /dev/null diff --git a/cgi-bin/.add.py.un~ b/cgi-bin/.add.py.un~ Binary files differdeleted file mode 100644 index 6547452..0000000 --- a/cgi-bin/.add.py.un~ +++ /dev/null diff --git a/cgi-bin/.conf.ini.un~ b/cgi-bin/.conf.ini.un~ Binary files differdeleted file mode 100644 index 3d1e5b5..0000000 --- a/cgi-bin/.conf.ini.un~ +++ /dev/null diff --git a/cgi-bin/.conf.py.un~ b/cgi-bin/.conf.py.un~ Binary files differdeleted file mode 100644 index ea49443..0000000 --- a/cgi-bin/.conf.py.un~ +++ /dev/null diff --git a/cgi-bin/.config.py.un~ b/cgi-bin/.config.py.un~ Binary files differdeleted file mode 100644 index 9271503..0000000 --- a/cgi-bin/.config.py.un~ +++ /dev/null diff --git a/cgi-bin/.img.py.swp b/cgi-bin/.img.py.swp Binary files differdeleted file mode 100644 index 82da003..0000000 --- a/cgi-bin/.img.py.swp +++ /dev/null diff --git a/cgi-bin/.img.py.un~ b/cgi-bin/.img.py.un~ Binary files differdeleted file mode 100644 index d15ae3a..0000000 --- a/cgi-bin/.img.py.un~ +++ /dev/null diff --git a/cgi-bin/.imgs.py.un~ b/cgi-bin/.imgs.py.un~ Binary files differdeleted file mode 100644 index a86dd44..0000000 --- a/cgi-bin/.imgs.py.un~ +++ /dev/null diff --git a/cgi-bin/.issue.html.swp b/cgi-bin/.issue.html.swp Binary files differdeleted file mode 100644 index 8a34f7e..0000000 --- a/cgi-bin/.issue.html.swp +++ /dev/null diff --git a/cgi-bin/.issue.html.un~ b/cgi-bin/.issue.html.un~ Binary files differdeleted file mode 100644 index 1981975..0000000 --- a/cgi-bin/.issue.html.un~ +++ /dev/null diff --git a/cgi-bin/.issue.py.swp b/cgi-bin/.issue.py.swp Binary files differdeleted file mode 100644 index 2d89ae4..0000000 --- a/cgi-bin/.issue.py.swp +++ /dev/null diff --git a/cgi-bin/.issue.py.un~ b/cgi-bin/.issue.py.un~ Binary files differdeleted file mode 100644 index b3bc373..0000000 --- a/cgi-bin/.issue.py.un~ +++ /dev/null diff --git a/cgi-bin/.issue_unit.html.un~ b/cgi-bin/.issue_unit.html.un~ Binary files differdeleted file mode 100644 index fa271bd..0000000 --- a/cgi-bin/.issue_unit.html.un~ +++ /dev/null diff --git a/cgi-bin/.page.html.swp b/cgi-bin/.page.html.swp Binary files differdeleted file mode 100644 index 3632958..0000000 --- a/cgi-bin/.page.html.swp +++ /dev/null diff --git a/cgi-bin/.page.html.un~ b/cgi-bin/.page.html.un~ Binary files differdeleted file mode 100644 index e28b9b7..0000000 --- a/cgi-bin/.page.html.un~ +++ /dev/null diff --git a/cgi-bin/.page.py.swp b/cgi-bin/.page.py.swp Binary files differdeleted file mode 100644 index 4c9b355..0000000 --- a/cgi-bin/.page.py.swp +++ /dev/null diff --git a/cgi-bin/.page.py.un~ b/cgi-bin/.page.py.un~ Binary files differdeleted file mode 100644 index 8128fc8..0000000 --- a/cgi-bin/.page.py.un~ +++ /dev/null diff --git a/cgi-bin/.path.py.swp b/cgi-bin/.path.py.swp Binary files differdeleted file mode 100644 index 298517e..0000000 --- a/cgi-bin/.path.py.swp +++ /dev/null diff --git a/cgi-bin/.path.py.un~ b/cgi-bin/.path.py.un~ Binary files differdeleted file mode 100644 index 85f7f9f..0000000 --- a/cgi-bin/.path.py.un~ +++ /dev/null diff --git a/cgi-bin/.tag_unit.html.un~ b/cgi-bin/.tag_unit.html.un~ Binary files differdeleted file mode 100644 index ff82ead..0000000 --- a/cgi-bin/.tag_unit.html.un~ +++ /dev/null diff --git a/cgi-bin/.tags.py.un~ b/cgi-bin/.tags.py.un~ Binary files differdeleted file mode 100644 index 9184da7..0000000 --- a/cgi-bin/.tags.py.un~ +++ /dev/null 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 @@ +<html> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>添加issue</title> +<body> +<link rel="stylesheet" href="style.css" type="text/css" /> +<div id="container"> + <img src="logo.png" id="logo"/> + <br/> + <script src="ckeditor/ckeditor.js"></script> + + <form action="/insert" method="post" class="form_add"> + <font class="issue_font">标题:</font><input name="issue_title" type="text" class="issue_title"/> + <br/> + <font class="issue_font">标签(用空格分割):</font><input name="issue_tags" type="text" class="issue_tags"/> + <font class="issue_font">问题描述:</font> + <textarea name="issue_description" id="editor1" class="ckeditor" rows="10" cols="80"> + </textarea> + <font class="issue_font">解决方案:</font> + <textarea name="issue_solve" id="editor2" class="ckeditor" rows="20" cols="80"> + </textarea> + <input type="submit" value="提交" class="submit"/> + </form> +</div> +</body> +</html> + 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 = """ -<html> -<head> -<meta http-equiv="refresh" content="0;url=issue?id={0}"> -</head> -</html> -""".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 = """ +<html> +<head> +<meta http-equiv="refresh" content="0;url=issue?id={0}"> +</head> +</html> +""".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 @@ <input type="text" id="searchbar_input" name="content"/> <input type="submit" id="searchbar_submit" value="搜索"/> <a href="/tags">标签</a> - <a href="/add.html">添加</a> + <a href="/add">添加</a> </form> <br/> <!--issues--> 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() |