Skip to content

Commit

Permalink
Merge pull request #224 from ODM2/release/0.7.0
Browse files Browse the repository at this point in the history
Release/0.7.0
  • Loading branch information
jcaraballo17 authored Apr 16, 2018
2 parents af8c567 + a465e15 commit ddbecc9
Show file tree
Hide file tree
Showing 41 changed files with 1,644 additions and 874 deletions.
2 changes: 1 addition & 1 deletion src/WebSDL/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WebSDL.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WebSDL.settings.linux_sandbox")

crontab_jobs.start_jobs()

Expand Down
15 changes: 7 additions & 8 deletions src/crontab_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from crontab import CronTab
import re
from django.utils.termcolors import colorize
import logging

from WebSDL.settings.base import CRONTAB_LOGFILE_PATH as LOGFILE
from WebSDL.settings.base import CRONTAB_EXECUTE_DAILY_AT_HOUR as AT_HOUR
Expand Down Expand Up @@ -32,15 +33,13 @@ def start_jobs(user=True):
import getpass

curr_user = getpass.getuser()
msg = "\nWARNING: user '{0}' does not have the write permission to {1}. crontab jobs might not run correctly"\
.format(curr_user, LOGFILE)
print(colorize(msg, fg='red'))
logging.warning("'{0}' does not have write permissions to {1}. Crontab jobs will not run.".format(curr_user, LOGFILE))

else:

manage_path = locate_file('manage.py') # get the file path of 'manage.py'
if manage_path is None:
raise Exception('the file "manage.py" was not found')
raise Exception('"manage.py" not found')

output = subprocess.check_output(['which', 'python']) # get the python path used by the current process
python_path = re.sub(r"(?<=[a-z])\r?\n", "", output) # remove newlines from output...
Expand Down Expand Up @@ -75,21 +74,21 @@ def start_jobs(user=True):
"""

# print jobs created
print(colorize("\nStarted crontab jobs: ", fg='blue'))
logging.info(colorize("Started crontab jobs: ", fg='blue'))
for job in cron:
print(colorize('\t' + str(job), fg='green'))
logging.info(colorize('\t' + str(job), fg='green'))


def stop_jobs(cron=None, user=None):
""" Stops crontab jobs containing JOB_COMMENT_PREPENDER in the job's comment """
print(colorize("\nStopping crontab jobs: ", fg='blue'))
logging.info(colorize("Stopping crontab jobs: ", fg='blue'))
if cron is None and user:
cron = CronTab(user=user)

for job in cron:
if re.search(re.escape(JOB_COMMENT_PREPENDER), job.comment):
job_name = re.sub(re.escape(JOB_COMMENT_PREPENDER), r'', job.comment)
print("\t" + colorize(str(job_name), fg='green'))
logging.info("\t" + colorize(str(job_name), fg='green'))
cron.remove(job)
cron.write()

Expand Down
6 changes: 5 additions & 1 deletion src/dataloader/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class Meta:
class ElevationDatum(ControlledVocabulary):
class Meta:
db_table = 'cv_elevationdatum'
ordering = ['name']


class EquipmentType(ControlledVocabulary):
Expand All @@ -289,6 +290,7 @@ class Meta:
class Medium(ControlledVocabulary):
class Meta:
db_table = 'cv_medium'
ordering = ['name']


class MethodType(ControlledVocabulary):
Expand Down Expand Up @@ -412,6 +414,7 @@ def __repr__(self):

class Meta:
db_table = 'people'
ordering = ['person_first_name', 'person_last_name']


@python_2_unicode_compatible
Expand Down Expand Up @@ -469,6 +472,7 @@ def __repr__(self):

class Meta:
db_table = 'affiliations'
ordering = ['person__person_first_name', 'person__person_last_name']


@python_2_unicode_compatible
Expand Down Expand Up @@ -717,7 +721,7 @@ def __repr__(self):

class Meta:
db_table = 'units'
ordering = ['unit_abbreviation']
ordering = ['unit_type_id', 'unit_name']


@python_2_unicode_compatible
Expand Down
56 changes: 31 additions & 25 deletions src/dataloaderinterface/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ def create_option(self, name, value, label, selected, index, subindex=None, attr
return option


class SampledMediumField(forms.ModelChoiceField):
custom_labels = {
'Liquid aqueous': 'Water - Liquid Aqueous'
}

@staticmethod
def get_custom_label(medium):
return SampledMediumField.custom_labels[medium] if medium in SampledMediumField.custom_labels else medium

def label_from_instance(self, obj):
return SampledMediumField.get_custom_label(obj.name)


class UserOrganizationField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return obj.organization_name


class MDLRadioButton(forms.RadioSelect):
def render(self, name, value, attrs=None, renderer=None):
"""Adds MDL HTML classes to label and input tags"""
Expand Down Expand Up @@ -88,28 +106,19 @@ def __init__(self, *args, **kwargs):
label='Resource Title',
)

resources = forms.ModelChoiceField(queryset=HydroShareResource.objects.all(), required=False)

# TODO: Make this a model form
# class Meta:
# model = HydroShareResource
# fields = ['hs_account', 'ext_id', 'site_registration', 'sync_type', 'update_freq', 'is_enabled', 'data_types']


class HydroShareSiteForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(HydroShareSiteForm, self).__init__(*args, **kwargs)
freq_choice_index = self.instance.get_udpate_freq_index()
self.initial['update_freq'] = HydroShareResource.FREQUENCY_CHOICES[freq_choice_index][0]

class Meta:
model = HydroShareResource
fields = ['is_enabled', 'sync_type', 'update_freq', 'hs_account', 'site_registration']
widgets = {'update_freq': forms.Select(choices=HydroShareResource.FREQUENCY_CHOICES)}


class HydroShareResourceDeleteForm(forms.Form):

delete_external_resource = forms.BooleanField(initial=False,
label="Delete connected resource in HydroShare.",
required=False)
delete_external_resource = forms.BooleanField(
initial=False,
label="Delete connected resource in HydroShare.",
required=False)


class UserRegistrationForm(UserCreationForm):
Expand All @@ -118,8 +127,8 @@ class UserRegistrationForm(UserCreationForm):
first_name = forms.CharField(required=True, max_length=50)
last_name = forms.CharField(required=True, max_length=50)
email = forms.EmailField(required=True, max_length=254)
organization = forms.ModelChoiceField(
queryset=Organization.objects.all().exclude(organization_type__in=['Vendor', 'Manufacturer']), required=False, help_text='Begin to enter the common name of your organization to choose from the list. If "No results found", then clear your entry, click on the drop-down-list to select "Add New Organization".')
organization = UserOrganizationField(
queryset=Organization.objects.all().exclude(organization_type__in=['Vendor', 'Manufacturer']).order_by('organization_name'), required=False, help_text='Begin to enter the common name of your organization to choose from the list. If "No results found", then clear your entry, click on the drop-down-list to select "Add New Organization".')
agreement = forms.BooleanField(required=True)

def save(self, commit=True):
Expand Down Expand Up @@ -265,13 +274,10 @@ def __init__(self, *args, **kwargs):
self.empty_permitted = False

equipment_model = forms.ModelChoiceField(queryset=EquipmentModel.objects.for_display(), help_text='Choose the model of your sensor')
sampled_medium = forms.ModelChoiceField(queryset=Medium.objects.filter(
Q(pk='Air') |
Q(pk='Soil') |
Q(pk='Liquid aqueous') |
Q(pk='Equipment') |
Q(pk='Not applicable')
), help_text='Choose the sampled medium')
sampled_medium = SampledMediumField(queryset=Medium.objects.filter(pk__in=[
'Air', 'Soil', 'Sediment', 'Liquid aqueous',
'Equipment', 'Not applicable', 'Other'
]), help_text='Choose the sampled medium')

class Meta:
model = Result
Expand Down
17 changes: 11 additions & 6 deletions src/dataloaderinterface/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def __repr__(self):
class ODM2User(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
affiliation_id = models.IntegerField()
hydroshare_account = models.OneToOneField('HydroShareAccount',
db_column='hs_account_id',
null=True)
hydroshare_account = models.OneToOneField('HydroShareAccount', db_column='hs_account_id', null=True, blank=True)

@property
def affiliation(self):
Expand Down Expand Up @@ -201,7 +199,7 @@ class Meta:
class HydroShareAccount(models.Model):
is_enabled = models.BooleanField(default=False)
ext_id = models.IntegerField(unique=True) # external hydroshare account id
token = models.ForeignKey(OAuthToken, db_column='token_id', null=True)
token = models.ForeignKey(OAuthToken, db_column='token_id', null=True, on_delete=models.CASCADE)

def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
Expand Down Expand Up @@ -262,13 +260,14 @@ class HydroShareResource(models.Model):
hs_account = models.ForeignKey(HydroShareAccount, db_column='hs_account_id', on_delete=models.CASCADE, null=True,
blank=True)
ext_id = models.CharField(max_length=255, blank=True, null=True, unique=True) # external hydroshare resource id
title = models.CharField(max_length=255, blank=True, null=True)
site_registration = models.OneToOneField(SiteRegistration, unique=True)
site_registration = models.OneToOneField(SiteRegistration, related_name='hydroshare_resource')
sync_type = models.CharField(max_length=255, default='manual', choices=HYDROSHARE_SYNC_TYPES)
update_freq = models.CharField(max_length=32, verbose_name='Update Frequency', default='daily')
is_enabled = models.BooleanField(default=True)
last_sync_date = models.DateTimeField(auto_created=True)
data_types = models.CharField(max_length=255, blank=True, default='')
visible = models.BooleanField(default=True)
title = models.CharField(default='', blank=True, null=True, max_length=255)

@property
def sync_type_verbose(self):
Expand Down Expand Up @@ -337,6 +336,12 @@ def to_dict(self):
# def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
# return super(HydroShareResource, self).save(force_insert, force_update, using, update_fields)

def __str__(self):
return '<HydroShareResource: {}>'.format(self.pk)

def __unicode__(self):
return self.title if self.title is not None else self.ext_id

class Meta:
db_table = 'hydroshare_resource'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,98 @@
.map-container {
margin-top: 25px;
height: 700px;
padding: 0;
body {
/*overflow: hidden;*/
}

#wrapper {
height: 100%;
padding-top: 81px;
margin-top: 0;
}

#map {
height: 100%;
background: #e8e8e8;
}

div.map-info {
margin: 5px;
.map-container {
height: 100%;
}

span.map-tip {
box-shadow: rgba(0, 0, 0, 0.298039) 0 1px 4px -1px;
background-color: rgba(255, 255, 255, .95);
border-radius: 2px;
font-size: 13px;
padding: 7px 15px;
.full-height {
height: 100%;
}

.browse-sites-header {
display: inline-block;
#filters {
overflow-y: scroll;
background: #e8e8e8;
height: 100%;
border-bottom: 1px solid #DDD;
}

@media only screen and (max-width: 720px) {
#filters {
overflow-y: initial;
height: initial;
}
}

#filters label {
display: table-cell;
padding-right: 40px;
}

#filters .badge {
position: absolute;
z-index: 1;
background: #FFF;
padding: 24px;
margin: 15px;
border-radius: 2px;
max-width: 350px;
right: 24px;
top: 16px;
width: 24px;
}

.filter-container {
margin-top: 20px;
margin-bottom: 40px;
}

.browse-sites-header .page-title {
.filter-body {
overflow: auto;
}

.filter-header table {
background-color: #66cbcb;
}

.filter-header table tr:hover {
background-color: #94eaea;
}

.filter-header h6 {
margin: 0;
font-size: 14px;
}

#filters .filter-header h6 > i.material-icons:first-child {
vertical-align: middle;
background: #005050;
color: #fff;
border-radius: 50%;
padding: 0px;
border: 2px solid #048a8a;
}

.page-title {
margin: 12px 0;
display: inline-block;
}

.subtitle {
vertical-align: middle;
display: inline-block;
margin: 10px 0;
}

.page-title, .subtitle {
text-shadow: 0 1px 0 #000;
color: #FFF;
}

#map {
border: 0;
}
Loading

0 comments on commit ddbecc9

Please sign in to comment.