Wang Dingwei avatar Wang Dingwei committed 07a4c94

adds function to display fga sdr

Comments (0)

Files changed (7)

 *.log
 *~
 *.swp
-*.rar
-*.zip
 dist
-uploads
 TESTDIR
 OIE_LISTS
 OrderBackup
 from flaskext.uploads import (UploadSet, configure_uploads, 
                               UploadNotAllowed)
 
+import os, glob
 import datetime
 from collections import defaultdict
 
 def push_file(attname):
     return send_from_directory(app.config['UPLOADED_FILES_DEST'], attname)
 
+
+@app.route('/fga_sdr/')
+def list_sdrs():
+    sdrs = glob.glob(os.path.join(app.config['FGA_DIR'], '*'))
+    sdrs.sort(key=lambda x: os.path.getmtime(x), reverse=True)
+    sdrs = [s.split('_')[1] for s in sdrs]
+    return render_template('fga.html', sdrs=sdrs)
+
+
+@app.route('/get_sdr/', methods=['GET', 'POST'])
+def get_sdr():
+    if request.method == 'POST':
+        config = request.form['config'].strip()
+        return redirect(url_for('display_sdr', config=config))
+    return redirect(url_for('list_sdrs'))
+
+
+@app.route('/get_sdr/<config>', methods=['GET', 'POST'])
+def display_sdr(config):
+    if request.method == 'POST':
+        config = request.form['config'].strip()
+        
+    sdr_name = 'SDR_' + config + '_FGA.txt'
+    sdr_path = os.path.join(app.config['FGA_DIR'], sdr_name)
+    if os.path.exists(sdr_path):
+        sdr_content = open(sdr_path).read()
+        return render_template('show_sdr.html',
+                               config=config,
+                               content=sdr_content)
+    else:
+        return render_template('500.html', msg="SDR not found!"), 500
+
 if __name__ == '__main__':
     db.create_all()
     app.run()
+@echo off
+
+title OrderFilter Web Server
+echo Running orderfilter query system on CherryPy (Ctrl+C to abort)
+echo.
+echo ENV path: D:\env\baseline
+echo APP path: D:\env\orderfilter_web
+echo Web URL:  http://127.0.0.1:8080
+echo.
+
+
+call D:\env\baseline\Scripts\activate.bat
+python runserver.py
-import os
-from datetime import timedelta
-
 class Config(object):
     DEBUG = False
     TESTING = False
-    SQLALCHEMY_DATABASE_URI = 'sqlite:///F:\\Projects\\orderfilter\\test.db'
+    SQLALCHEMY_DATABASE_URI = 'sqlite:///D:\\CTO\\orderfilter\\filter_result.db'
     SECRET_KEY = 'development'
     UPLOADED_FILES_DEST = "uploads"
-    UPLOADED_FILES_ALLOW = ('doc', 'docx', 'ppt', 'pptx', 'msg', 'txt')
+    UPLOADED_FILES_ALLOW = tuple('doc docx ppt pptx msg txt rar'.split())
     USERNAME = 'admin'
     PASSWORD = 'ndk800'
+    FGA_DIR = "D:\\CTO\\FGASDR"
     
 class ProductionConfig(Config):
-    pass
+    SQLALCHEMY_DATABASE_URI = 'sqlite:///D:\\CTO\\orderfilter\\filter_result.db'
 
 class DevelopmentConfig(Config):
     DEBUG = True

templates/fga.html

+{% extends "layout.html" %}
+
+{% block title %}
+    OrderFilter Query System
+{% endblock %}
+
+{% block body %}
+
+<h2>Search SDR</h2>
+
+<form action="/get_sdr/" method="POST">
+    <input type="text" name="config">
+    <input type="submit" value="Submit">
+</form>
+
+
+<h2>FGA SDRS</h2>
+<ul>
+{% if sdrs %}
+    {% for sdr in sdrs %}
+       <li><a href={{ url_for('display_sdr', config=sdr)}}>{{ sdr }}</a></li>
+    {% endfor %}
+</ul>
+{% else %}
+<p> No result available </p>
+{% endif %}
+
+
+{% endblock %}

templates/index.html

     <p>End:   <input type="text" name="end"></p>
     <input type="submit" value="Submit">
 </form>
+<p><a href={{url_for('list_sdrs')}}>Check FGA SDR</a></p>
 {% endblock %}

templates/show_sdr.html

+{% extends "layout.html" %}
+
+{% block title %}
+    OrderFilter Query System
+{% endblock %}
+
+{% block body %}
+
+<h2>Search SDR</h2>
+
+<form action="/get_sdr/" method="POST">
+    <input type="text" name="config">
+    <input type="submit" value="Submit">
+</form>
+
+
+<h2>SDR for Config {{ config }}</h2>
+<pre>
+{{content}}
+</pre>
+
+
+{% endblock %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.