Skip to content

Commit

Permalink
Merge branch 'form-refactor' of https://github.com/darkreactions/ESCA…
Browse files Browse the repository at this point in the history
…LATE into load_script_refactor
  • Loading branch information
ichang1 committed Dec 5, 2021
2 parents 9eb5069 + 4a6a154 commit d92fa97
Show file tree
Hide file tree
Showing 16 changed files with 392 additions and 271 deletions.
4 changes: 3 additions & 1 deletion escalate/core/forms/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ class ExperimentTemplateForm(Form):
)

def __init__(self, *args, **kwargs):
org_id = kwargs.pop("org_id")
org_id = kwargs.pop('org_id')
if not org_id:
raise ValueError('Please select a lab to continue')
lab = vt.Actor.objects.get(organization=org_id, person__isnull=True)
super().__init__(*args, **kwargs)
# self.fields['organization'].queryset = OrganizationPassword.objects.all()
Expand Down
126 changes: 47 additions & 79 deletions escalate/core/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.hashers import make_password
from django.contrib.admin import widgets
from core.models import (
CustomUser,
OrganizationPassword,
)
from core.models.view_tables import (
Person,
Material,
Inventory,
Actor,
Note,
Organization,
Systemtool,
SystemtoolType,
UdfDef,
Status,
Tag,
TagAssign,
TagType,
MaterialType,
Edocument,
InventoryMaterial,
Vessel,
)
from core.models import (CustomUser, OrganizationPassword, )
from core.models.view_tables import (Person, Material, Inventory, Actor, Note,
Organization, Systemtool, SystemtoolType,
UdfDef, Status, Tag, TagAssign, TagType, MaterialType,
Edocument, InventoryMaterial, Vessel, MaterialIdentifier)
from core.models.core_tables import TypeDef

from packaging import version
Expand All @@ -51,7 +33,7 @@ class LoginForm(forms.Form):


class CustomUserCreationForm(UserCreationForm):
class Meta:
class Meta:
model = CustomUser
fields = ["username", "password1", "password2"]

Expand Down Expand Up @@ -154,48 +136,40 @@ class Meta(PersonFormData.Meta):


class MaterialForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
# pk of model that is passed in to filter for tags belonging to the model
material_instance = kwargs.get("instance", None)

current_material_identifiers = material_instance.identifier.all() if material_instance else MaterialIdentifier.objects.none()
current_material_types = material_instance.material_type.all() if material_instance else MaterialType.objects.none()

super(MaterialForm, self).__init__(*args, **kwargs)

self.fields['identifier'] = forms.ModelMultipleChoiceField(
initial=current_material_identifiers,
required=False,
queryset=MaterialIdentifier.objects.all())
self.fields['identifier'].widget.attrs.update(dropdown_attrs)

self.fields['material_type'] = forms.ModelMultipleChoiceField(
initial=current_material_types,
required=False,
queryset=MaterialType.objects.all())
self.fields['material_type'].widget.attrs.update(dropdown_attrs)
class Meta:
model = Material
fields = ["status"]
"""
'abbreviation': forms.CharField,
'chemical_name': forms.CharField,
'inchi': forms.CharField,
'inchikey': forms.CharField,
'molecular_formula': forms.CharField,
'smiles': forms.CharField
"""
fields = ['consumable', 'material_class', 'identifier', 'material_type', 'status']
field_classes = {
"create_date": forms.SplitDateTimeField,
}
"""
'abbreviation': 'Abbreviation',
'chemical_name': 'Chemical name',
'inchi': 'International Chemical Identifier (InChI)',
'inchikey': 'International Chemical Identifier key (InChI key)',
'molecular_formula': 'Molecular formula',
'smiles': 'Smiles',
"""
labels = {"create_date": "Create date", "material_status": "Status"}
"""
'abbreviation': forms.TextInput(attrs={'placeholder': 'Ex: Water'}),
'chemical_name': forms.TextInput(attrs={
'placeholder': 'Ex: Dihydrogen Monoxide'}),
'inchi': forms.TextInput(attrs={'placeholder': 'Ex: 1S/H2O/h1H2'}),
'inchikey': forms.TextInput(attrs={
'placeholder': 'Ex: XLYOFNOQVPJJNP-UHFFFAOYSA-N'}),
'molecular_formula': forms.TextInput(attrs={
'placeholder': 'Ex: H2O'}),
'smiles': forms.TextInput(attrs={'placeholder': 'Ex: O'}),
"""
# 'create_date': forms.SplitDateTimeField,
}
labels = {
'create_date': 'Create date',
'material_status': 'Status'
}
widgets = {
"create_date": forms.SplitDateTimeWidget(
date_format="%d-%m-%Y",
date_attrs={"placeholder": "DD-MM-YYYY"},
time_format="%H:%M",
time_attrs={"placeholder": "HH-MM"},
),
"material_status": forms.Select(attrs=dropdown_attrs),
'consumable': forms.CheckboxInput(),
'material_class': forms.RadioSelect(choices=model._meta.get_field('material_class').choices),
'status': forms.Select(attrs=dropdown_attrs),
}


Expand Down Expand Up @@ -631,9 +605,9 @@ class Meta:
"description": forms.CharField,
"part_no": forms.CharField,
#'onhand_amt': ValFormField,
#'onhand_amt': forms.CharField,
"expiration_date": forms.SplitDateTimeField,
"location": forms.CharField,
'onhand_amt': forms.CharField,
'expiration_date': forms.SplitDateTimeField,
'location': forms.CharField,
}
labels = {
"description": "Description",
Expand Down Expand Up @@ -663,25 +637,19 @@ class Meta:
class VesselForm(forms.ModelForm):
class Meta:
model = Vessel
# fields = ['plate_name', 'well_number']
fields = ["description", "parent"]
fields = ['description', 'parent', 'total_volume']
field_classes = {
#'plate_name': forms.CharField,
#'well_number': forms.CharField,
"description": forms.CharField,
'description': forms.CharField,
'total_volumne': forms.CharField,
}
labels = {
#'plate_name': 'Plate Name',
#'well_number': 'Well Number',
"description": "Description"
'description': 'Description',
'parent': 'Parent',
'total_volume': 'Total Volume'
}
widgets = {
"plate_name": forms.Textarea(
attrs={"cols": "10", "rows": "3", "placeholder": "Plate name"}
),
"well_number": forms.Textarea(
attrs={"cols": "10", "rows": "1", "placeholder": "Well number"}
),
'description': forms.TextInput(attrs={'placeholder': 'Vessel Information...'}),
'total_volumne': forms.TextInput(attrs={'placeholder': 'total Volume...'}),
}


Expand Down
4 changes: 2 additions & 2 deletions escalate/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.0.14 on 2021-11-23 22:04
# Generated by Django 3.0.14 on 2021-12-03 18:01

import core.models.core_tables
import core.models.custom_types
Expand Down Expand Up @@ -494,7 +494,7 @@ class Migration(migrations.Migration):
('description', models.CharField(blank=True, max_length=255, null=True)),
('uuid', core.models.core_tables.RetUUIDField(db_column='vessel_uuid', default=uuid.uuid4, primary_key=True, serialize=False)),
('total_volume', models.CharField(blank=True, max_length=255, null=True)),
('internal_slug', core.models.core_tables.SlugField(blank=True, editable=False, max_length=255, overwrite=True, populate_from=['description'])),
('internal_slug', core.models.core_tables.SlugField(blank=True, editable=False, max_length=255, overwrite=True, populate_from=['description', 'total_volume', 'parent__description'])),
('actor', models.ForeignKey(blank=True, db_column='actor_uuid', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='vessel_actor', to='core.Actor')),
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='parent_vessel', to='core.Vessel')),
('status', models.ForeignKey(blank=True, db_column='status_uuid', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='vessel_status', to='core.Status')),
Expand Down
28 changes: 12 additions & 16 deletions escalate/core/models/view_tables/chemistry_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,18 @@ class Vessel(DateColumns, StatusColumn, ActorColumn, DescriptionColumn):
# dead_volume = models.CharField(max_length=255,blank=True, null=True)
# whole plate can leave well_number blank
# well_number = models.CharField(max_length = 16, blank=True, null=True)
parent = models.ForeignKey(
"Vessel",
on_delete=models.DO_NOTHING,
blank=True,
null=True,
related_name="parent_vessel",
)
internal_slug = SlugField(
populate_from=[
#'plate_name',
#'well_number'
"description"
],
overwrite=True,
max_length=255,
)
parent = models.ForeignKey('Vessel', on_delete=models.DO_NOTHING,
blank=True, null=True,
related_name='parent_vessel')
internal_slug = SlugField(populate_from=[
#'plate_name',
#'well_number'
'description',
"total_volume",
"parent__description"
],
overwrite=True,
max_length=255)

def __str__(self):
# return "{} {}".format(self.plate_name, self.well_number)
Expand Down
25 changes: 22 additions & 3 deletions escalate/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@
<ul class="navbar-nav mr-auto">
<li class="nav-item {% if url_name == 'main_menu' %}active{% endif %}">
<a class="nav-link" href="{% url 'main_menu' %}">Main Menu</a>

</li>

<li class="nav-item {% if url_name == 'select_lab' %}active{% endif %}">
<a class="nav-link" href="{% url 'select_lab' %}">Select Lab</a>
</li>

<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle {% if not request.session.current_org_id %}disabled{% endif %}" href="#" id="dropdown" data-toggle="dropdown">Models</a>
<a class="nav-link dropdown-toggle " href="#" id="dropdown" data-toggle="dropdown">Models</a>
<div class="dropdown-menu">
<ul class="list-unstyled">
<li><a class="dropdown-item" href="{% url 'material_list' %}">Material</a></li>
Expand All @@ -87,7 +93,7 @@
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle {% if not request.session.current_org_id %}disabled{% endif %}" href="#" id="dropdown" data-toggle="dropdown">Experiment</a>
<a class="nav-link dropdown-toggle " href="#" id="dropdown" data-toggle="dropdown">Experiment</a>
<div class="dropdown-menu">
<ul class="list-unstyled">
<li>
Expand All @@ -109,11 +115,14 @@
</ul>
<ul class="navbar-nav flex-row mt-4">
<li class="nav-item text-light">
{{ request.session.current_org_name }}
{% if request.session.current_org_name %}
Selected Lab {{ request.session.current_org_name }}
{% endif %}
</li>
</ul>

</div>

<div class="dropdown">
<a class="btn btn-info dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ request.user.person.first_name }} {{ request.user.person.last_name }}
Expand All @@ -133,8 +142,18 @@
{% endblock %}
<section>
<div class="container">

<div class="card">
<div class="card-body" id="page-content">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<div class="alert alert-danger" role="alert">
{{ message }}
</div>
{% endfor %}
</ul>
{% endif %}
{% block content %}
{% endblock %}
<nav>
Expand Down
20 changes: 6 additions & 14 deletions escalate/core/templates/core/create_experiment.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<p>Selected experiment {{ selected_exp_template.description }}</p>
<div class="row">
<div class="col-md-12">

<form method="post" enctype="multipart/form-data">{% csrf_token %}

{% if manual > 0 %}
<form method="post" enctype="multipart/form-data">{% csrf_token %}

{% if manual > 0 %}

<button class="btn btn-outline-primary" type="submit" name="robot_download"
value="Submit">Download Robot file</button>
Expand Down Expand Up @@ -139,11 +139,7 @@ <h6 class="pt-3 pl-3">Reaction Parameters for {{ selected_exp_template.descripti
</div>
<br>
{% endfor %}

{{ robot_file_upload_form|crispy }}
<button class="btn btn-outline-primary" type="submit" name="robot_upload" value="create_exp">Create Experiment</button>


<div class="treeview-animated border mx-3 my-4">
<h6 class="pt-3 pl-3">Vessel Selection for {{ selected_exp_template.description }}</h6>
<hr>
Expand Down Expand Up @@ -192,17 +188,13 @@ <h6 class="pt-3 pl-3">Reaction Parameters for {{ selected_exp_template.descripti
{% endfor %}
</ul>
</div>
<input type="hidden" id="automated" name="automated" value="{{ automated }}">
<div class="text-right">
<button class="btn btn-outline-primary" type="submit" name="create_exp" value="create_exp">Create Experiment</button>
{% endif %}

</div>
{{ robot_file_upload_form|crispy }}
<button class="btn btn-outline-primary" type="submit" name="robot_upload" value="create_exp">Create Experiment</button>

</div>

</div>

{% endif %}
{% endif %}
{% endif %}

Expand Down
27 changes: 1 addition & 26 deletions escalate/core/templates/core/main_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,14 @@


{% block content %}



<div class="container">
<p> Choose your lab </p>
<div class="row">
<div class="col-md-12 text-secondary">
<form method="post">{% csrf_token %}
<select id='org_select' name='org_select' class='form-control selectpicker' data-style='btn-dark'
data-live-search='true'>
<option disabled>────────────</option>
{% for org in user_person.added_organization.all %}
<option value={{ org.uuid }} {% if request.session.current_org_name == org.full_name %} selected {% endif %}>
{{ org.full_name }}</option>
{% endfor %}
</select>
<button class="btn btn-outline-primary" type="submit" name="select_org" value="select_org">Select Lab</button>
</form>
</div>
</div>


<h3>Please select a lab organization before performing any experiment creation task</h3>

<h3>Links to tables in the nav bar above will change based on logical groupings</h3>
<h3>Plots and Dashboard on this page</h3>

{% autoescape off %}
{{ plot_div }}
{% endautoescape %}
</div>




{% endblock %}

Expand Down
Loading

0 comments on commit d92fa97

Please sign in to comment.