Skip to content

Commit

Permalink
Merge branch 'release-1.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanandrews committed Oct 26, 2020
2 parents e6557f7 + c5c6e4a commit 367b6eb
Show file tree
Hide file tree
Showing 2,642 changed files with 337,589 additions and 888 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ jobs:
docker-compose -f local.yml run --rm tests \
sh -c "until curl -Is http://localhost:8000; do echo 'sleeping'; sleep 10; done &&
google-chrome --version && chromedriver --version &&
firefox --version && geckodriver --version &&
nodejs -v &&
./RunAllTests-Chrome-Linux.bat &&
./RunAllTests-Firefox-Linux.bat"
./RunAllTests-Chrome-Linux.bat"
- run:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,6 @@ media/
.envs/*
!.envs.example/
!static/css/jstree/dist/

# Celery
celerybeat-schedule
9 changes: 8 additions & 1 deletion compose/local/tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ RUN apt-get install -y wget && apt install -y unzip
# At Circleci root dir
COPY ./tests/*.bat /tests/
COPY ./tests/*.js /tests/
COPY ./tests/*.csv /tests/

RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs
RUN npm install jsdom
RUN npm install jquery
RUN npm install jquery-csv

RUN npm install selenium-webdriver

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && apt install -y ./google-chrome-stable_current_amd64.deb
RUN wget https://chromedriver.storage.googleapis.com/85.0.4183.83/chromedriver_linux64.zip && unzip -o chromedriver_linux64.zip -d/usr/local/bin
RUN apt install -y firefox && apt install -y firefox-geckodriver

#RUN apt install -y firefox && apt install -y firefox-geckodriver

RUN chmod +x /tests/RunAllTests-Chrome-Linux.bat
RUN sed -i 's/\r//' /tests/RunAllTests-Chrome-Linux.bat
Expand Down
4 changes: 2 additions & 2 deletions compose/production/nginx/ooi-rdb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ server {
listen 443; # <-

ssl on; # <-
ssl_certificate /etc/ssl/certs/whoi-inCommon-certificate.cer; # <-
ssl_certificate_key /etc/ssl/certs/whoi-inCommon-private.key; # <-
ssl_certificate /etc/ssl/certs/ooi-cgrdb.whoi.edu-multi.crt; # <-
ssl_certificate_key /etc/ssl/certs/ooi-cgrdb.whoi.net.key; # <-

client_max_body_size 0M;

Expand Down
4 changes: 2 additions & 2 deletions compose/production/nginx/rdb-testing.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ server {
listen 443; # <-

ssl on; # <-
ssl_certificate /etc/ssl/certs/whoi-inCommon-certificate.cer; # <-
ssl_certificate_key /etc/ssl/certs/whoi-inCommon-private.key; # <-
ssl_certificate /etc/ssl/certs/ooi-cgrdb-staging.whoi.edu-multi.crt; # <-
ssl_certificate_key /etc/ssl/certs/ooi-cgrdb-staging.whoi.net.key; # <-

client_max_body_size 0M;

Expand Down
1 change: 0 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
path('locations/', include('roundabout.locations.urls', namespace='locations')),
path('parts/', include('roundabout.parts.urls', namespace='parts')),
path('inventory/', include('roundabout.inventory.urls', namespace='inventory')),
path('deployments/', include('roundabout.inventory.urls_deployment', namespace='deployments')),
path('admintools/', include('roundabout.admintools.urls', namespace='admintools')),
path('userdefinedfields/', include('roundabout.userdefinedfields.urls', namespace='userdefinedfields')),
path('assemblies/', include('roundabout.assemblies.urls', namespace='assemblies')),
Expand Down
31 changes: 31 additions & 0 deletions rebuild_testing_and_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Copyright (C) 2019-2020 Woods Hole Oceanographic Institution
#
# This file is part of the Roundabout Database project ("RDB" or
# "ooicgsn-roundabout").
#
# ooicgsn-roundabout is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# ooicgsn-roundabout is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ooicgsn-roundabout in the COPYING.md file at the project root.
# If not, see <http://www.gnu.org/licenses/>.


# Script to rebuild rdb-testing containers and run migrate/collectstatic to deploy
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

if [ -e production-testing-site.yml ]
then
docker-compose -f production-testing-site.yml up -d --no-deps --build django_testing
docker-compose -f production-testing-site.yml run --rm django_testing python manage.py migrate
docker-compose -f production-testing-site.yml run --rm django_testing python manage.py collectstatic --noinput
fi
103 changes: 102 additions & 1 deletion roundabout/admintools/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,117 @@
# If not, see <http://www.gnu.org/licenses/>.
"""

import csv
import io
import datetime
from types import SimpleNamespace

from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


from .models import Printer
from roundabout.inventory.models import Inventory, Action
from roundabout.inventory.utils import _create_action_history
from roundabout.calibrations.models import CoefficientName, CoefficientValueSet, CalibrationEvent
from roundabout.calibrations.forms import validate_coeff_vals, parse_valid_coeff_vals
from roundabout.users.models import User


class ImportInventoryForm(forms.Form):
document = forms.FileField()

class ImportCalibrationForm(forms.Form):
document = forms.FileField()
cal_csv = forms.FileField(
widget=forms.ClearableFileInput(
attrs={
'multiple': True
}
)
)
user_draft = forms.ModelMultipleChoiceField(
queryset = User.objects.all().exclude(groups__name__in=['inventory only']).order_by('username'),
required=False,
label = 'Select Reviewers'
)

def clean_cal_csv(self):
cal_files = self.files.getlist('cal_csv')
for cal_csv in cal_files:
cal_csv.seek(0)
ext = cal_csv.name[-3:]
if ext == 'ext':
continue
if ext == 'csv':
reader = csv.DictReader(io.StringIO(cal_csv.read().decode('utf-8')))
headers = reader.fieldnames
try:
inv_serial = cal_csv.name.split('__')[0]
inventory_item = Inventory.objects.get(serial_number=inv_serial)
except:
raise ValidationError(
_('%(value)s: Unable to find Inventory item with this Serial Number'),
params={'value': inv_serial},
)
try:
cal_date_string = cal_csv.name.split('__')[1][:8]
cal_date_date = datetime.datetime.strptime(cal_date_string, "%Y%m%d").date()
except:
raise ValidationError(
_('%(value)s: Unable to parse Calibration Date from Filename'),
params={'value': cal_date_string},
)
for idx, row in enumerate(reader):
row_data = row.items()
for key, value in row_data:
if key == 'name':
calibration_name = value.strip()
try:
cal_name_item = CoefficientName.objects.get(
calibration_name = calibration_name,
coeff_name_event = inventory_item.part.coefficient_name_events.first()
)
except:
raise ValidationError(
_('Row %(row)s, %(value)s: Unable to find Calibration item with this Name'),
params={'value': calibration_name, 'row': idx},
)
elif key == 'value':
valset_keys = {'cal_dec_places': inventory_item.part.cal_dec_places}
mock_valset_instance = SimpleNamespace(**valset_keys)
try:
raw_valset = str(value)
if '[' in raw_valset:
raw_valset = raw_valset[1:-1]
if 'SheetRef' in raw_valset:
for file in cal_files:
file.seek(0)
file_extension = file.name[-3:]
if file_extension == 'ext':
cal_ext_split = file.name.split('__')
inv_ext_serial = cal_ext_split[0]
cal_ext_date = cal_ext_split[1]
cal_ext_name = cal_ext_split[2][:-4]
if (inv_ext_serial == inv_serial) and (cal_ext_date == cal_date_string) and (cal_ext_name == calibration_name):
reader = io.StringIO(file.read().decode('utf-8'))
contents = reader.getvalue()
raw_valset = contents
except:
raise ValidationError(
_('Row %(row)s: Unable to parse Calibration Coefficient value(s)'),
params={'row': idx},
)
validate_coeff_vals(mock_valset_instance, cal_name_item.value_set_type, raw_valset)
elif key == 'notes':
try:
notes = value.strip()
except:
raise ValidationError(
_('Row %(row)s: Unable to parse Calibration Coefficient note(s)'),
params={'row': idx},
)
return cal_csv


class PrinterForm(forms.ModelForm):
Expand Down
86 changes: 75 additions & 11 deletions roundabout/admintools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
import json
import requests
from dateutil import parser
import datetime
from types import SimpleNamespace

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse, reverse_lazy
from django.db import IntegrityError
from django.views.generic import View, DetailView, ListView, RedirectView, UpdateView, CreateView, DeleteView, TemplateView, FormView
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


from .forms import PrinterForm, ImportInventoryForm, ImportCalibrationForm
from .models import *
Expand All @@ -40,28 +45,87 @@
from roundabout.locations.models import Location
from roundabout.assemblies.models import AssemblyType, Assembly, AssemblyPart
from roundabout.assemblies.views import _make_tree_copy
from roundabout.inventory.utils import _create_action_history
from roundabout.calibrations.models import CoefficientName, CoefficientValueSet, CalibrationEvent
from roundabout.calibrations.forms import validate_coeff_vals, parse_valid_coeff_vals
from roundabout.users.models import User


# Test URL for Sentry.io logging
def trigger_error(request):
division_by_zero = 1 / 0


# Calibrations Github CSV file uploader
# Upload formview for Inventory Bulk upload
# CSV File Uploader for GitHub Calibration Coefficients
class ImportCalibrationsUploadView(LoginRequiredMixin, FormView):
form_class = ImportCalibrationForm
template_name = 'admintools/import_calibrations_upload_form.html'

def form_valid(self, form):
csv_file = self.request.FILES['document']
print(csv_file)
# Set up the Django file object for CSV DictReader
csv_file.seek(0)
reader = csv.DictReader(io.StringIO(csv_file.read().decode('utf-8')))

for row in reader:
print(row)

cal_files = self.request.FILES.getlist('cal_csv')
for cal_csv in cal_files:
ext = cal_csv.name[-3:]
if ext == 'ext':
continue
if ext == 'csv':
cal_csv.seek(0)
reader = csv.DictReader(io.StringIO(cal_csv.read().decode('utf-8')))
headers = reader.fieldnames
coeff_val_sets = []
inv_serial = cal_csv.name.split('__')[0]
cal_date_string = cal_csv.name.split('__')[1][:8]
inventory_item = Inventory.objects.get(serial_number=inv_serial)
cal_date_date = datetime.datetime.strptime(cal_date_string, "%Y%m%d").date()
csv_event = CalibrationEvent.objects.create(
calibration_date = cal_date_date,
inventory = inventory_item
)
for idx, row in enumerate(reader):
row_data = row.items()
for key, value in row_data:
if key == 'name':
calibration_name = value.strip()
cal_name_item = CoefficientName.objects.get(
calibration_name = calibration_name,
coeff_name_event = inventory_item.part.coefficient_name_events.first()
)
elif key == 'value':
valset_keys = {'cal_dec_places': inventory_item.part.cal_dec_places}
mock_valset_instance = SimpleNamespace(**valset_keys)
raw_valset = str(value)
if '[' in raw_valset:
raw_valset = raw_valset[1:-1]
if 'SheetRef' in raw_valset:
for file in cal_files:
file.seek(0)
file_extension = file.name[-3:]
if file_extension == 'ext':
cal_ext_split = file.name.split('__')
inv_ext_serial = cal_ext_split[0]
cal_ext_date = cal_ext_split[1]
cal_ext_name = cal_ext_split[2][:-4]
if (inv_ext_serial == inv_serial) and (cal_ext_date == cal_date_string) and (cal_ext_name == calibration_name):
reader = io.StringIO(file.read().decode('utf-8'))
contents = reader.getvalue()
raw_valset = contents
validate_coeff_vals(mock_valset_instance, cal_name_item.value_set_type, raw_valset)
elif key == 'notes':
notes = value.strip()
coeff_val_set = CoefficientValueSet(
coefficient_name = cal_name_item,
value_set = raw_valset,
notes = notes
)
coeff_val_sets.append(coeff_val_set)
if form.cleaned_data['user_draft'].exists():
draft_users = form.cleaned_data['user_draft']
for user in draft_users:
csv_event.user_draft.add(user)
for valset in coeff_val_sets:
valset.calibration_event = csv_event
valset.save()
parse_valid_coeff_vals(valset)
_create_action_history(csv_event, Action.CALCSVIMPORT, self.request.user)
return super(ImportCalibrationsUploadView, self).form_valid(form)

def get_success_url(self):
Expand Down
7 changes: 6 additions & 1 deletion roundabout/assemblies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,13 @@ class AssemblyPartAjaxDetailView(LoginRequiredMixin, DetailView):

def get_context_data(self, **kwargs):
context = super(AssemblyPartAjaxDetailView, self).get_context_data(**kwargs)
part_has_configs = False
if self.object.part.config_name_events.exists():
if self.object.part.config_name_events.first().config_names.filter(config_type='conf').exists():
part_has_configs = True
context.update({
'node_type': self.object.get_object_type()
'node_type': self.object.get_object_type(),
'part_has_configs': part_has_configs
})
return context

Expand Down
Loading

0 comments on commit 367b6eb

Please sign in to comment.