Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f9e07bf
ignore my PyCharm files
skeating May 9, 2019
d8167d0
Merge remote-tracking branch 'origin/master' into 67-add-view-run-exp
skeating May 13, 2019
01969b8
Finally sorted the url and getting a new page displayed
skeating May 13, 2019
f274d1c
corrected name as can use run experiments with either models/protocols
skeating May 13, 2019
c2aade3
change name model -> entity
skeating May 13, 2019
bf4174b
page no lists the appropriate things - tackling version next
skeating May 14, 2019
e93247c
fixed test that worked locally but not in github
skeating May 16, 2019
88ecc0a
sorted the view for my model/protocols
skeating May 17, 2019
5b04abf
add force override checkbox
skeating May 17, 2019
441a1bb
My local set up is not letting me play with js files so adding them s…
skeating May 17, 2019
bc4de21
add url test for runexperiments
skeating May 20, 2019
898e589
getting checkboxes to work as indicated
skeating May 20, 2019
b79fc2c
checkboxes not working as hoped try again
skeating May 20, 2019
7e07e6f
trying checkboxes again
skeating May 20, 2019
010f601
sorry changed context and forgot tests
skeating May 20, 2019
b0f360f
typo in comments
skeating May 21, 2019
9f6a427
Try Jonathan's suggestion to sort checkboxes
skeating May 21, 2019
964d8d0
Made EntityRunExperimentView also inherit PermissionRequiredMixin
skeating May 21, 2019
00bb989
start with latest versions checked
skeating May 21, 2019
6f1019f
update tests for adding permission to run experiment view
skeating May 21, 2019
b56a372
try again with tests - my local setup is clearly not completely accur…
skeating May 22, 2019
3718b94
think I've got it- sorted the tests for permissions on runExperiment
skeating May 22, 2019
75db07d
<ul> tag should be outside for loop
skeating May 22, 2019
cf45cd2
improve query speed
skeating May 22, 2019
0a2dac4
change wording of force override button
skeating May 22, 2019
12d466d
only show Run experiment button if user has permission to create expe…
skeating May 22, 2019
626b5ed
changed hard coded 'model' to get correct entity type
skeating May 22, 2019
9d61b18
Merge remote-tracking branch 'origin/submit-expt-improvements' into 6…
skeating May 23, 2019
dde92d2
In teh interest of time pushing my development work to git so I get a…
skeating May 23, 2019
29415f6
trying to see if this works
skeating May 23, 2019
dd6e4e9
am I actually picking up experiments
skeating May 23, 2019
4137ec8
that confirmed my suspicions - take out the 404 code that I added to …
skeating May 23, 2019
d377474
Merge remote-tracking branch 'origin/master' into 67-add-view-run-exp
skeating May 23, 2019
5ca1340
Merge remote-tracking branch 'origin/master' into 67-add-view-run-exp
skeating May 28, 2019
65e7afe
finally got tings working so I add experiments to PlannedExperiments
skeating May 28, 2019
c6ad76f
divide listed entities into 'My' and 'Other'
skeating May 28, 2019
5a27adf
testing of my vs other lists and running experiments
skeating May 29, 2019
bba5e24
Merge remote-tracking branch 'origin/master' into 67-add-view-run-exp
skeating May 29, 2019
9b1e47d
Got the force or not to force rerun checkbox working
skeating May 29, 2019
e1bf92d
changed spelling of function to be more python-esque Thanks Michael
skeating May 29, 2019
2986d68
changed name and added additional test for no checkboxes checked
skeating May 30, 2019
dcf1a71
few more changes from Jonathan - mostly syntax
skeating May 30, 2019
4b7ded9
more changes from Jonathan
skeating May 30, 2019
6f6c64b
missed a line
skeating May 31, 2019
114f0b6
filter for experiments with or whithout versions
skeating May 31, 2019
bdb41e1
add test for experiment no versions
skeating May 31, 2019
e555f0a
took out if permission to create experiment
skeating May 31, 2019
9874020
add newline at eof
skeating May 31, 2019
a3a4e6d
Creating expts & editing entities are independent permissions
jonc125 Jun 1, 2019
e616eaf
Funkier way of setting filter args
jonc125 Jun 1, 2019
79334c2
Correct experiment with no versions test
jonc125 Jun 1, 2019
5f501c7
Associate run experiments view with an entity _version_
jonc125 Jun 1, 2019
24d783b
Fix templatetag test
jonc125 Jun 1, 2019
775307f
Merge branch 'master' into 67-add-view-run-exp
jonc125 Jun 1, 2019
20d73fb
pick relevant commits that went into 182-fitting branch
skeating Jun 6, 2019
955c620
Force text to be inline rather than separate lines
skeating Jun 6, 2019
d93574c
Shrink display further
jonc125 Jun 11, 2019
8fd191b
add tests for run experiment view of not latest version of an entity
skeating Jun 11, 2019
a4dbf1c
Test that post runxperiments also works with not latest version
skeating Jun 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ ENV/
# Rope project settings
.ropeproject

# PyCharm files
.idea/

# mkdocs documentation
/site

Expand All @@ -113,5 +116,3 @@ weblab/data/

# media directory
weblab/media/

weblab/\.idea/
7 changes: 7 additions & 0 deletions weblab/entities/templatetags/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,10 @@ def can_delete_entity(context, entity):
def can_manage_entity(context, entity):
user = context['user']
return entity.is_managed_by(user)


@register.filter
def url_run_experiments(entity, commit):
last_tag = _url_friendly_label(entity, commit)
args = [entity.entity_type, entity.id, last_tag]
return reverse('entities:runexperiments', args=args)
13 changes: 13 additions & 0 deletions weblab/entities/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,16 @@ def test_url_friendly_label(model_with_version, helpers):
commit3 = helpers.add_version(model_with_version)
model_with_version.repo.tag('latest')
assert entity_tags._url_friendly_label(model_with_version, commit3) == commit3.hexsha


@pytest.mark.django_db
def test_url_runexperiments(model_with_version, protocol_with_version):
model = model_with_version
model_commit = model.repo.latest_commit
assert (entity_tags.url_run_experiments(model, model_commit) ==
'/entities/models/%d/versions/%s/runexperiments' % (model.pk, model_commit.hexsha))

protocol = protocol_with_version
protocol_commit = protocol.repo.latest_commit
assert (entity_tags.url_run_experiments(protocol, protocol_commit) ==
'/entities/protocols/%d/versions/%s/runexperiments' % (protocol.pk, protocol_commit.hexsha))
506 changes: 506 additions & 0 deletions weblab/entities/tests/test_views.py

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions weblab/entities/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
name='entity_archive',
),

url(
r'^%s/(?P<pk>\d+)/versions/%s/runexperiments$' % (_ENTITY_TYPE, _COMMIT),
views.EntityRunExperimentView.as_view(),
name='runexperiments',
),

url(
r'^(?P<pk>\d+)/upload-file$',
views.FileUploadView.as_view(),
Expand Down
79 changes: 78 additions & 1 deletion weblab/entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from core.visibility import (
Visibility, VisibilityMixin
)
from experiments.models import Experiment, PlannedExperiment
from experiments.models import Experiment, PlannedExperiment, ExperimentVersion
from repocache.exceptions import RepoCacheMiss
from repocache.models import CachedEntityVersion

Expand Down Expand Up @@ -1016,3 +1016,80 @@ def get(self, request, *args, **kwargs):
return JsonResponse({
task: result
})


class EntityRunExperimentView(PermissionRequiredMixin, LoginRequiredMixin,
EntityTypeMixin, EntityVersionMixin, DetailView):
"""
A view allowing users to set up a batch-run of experiments involving a single entity.
"""
permission_required = 'experiments.create_experiment'
context_object_name = 'entity'
template_name = 'entities/entity_runexperiments.html'

def get_context_data(self, **kwargs):
entity = self.object
context = super().get_context_data(**kwargs)

# preposition to use in sentence: You may run this entity on/under the following entities
context['preposition'] = 'under'
if entity.entity_type == 'protocol':
context['preposition'] = 'on'

# ended up using a nested dict as nested lists caused django's unpacking in forloops to
# mess things up slightly
other_entities = Entity.objects.filter(
entity_type=entity.other_type
).select_related(
'cachedentity'
).prefetch_related(
'cachedentity__versions',
'cachedentity__versions__tags'
)
context['object_list'] = []
context['other_object_list'] = []
for item in other_entities:
versions = item.cachedentity.versions
version_info = []
for version in versions.prefetch_related('tags'):
tag_list = list(version.tags.values_list('tag', flat=True))
commit = item.repo.get_commit(version.sha)
Comment thread
skeating marked this conversation as resolved.
latest = item.repo.latest_commit
version_info.append({'commit': commit, 'tags': tag_list, 'latest': latest == commit})
if item.author == self.request.user:
context['object_list'].append({'id': item.id, 'name': item.name, 'versions': version_info})
else:
context['other_object_list'].append({'id': item.id, 'name': item.name, 'versions': version_info})
return context

def post(self, request, *args, **kwargs):
# this in not intuitive
# in get context self.object was the entity being worked with
# here we have to retrieve it
this_entity = self.get_object()
Comment thread
skeating marked this conversation as resolved.
this_version = self.get_commit().hexsha
is_latest = (this_version == this_entity.repocache.latest_version.sha)
exclude_existing = 'rerun_expts' not in request.POST
experiments_to_run = request.POST.getlist('model_protocol_list[]')
for version in experiments_to_run:
ident, sha = version.split(':')
exper_kwargs = {
this_entity.other_type + '_id': ident,
this_entity.other_type + '_version': sha,
this_entity.entity_type + '_id': this_entity.id,
this_entity.entity_type + '_version': this_version,
}
if exclude_existing:
filter_kwargs = {
'experiment__' + name: value
for (name, value) in exper_kwargs.items()
}
if ExperimentVersion.objects.filter(**filter_kwargs).exists():
continue
PlannedExperiment.objects.get_or_create(**exper_kwargs)
# return to entity page
version_to_use = 'latest'
if not is_latest:
version_to_use = kwargs['sha']
return HttpResponseRedirect(
reverse('entities:version', args=[kwargs['entity_type'], kwargs['pk'], version_to_use]))
1 change: 1 addition & 0 deletions weblab/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var experiment = require('./experiment.js');
var notifications = require('./lib/notifications.js');
require('./compare.js');
require('./entity_version_list.js');
require('./run_experiment.js');
require('django-formset');


Expand Down
39 changes: 39 additions & 0 deletions weblab/static/js/run_experiment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

var RunExperiment = function() {};

RunExperiment.prototype = {
init: function() {
$("#checkallbutton").click (function () {
$(".latestexperimentCheckBox").each (function () {
$(this).prop('checked', true)
});
$(".experimentCheckBox").each (function () {
$(this).prop('checked', true)
});
});
$("#uncheckallbutton").click (function () {
$(".latestexperimentCheckBox").each (function () {
$(this).prop('checked', false)
});
$(".experimentCheckBox").each (function () {
$(this).prop('checked', false)
});
});
$("#checklatestbutton").click (function () {
$(".latestexperimentCheckBox").each (function () {
$(this).prop('checked', true)
});
$(".experimentCheckBox").each (function () {
$(this).prop('checked', false)
});
});
}
};


$(document).ready(function() {
if ($("#runexperiment").length > 0) {
var page = new RunExperiment();
page.init();
}
});
109 changes: 109 additions & 0 deletions weblab/templates/entities/entity_runexperiments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load entities %}

{% block title %}Experiment: run specific combinations - {% endblock title %}

{% block body_id %}runexperiment{% endblock %}

{% block content %}
<h1 id="entityname">Run experiments using <span>{{ entity.name }}</span></h1>

<button id="checkallbutton">check all</button>
<button id="checklatestbutton">check latest</button>
<button id="uncheckallbutton">uncheck all</button>
<form action="" method="post">
{% csrf_token %}
<button id="savebutton">run experiments</button>
<p>
<input class="overrideCheckBox" type="checkbox" name="rerun_expts"/>
Create new versions of existing experiments (if unchecked, existing combinations will be skipped)
</p>


<p>You may run this {{ type }} {{ preposition }} the following {{ other_type }}s.</p>

<h2> Your {{ other_type }}s</h2>

<!-- list each entity and all versions of that entity -->
{% for entity_object in object_list %}

<strong>{{ entity_object.name }}</strong>
<ul>
{% for entity_version in entity_object.versions %}

<li>
<p>
{% if entity_version.latest %}

<input class="latestexperimentCheckBox" type="checkbox"
value="{{ entity_object.id }}:{{ entity_version.commit.hexsha }}"
name="model_protocol_list[]"
checked/>
{% else %}
<input class="experimentCheckBox" type="checkbox"
value="{{ entity_object.id }}:{{ entity_version.commit.hexsha }}"
name="model_protocol_list[]"/>
{% endif %}
<strong>
<a class="entityversionlink" href="{{ entity|url_version:entity_version.commit }}">
{% include "./includes/version_name.html" with tags=entity_version.tags version=entity_version.commit only %}
</a>
</strong>
<span class="suppl"><small style="display: inline;">by <em>{{ entity_version.commit.author }}</em>
created <time>{{ entity_version.commit.committed_at }}</time></small></span><br/>
<span class="suppl">
{{ entity_version.commit.message|linebreaksbr }}
</span>
</p>
</li>
{% endfor %}
</ul>
{% endfor %}

<h2> Other {{ other_type }}s</h2>

<!-- list each entity and all versions of that entity -->
{% for entity_object in other_object_list %}

<strong>{{ entity_object.name }}</strong>
<ul>
{% for entity_version in entity_object.versions %}

<li>
<p>
{% if entity_version.latest %}

<input class="latestexperimentCheckBox" type="checkbox"
value="{{ entity_object.id }}:{{ entity_version.commit.hexsha }}"
name="model_protocol_list[]"
checked/>
{% else %}
<input class="experimentCheckBox" type="checkbox"
value="{{ entity_object.id }}:{{ entity_version.commit.hexsha }}"
name="model_protocol_list[]"/>
{% endif %}
<strong>
<a class="entityversionlink" href="{{ entity|url_version:entity_version.commit }}">
{% include "./includes/version_name.html" with tags=entity_version.tags version=entity_version.commit only %}
</a>
</strong>
by <em>{{ entity_version.commit.author }}</em><br/>
<span class="suppl">
<small style="display: inline;">created </small> <time>{{ entity_version.commit.committed_at }}</time>
{% with entity_version.commit.filenames|length as numfiles %}
<small style="display: inline;">containing</small> {{ numfiles }} file{{ numfiles|pluralize }}
{% endwith %}
</span><br/>
<span class="suppl">
{{ entity_version.commit.message|linebreaksbr }}
</span>
</p>
</li>
{% endfor %}
</ul>
{% endfor %}

</form>

{% endblock %}
18 changes: 13 additions & 5 deletions weblab/templates/entities/entity_version.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{% include "./includes/entity_header.html" %}
{% can_create_version entity as permission %}


<div id="entitydetails">
</div>

Expand Down Expand Up @@ -38,14 +39,21 @@ <h2 id="entityversionname">
<div id="versionVisibility" data-change-href="{{ entity|url_change_version_visibility:version }}">
{% if permission %}
<a href="{{ entity|url_tag_version:version }}">Add tag</a>.
<form method="POST" action="">
<form method="POST" action="" style="display: inline;">
Change visibility: {{ form.visibility }}
<img src="{% static 'img/info.png' %}" alt="help" title="{{ entity.VISIBILITY_HELP }}" />.
<img src="{% static 'img/info.png' %}" alt="help" title="{{ entity.VISIBILITY_HELP }}" />
<span id="versionVisibilityAction"></span>
</form>
{% else %}
</form>
{% else %}
Visibility: {{ visibility }}
<img src="{% static 'img/info.png' %}" alt="help" title="{{ entity.VISIBILITY_HELP }}" />.
<img src="{% static 'img/info.png' %}" alt="help" title="{{ entity.VISIBILITY_HELP }}" />
{% endif %}
{% if perms.experiments.create_experiment %}
Run experiments:
<a title="Run experiments" href="{{ entity|url_run_experiments:version }}">
<img src="{% static 'img/batch.png' %}" alt="Run experiments:"
title="Run experiments using this {{ entity.entity_type }}"/>
</a>
{% endif %}
</div>
</small>
Expand Down
2 changes: 1 addition & 1 deletion weblab/templates/entities/includes/version_name.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
{% for tag in tags %}
<b>{{ tag }}</b>{% if not forloop.last %},{% endif %}
{% endfor %}
{% if tags %}<small>({% endif %}{% spaceless %}
{% if tags %}<small style="display: inline;">({% endif %}{% spaceless %}
<span title="Full identifier: {{ version.hexsha }}">{{ version.hexsha|truncatechars:11 }}</span>
{% endspaceless %}{% if tags %})</small>{% endif %}