Skip to content

Commit

Permalink
Due to this problem openwisp/django-swappable-models#12, must remove …
Browse files Browse the repository at this point in the history
…migration files from core, and force user to run makemigrations upon installing waves core module. Just in cas someone wants to override defaults Service or Submission model
  • Loading branch information
Marc Chjakiachvili committed Sep 15, 2017
1 parent 15b7ca0 commit 5256132
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 818 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ ENV/
/media/*
!/media/.gitkeep
*.sqlite3
/waves/wcore/migrations/*
!/waves/wcore/migrations/.gitkeep
!/waves/templates/waves/parts/
!/waves/forms/lib/
/waves/tests/settings.ini
Expand Down
12 changes: 3 additions & 9 deletions waves/wcore/admin/forms/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Service = swapper.load_model("wcore", "Service")

__all__ = ['ServiceForm', 'ImportForm', 'SubmissionInlineForm', 'InputInlineForm', 'SubmissionExitCodeForm',
'SubmissionOutputForm', 'SampleDepForm', 'InputSampleForm', 'InputSampleForm2', 'SampleDepForm2',
'SubmissionOutputForm', 'SampleDepForm', 'InputSampleForm', 'SampleDepForm2',
'ServiceSubmissionForm']


Expand Down Expand Up @@ -122,6 +122,8 @@ def __init__(self, *args, **kwargs):
if isinstance(self.instance, ListParam) or isinstance(self.instance, BooleanParam):
self.fields['default'] = forms.ChoiceField(choices=self.instance.choices, initial=self.instance.default)
self.fields['default'].required = False
if isinstance(self.instance, FileInput):
self.fields['default'].widget.attrs['readonly'] = True
if self.instance.parent is not None:
self.fields['required'].widget.attrs['disabled'] = 'disabled'
self.fields['required'].widget.attrs['title'] = 'Inputs with dependencies must be optional'
Expand All @@ -144,14 +146,6 @@ def label_from_instance(self, obj):
return '(%s - %s) %s' % (obj.submission.service.name, obj.submission.name, obj)


class InputSampleForm2(forms.ModelForm):
file_input = InputSampleModelChoiceField(queryset=FileInput.objects.all())

class Meta:
model = FileInputSample
fields = '__all__'


def get_related_to():
return AParam.objects.not_instance_of(FileInput)

Expand Down
15 changes: 7 additions & 8 deletions waves/wcore/admin/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.contrib import messages
from django.contrib.admin.options import IS_POPUP_VAR, TO_FIELD_VAR
from django.core.urlresolvers import reverse
from django.db import models
from django.db import models, DatabaseError
from django.http import HttpResponseRedirect
from django.template.response import SimpleTemplateResponse
from django.utils import six
Expand All @@ -25,7 +25,7 @@

__all__ = ['AllParamModelAdmin']

required_base_fields = ['label', 'name', 'cmd_format', 'required']
required_base_fields = ['label', 'name', 'cmd_format', 'required', 'submission']
extra_base_fields = ['help_text', 'multiple', 'api_name', 'default']
dependencies_fields = ['parent', 'when_value']

Expand Down Expand Up @@ -57,7 +57,6 @@ class AParamAdmin(WavesModelAdmin, PolymorphicChildModelAdmin):

@property
def popup_response_template(self):
print "jet in apps ", ('jet' in settings.INSTALLED_APPS)
if 'jet' in settings.INSTALLED_APPS:
return 'admin/waves/baseparam/jet_popup_response.html'
else:
Expand Down Expand Up @@ -94,7 +93,8 @@ def save_model(self, request, obj, form, change):
obj.submission = request.submission
try:
super(AParamAdmin, self).save_model(request, obj, form, change)
except BaseException:
except DatabaseError as e:
messages.error(request, "Error occurred saving param %s" % e.message)
pass
else:
messages.success(request, "Param successfully saved")
Expand All @@ -112,7 +112,6 @@ def get_form(self, request, obj=None, **kwargs):
form.base_fields['submission'].widget = forms.HiddenInput()
if request.submission or (obj and obj.submission):
form.base_fields['submission'].initial = request.submission.pk if request.submission else obj.submission.pk
# form.fields['submission'].initial = request.submission
return form

def add_view(self, request, form_url='', extra_context=None):
Expand Down Expand Up @@ -144,8 +143,8 @@ def response_add(self, request, obj, post_url_continue=None):
'value': six.text_type(value),
'obj': six.text_type(obj),
})
return SimpleTemplateResponse(self.popup_response_template, {
'popup_response_data': popup_response_data,
return SimpleTemplateResponse(self.popup_response_template, context={
'popup_response_data': popup_response_data
})
elif "_addanother" in request.POST:
# TODO add new param and setup submission foreign key
Expand Down Expand Up @@ -200,7 +199,7 @@ class FileInputAdmin(AParamAdmin):
inlines = [FileInputSampleInline, SampleDependentInputInline]
# TODO activate sample selection dependencies (both on forms and on submission)
# TOD, SampleDependentInputInline,]
readonly_fields = ['regexp', ]
# readonly_fields = ['default', ]
fieldsets = [
('General', {
'fields': required_base_fields + ['max_size', 'allowed_extensions'],
Expand Down
1 change: 1 addition & 0 deletions waves/wcore/admin/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class OrgRepeatGroupInline(CompactInline):

class OrganizeInputInline(SortableInlineAdminMixin, admin.TabularInline):
model = AParam
form = InputInlineForm
classes = ["collapse", ]
fields = ['class_label', 'label', 'name', 'multiple', 'required', 'default']
readonly_fields = ['class_label']
Expand Down
4 changes: 0 additions & 4 deletions waves/wcore/forms/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
logger = logging.getLogger(__name__)


class ServiceForm(forms.ModelForm):
pass


class ServiceSubmissionForm(forms.ModelForm):
class Meta:
model = Submission
Expand Down
Loading

0 comments on commit 5256132

Please sign in to comment.