summaryrefslogtreecommitdiff
path: root/cgi-bin/issue.py
blob: 0c694e0d4304f311dc153e6a92838daba46199e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!C:\Python364\python3.exe
# -*- coding: utf-8 -*-
import sys, codecs
import cgi, cgitb
import pymysql
import issuedb
from issuedb import IssueDBFactory
sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)

print("Content-type:text/html\n")

db = IssueDBFactory.produce()
cursor = db.cursor() 

tag_unit_html_file = open("tag_unit.html", 'r', encoding='utf8')
issue_html_file = open("issue.html", 'r', encoding='utf8')
issue_html = issue_html_file.read()
tag_unit_html = tag_unit_html_file.read() 

issue = ""

try: 
    issueId = cgi.FieldStorage().getvalue("id")
    cursor.execute("select * from issue where issueId={0}".format(issueId))
    issue_content = cursor.fetchall()
    issue_content = issue_content[0]

    if issue_content != None: 
        taglist = "" 
        cursor.execute("SELECT * FROM tag WHERE tagId IN (SELECT tagId FROM relation WHERE issueId = {0})".format(issueId))
        tags_rows = cursor.fetchall() 
        for tag_row in tags_rows:
            tag = tag_unit_html.format(\
                tagid = tag_row[0], \
                tag_name = tag_row[1],\
                tag_count = '' \
            )
            taglist += tag 
        issue = issue_html.format( \
                issueId = issue_content[0], \
                issueTitle = issue_content[1],\
                issueDescription = issue_content[2],\
                issueSolve = issue_content[3],\
                tags = taglist\
            )
    print(issue)
except:
    print("Error: unable to fetch data \n" + e.message)   

cursor.close()
db.close()