-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
174 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import re | ||
import datetime | ||
import dataclasses | ||
import collections | ||
import dateutil.relativedelta | ||
import json | ||
|
||
from ... import simpledata, data, persistence | ||
from .. import jira | ||
|
||
|
||
def load_data(): | ||
try: | ||
with open("/tmp/estimage_demo.json") as f: | ||
ret = json.loads(f.read()) | ||
except Exception: | ||
ret = dict() | ||
return ret | ||
|
||
|
||
def save_data(what): | ||
old = load_data() | ||
old.update(what) | ||
with open("/tmp/estimage_demo.json", "w") as f: | ||
json.dump(old, f) | ||
|
||
|
||
class NotToday: | ||
@property | ||
def DDAY_LABEL(self): | ||
return "Week from now" | ||
|
||
def get_date_of_dday(self): | ||
data = load_data() | ||
day_index = data.get("day_index", 0) | ||
return datetime.datetime.today() + datetime.timedelta(days=day_index) | ||
|
||
|
||
EXPORTS = dict( | ||
MPLPointPlot="NotToday", | ||
MPLVelocityPlot="NotToday", | ||
) | ||
|
||
|
||
QUARTER_TO_MONTH_NUMBER = None | ||
PROJECT_NAME = "OPENSCAP" | ||
|
||
|
||
TEMPLATE_OVERRIDES = { | ||
} | ||
|
||
|
||
def get_not_finished_targets(targets): | ||
return [t for t in targets if t.state in (data.State.todo, data.State.in_progress)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from flask_wtf import FlaskForm | ||
import wtforms | ||
|
||
|
||
class DemoForm(FlaskForm): | ||
issues = wtforms.RadioField('Issues') | ||
progress = wtforms.FloatField('Progress') | ||
submit = wtforms.SubmitField("Next Day") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import flask | ||
import flask_login | ||
|
||
from ...webapp import web_utils | ||
from . import forms | ||
from . import get_not_finished_targets, load_data, save_data | ||
|
||
bp = flask.Blueprint("demo", __name__, template_folder="templates") | ||
|
||
|
||
@bp.route('/demo', methods=("GET", "POST")) | ||
@flask_login.login_required | ||
def next_day(): | ||
cls, loader = web_utils.get_retro_loader() | ||
targets_by_id = loader.get_loaded_targets_by_id() | ||
targets = get_not_finished_targets(targets_by_id.values()) | ||
|
||
form = forms.DemoForm() | ||
choices = [(t.name, t.title) for t in targets] | ||
form.issues.choices = choices | ||
if form.validate_on_submit(): | ||
old_plugin_data = load_data() | ||
old_plugin_data["day_index"] = old_plugin_data.get("day_index", 0) + 1 | ||
save_data(old_plugin_data) | ||
|
||
return web_utils.render_template( | ||
'demo.html', title='Demo Plugin', plugin_form=form, day_index=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends "base.html" %} | ||
|
||
{% import "utils.j2" as utils %} | ||
{% from 'bootstrap5/form.html' import render_form %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<div class="row"> | ||
<h1>Execution Demo</h1> | ||
<p>Day {{ day_index + 1 }}</p> | ||
{{ render_form(plugin_form, action=url_for("demo.next_day")) }} | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
|
||
from estimage import plugins, data, PluginResolver, persistence | ||
from estimage.data import BaseTarget | ||
import estimage.plugins.demo as tm | ||
|
||
from tests.test_target import base_target_load_save, fill_target_instance_with_stuff, assert_targets_are_equal | ||
from tests.test_inidata import temp_filename, targetio_inifile_cls | ||
|
||
|
||
@pytest.fixture | ||
def some_targets(): | ||
a = BaseTarget("a") | ||
a.state = data.State.todo | ||
b = BaseTarget("b") | ||
b.state = data.State.in_progress | ||
c = BaseTarget("c") | ||
d = BaseTarget("d") | ||
d.state = data.State.done | ||
return [a, b, c, d] | ||
|
||
|
||
def test_select_tasks_not_finished(some_targets): | ||
assert not tm.get_not_finished_targets([]) | ||
assert len(tm.get_not_finished_targets(some_targets)) == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters