-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from sharpeez/wc_sprint
WLC sprint #2
- Loading branch information
Showing
25 changed files
with
495 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* * * * * root eval $(grep -v '^#' /etc/.cronenv | xargs -d "\n" -I {} echo export \"{}\" ) && cd /app && python manage_wc.py system_maintenance_check > /dev/null 2>&1 | ||
0 2 * * * root eval $(grep -v '^#' /etc/.cronenv | xargs -d "\n" -I {} echo export \"{}\" ) && cd /app && python manage_wc.py cron_tasks > logs/cron_tasks.log 2>&1 | ||
10 2 * * * root eval $(grep -v '^#' /etc/.cronenv | xargs -d "\n" -I {} echo export \"{}\" ) && cd /app && python manage_wc.py runcrons > logs/runcrons.log 2>&1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
from django.contrib import admin | ||
#from ledger.accounts.models import EmailUser | ||
from wildlifecompliance.components.main import models | ||
from wildlifecompliance.components.main import models, forms | ||
#from reversion.admin import VersionAdmin | ||
|
||
|
||
@admin.register(models.GlobalSettings) | ||
class GlobalSettingsAdmin(admin.ModelAdmin): | ||
list_display = ['key', 'value'] | ||
ordering = ('key',) | ||
|
||
|
||
@admin.register(models.SystemMaintenance) | ||
class SystemMaintenanceAdmin(admin.ModelAdmin): | ||
list_display = ['name', 'description', 'start_date', 'end_date', 'duration'] | ||
ordering = ('start_date',) | ||
readonly_fields = ('duration',) | ||
form = forms.SystemMaintenanceAdminForm |
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,62 @@ | ||
import pytz | ||
|
||
from django import forms | ||
from django.conf import settings | ||
from datetime import datetime, timedelta | ||
|
||
from wildlifecompliance.components.main.models import SystemMaintenance | ||
|
||
|
||
class SystemMaintenanceAdminForm(forms.ModelForm): | ||
class Meta: | ||
model = SystemMaintenance | ||
fields = '__all__' | ||
|
||
MSG = 'Start date cannot be before an existing records latest end_date. Start Date must be after' | ||
|
||
def clean(self): | ||
cleaned_data = self.cleaned_data | ||
start_date = cleaned_data.get('start_date') | ||
end_date = cleaned_data.get('end_date') | ||
try: | ||
latest_obj = SystemMaintenance.objects.exclude( | ||
id=self.instance.id | ||
).latest('start_date') | ||
|
||
except Exception: | ||
latest_obj = SystemMaintenance.objects.none() | ||
tz_local = pytz.timezone(settings.TIME_ZONE) # start_date.tzinfo | ||
# tz_utc = pytz.timezone('utc') # latest_obj.start_date.tzinfo | ||
|
||
if latest_obj: | ||
latest_end_date = latest_obj.end_date.astimezone(tz=tz_local) | ||
if self.instance.id: | ||
if start_date < latest_end_date and start_date \ | ||
< self.instance.start_date.astimezone(tz_local): | ||
|
||
raise forms.ValidationError('{0} {1}'.format( | ||
self.MSG, | ||
latest_end_date.ctime() | ||
)) | ||
else: | ||
if start_date < latest_end_date: | ||
raise forms.ValidationError('{0} {1}'.format( | ||
self.MSG, | ||
latest_end_date.ctime() | ||
)) | ||
|
||
if self.instance.id: | ||
if start_date < datetime.now(tz=tz_local) - timedelta(minutes=5) \ | ||
and start_date < self.instance.start_date.astimezone(tz_local): | ||
|
||
raise forms.ValidationError('Start date cannot be edited to be further in the past') | ||
else: | ||
if start_date < datetime.now(tz=tz_local) - timedelta(minutes=5): | ||
raise forms.ValidationError('Start date cannot be in the past') | ||
|
||
if end_date < start_date: | ||
raise forms.ValidationError('End date cannot be before start date') | ||
|
||
super(SystemMaintenanceAdminForm, self).clean() | ||
|
||
return cleaned_data |
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
Oops, something went wrong.