From ae77523ce68e210051625da09f43cbdc7dd02ca7 Mon Sep 17 00:00:00 2001 From: dabercro Date: Thu, 1 Sep 2016 13:51:30 +0200 Subject: [PATCH 01/10] Reasons are being returned correctly now. --- clusterworkflows.py | 2 +- manageactions.py | 68 +++++++++++++++++++++++- runserver/actions/test.json | 14 ----- runserver/static/css/style.css | 8 ++- runserver/templates/actionsubmitted.html | 10 ++-- runserver/workflowtools.py | 12 ++--- 6 files changed, 82 insertions(+), 32 deletions(-) delete mode 100644 runserver/actions/test.json diff --git a/clusterworkflows.py b/clusterworkflows.py index 98d546a..a1511c9 100644 --- a/clusterworkflows.py +++ b/clusterworkflows.py @@ -17,7 +17,7 @@ .. math:: \\mathrm{distance} = \\frac{d}{\\sqrt{2} |\\vec{v}|} + - 2.0 w \\left(\\frac{|\\vec{v}|}{|\\vec{v}| + m} - 0.5\\right) + 2 w \\left(\\frac{|\\vec{v}|}{|\\vec{v}| + m} - 0.5\\right) *d* is the 'distance' parameter, *w* is the 'width' parameter, and *m* is the 'midpoint' parameter set in the ``config.yml``. diff --git a/manageactions.py b/manageactions.py index 0018d36..73d3932 100644 --- a/manageactions.py +++ b/manageactions.py @@ -6,12 +6,17 @@ import os import json +import glob from datetime import datetime +from datetime import timedelta from . import reasonsmanip +ACTIONS_DIRECTORY = 'actions' +"""The location to store the actions JSON files""" + def extract_reasons_params(**kwargs): """Extracts the reasons and parameters for an action from kwargs @@ -78,8 +83,13 @@ def submitaction(user, workflows, action, **kwargs): reasons, params = extract_reasons_params(**kwargs) - output_file_name = 'actions/{0}_{1}.json'.\ - format(user, datetime.now().strftime('%Y%m%d')) + if not os.path.exists(ACTIONS_DIRECTORY): + os.makedirs(ACTIONS_DIRECTORY) + + output_file_name = os.path.join( + ACTIONS_DIRECTORY, '{0}_{1}.json'.\ + format(user, datetime.now().strftime('%Y%m%d')) + ) add_to_json = {} if os.path.isfile(output_file_name): @@ -100,3 +110,57 @@ def submitaction(user, workflows, action, **kwargs): json.dump(add_to_json, outputfile) return workflows, action, reasons, params + + +def get_prev_actions(num_days): + """Get the keys and values of recent actions + + :param int num_days: is the number of days to check for actions + :rtype: generator + """ + + date = datetime.now() + date_int = int(date.strftime('%Y%m%d')) + prev_int = int((date - timedelta(num_days)).strftime('%Y%m%d')) + + for match in glob.iglob(os.path.join(ACTIONS_DIRECTORY, '*.json')): + check_int = int(match.split('_')[-1].rstrip('.json')) + if prev_int <= check_int <= date_int: + with open(match, 'r') as infile: + output = json.load(infile) + for key, value in output.iteritems(): + yield key, value + + +def get_actions(num_days): + """Get the recent actions to be act on in dictionary form + + :param int num_days: is the number of days to check for actions + :returns: A dictionary of actions, to be rendered as JSON + :rtype: dict + """ + + output = {} + + for key, value in get_prev_actions(num_days): + output[key] = value + + return output + + +def get_acted_workflows(num_days): + """Get all of the workflows that have actions assigned + + :param int num_days: is the number of past days to check for actions. + This speeds up the check while not losing the + ability to look farther back in time. + :returns: a list of workflows acted on + :rtype: list + """ + + workflows = [] + + for key, _ in get_prev_actions(num_days): + workflows.append(key) + + return workflows diff --git a/runserver/actions/test.json b/runserver/actions/test.json deleted file mode 100644 index 941574f..0000000 --- a/runserver/actions/test.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - - "test" : { - "Actions": "test", - - "Parameters": { - "test": "True", - "what": "test" - }, - - "Reasons": "I needed a test" - } - -} diff --git a/runserver/static/css/style.css b/runserver/static/css/style.css index 3bbf0a6..a515b0d 100644 --- a/runserver/static/css/style.css +++ b/runserver/static/css/style.css @@ -9,11 +9,15 @@ body { padding:2em; } -h1, h2, h3 { +h1, h2 { text-align:center; } +h3 { + background-color:#e6f7ff; +} + footer { padding:2em; background-color:#e6f7ff; -} \ No newline at end of file +} diff --git a/runserver/templates/actionsubmitted.html b/runserver/templates/actionsubmitted.html index d8dbeb7..0037443 100644 --- a/runserver/templates/actionsubmitted.html +++ b/runserver/templates/actionsubmitted.html @@ -6,21 +6,21 @@

Submitted action to Unified with the following parameters:

-

User

+

User

${user} -

Workflows

+

Workflows

% for wf in workflows: ${wf}
% endfor -

Action

+

Action

${action} -

Parameters

+

Parameters

${params} -

Reasons

+

Reasons

% for reason in reasons:

${reason['short']}

${reason['long']}

diff --git a/runserver/workflowtools.py b/runserver/workflowtools.py index c7f1b0a..69f201e 100755 --- a/runserver/workflowtools.py +++ b/runserver/workflowtools.py @@ -9,7 +9,6 @@ """ import os -import glob import cherrypy from mako.lookup import TemplateLookup @@ -213,9 +212,11 @@ def submitaction(self, workflows='', action='', **kwargs): @cherrypy.expose @cherrypy.tools.json_out() - def getaction(self, test=False): + def getaction(self, days=0, test=False): """Returns the latest action json that has not been adressed yet. + :param int days: The number of past days to check. + The default, 0, means to only check today. :param bool test: Used to determine whether or not to return the test file. :returns: a JSON file containing actions to act on :rtype: JSON @@ -236,8 +237,7 @@ def getaction(self, test=False): } } - newest_json = max(glob.iglob('actions/*.json'), key=os.path.getmtime) - raise cherrypy.HTTPRedirect('/' + newest_json) + return manageactions.get_actions(days) @cherrypy.expose def explainerror(self, errorcode="0", workflowstep="/"): @@ -394,10 +394,6 @@ def secureheaders(): 'tools.staticdir.on': True, 'tools.staticdir.dir': './static' }, - '/actions': { - 'tools.staticdir.on': True, - 'tools.staticdir.dir': './actions' - }, '/submitaction': { 'tools.auth_basic.on': True, 'tools.auth_basic.realm': 'localhost', From 3cc20017cbccff3b8adfbe18f5397c1b6976c8bd Mon Sep 17 00:00:00 2001 From: dabercro Date: Thu, 1 Sep 2016 14:01:25 +0200 Subject: [PATCH 02/10] Allow scripts to be loaded into template page. --- runserver/templates/newuser.html | 85 +++++++++++++++----------------- runserver/templates/simple.html | 2 + 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/runserver/templates/newuser.html b/runserver/templates/newuser.html index a3cf177..10f0814 100644 --- a/runserver/templates/newuser.html +++ b/runserver/templates/newuser.html @@ -1,52 +1,47 @@ - - - - - - - - +<%inherit file="simple.html"/> - +<%block name="title">New User Registration -

- On a successful submission, - you will get a confirmation page that an email was sent. -

+<%block name="scripts"> + + + -
- E-mail:
-
- Username:
-
- Password:
-
- Confirm Password:
- -
- -
+

+ On a successful submission, + you will get a confirmation page that an email was sent. +

-

- The username must only contain alphanumeric characters, - or it will not be added to the database. -

- +
+ E-mail:
+
+ Username:
+
+ Password:
+
+ Confirm Password:
+ +
+ +
-

- The email must end with one of the following: -

- +

+ The username must only contain alphanumeric characters, + or it will not be added to the database. +

+ -
+

+ The email must end with one of the following: +

+ - - +
diff --git a/runserver/templates/simple.html b/runserver/templates/simple.html index f480b52..2c3b4b4 100644 --- a/runserver/templates/simple.html +++ b/runserver/templates/simple.html @@ -5,6 +5,7 @@ <%block name="title"/> + <%block name="scripts"/> @@ -13,6 +14,7 @@