Skip to content

Commit

Permalink
Changed Css / js places - recommit crispy forms Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Chjakiachvili committed Jul 13, 2017
1 parent 107ed10 commit 66e5150
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ ENV/
!/waves/templates/waves/parts/
!/waves/forms/lib/
/waves/tests/settings.ini
/staticfiles/
!/waves/core/forms/lib/
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include LICENSE.md
include README.md
recursive-include waves/static *
recursive-include waves/templates *
recursive-include waves/core/static *
recursive-include waves/core/templates *
recursive-include docs *
recursive-exclude waves_core *
8 changes: 4 additions & 4 deletions waves/core/admin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ class WavesModelAdmin(ModelAdmin):
""" Base models admin including global medias """
class Media:
js = (
'waves/admin/js/admin.js',
'waves/admin/js/modal.js'
'admin/waves/js/admin.js',
'admin/waves/js/modal.js'
)
css = {
'screen': ('waves/admin/css/admin.css',
'waves/admin/css/modal.css')
'screen': ('admin/waves/css/admin.css',
'admin/waves/css/modal.css')
}


Expand Down
4 changes: 2 additions & 2 deletions waves/core/admin/forms/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Meta:

class Media:
""" Medias """
js = ('waves/admin/js/runner.js',
'waves/admin/js/connect.js')
js = ('admin/waves/js/runner.js',
'admin/waves/js/connect.js')

update_init_params = BooleanField(required=False, label='Reset related services')

Expand Down
4 changes: 2 additions & 2 deletions waves/core/admin/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class ServiceAdmin(ExportInMassMixin, DuplicateInMassMixin, MarkPublicInMassMixi
""" Service model objects Admin"""

class Media:
js = ('waves/admin/js/services.js',
'waves/admin/js/connect.js')
js = ('admin/waves/js/services.js',
'admin/waves/js/connect.js')

form = ServiceForm
filter_horizontal = ['restricted_client']
Expand Down
13 changes: 13 additions & 0 deletions waves/core/forms/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import unicode_literals


class BaseHelper(object):

def set_layout(self, service_input):
raise NotImplementedError()

def init_layout(self, fields):
pass

def end_layout(self):
pass
111 changes: 111 additions & 0 deletions waves/core/forms/lib/crispy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from __future__ import unicode_literals

from crispy_forms.bootstrap import *
from crispy_forms.helper import FormHelper as BaseFormHelper
from crispy_forms.layout import *

from waves.core.models.inputs import *
from waves.core.models.samples import FileInputSample
from . import BaseHelper

__all__ = ['FormHelper', 'FormLayout']


class FormHelper(BaseFormHelper, BaseHelper):
"""
Extended FormHelper based on crispy FormHelper,
Dynamic form fields according to inputs types and parameters
"""
# TODO Created dedicated field for (copy_paste field)

def __init__(self, form=None, **kwargs):
form_tag = kwargs.pop('form_tag', True)
form_class = kwargs.pop('form_class', 'form-horizontal')
label_class = kwargs.pop('label_class', 'col-lg-4')
field_class = kwargs.pop('field_class', 'col-lg-8 text-left')
super(FormHelper, self).__init__(form)
self.form_tag = form_tag
self.form_class = form_class
self.label_class = label_class
self.field_class = field_class
self.render_unmentioned_fields = False
self.layout = Layout()

def set_layout(self, service_input, form):
"""
Setup layout for displaying a form for a Service, append extra fields for forms if needed
"""
css_class = ""
field_id = "id_" + service_input.name
dependent_on = ""
dependent_4_value = ""
if service_input.dependents_inputs.count() > 0:
css_class = "has_dependent"
field_dict = dict(
css_class=css_class,
id=field_id,
title=service_input.help_text,
)
if service_input.parent is not None:
field_id += '_' + service_input.parent.name + '_' + service_input.when_value
dependent_on = service_input.parent.name
dependent_4_value = service_input.when_value
field_dict.update(dict(dependent_on=service_input.parent.name,
dependent_4_value=service_input.when_value))
when_value = form.data.get(service_input.parent.name, service_input.parent.default)
if service_input.when_value != when_value:
field_dict.update(dict(wrapper_class="hid_dep_parameter", disabled="disabled"))
else:
field_dict.update(dict(wrapper_class="dis_dep_parameter"))
input_field = Field(service_input.name, **field_dict)
if isinstance(service_input, FileInput) and not service_input.multiple:
cp_input_field = Field('cp_' + service_input.name, css_id='id_' + 'cp_' + service_input.name)
tab_input = Tab(
"File Upload",
input_field,
css_id='tab_' + service_input.name
)
if service_input.input_samples.count() > 0:
all_sample = []
for sample in service_input.input_samples.all():
all_sample.append(Field('sp_' + service_input.name + '_' + str(sample.pk)))
tab_input.extend(all_sample)
self.layout.append(
Div(
TabHolder(
tab_input,
Tab(
"Copy/paste content",
cp_input_field,
css_class='copypaste',
css_id='tab_cp_' + service_input.name,
),
css_id='tab_holder_' + service_input.name,
),
id='tab_pane_' + service_input.name,
css_class='copypaste',
dependent_on=dependent_on,
dependent_4_value=dependent_4_value
)
)
elif not isinstance(service_input, FileInputSample):
self.layout.append(
input_field
)

def init_layout(self, fields):
l_fields = []
for field in fields:
l_fields.append(Field(field))
self.layout = Layout()
self.layout.extend(l_fields)
return self.layout

def end_layout(self):
self.layout.extend([
HTML('<HR/>'),
FormActions(
Reset('reset', 'Reset form'),
Submit('save', 'Submit a job')
)
])
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>{% trans 'My Popup closing...' %}</title>
<script src="{% static "jet/js/build/bundle.min.js" %}"></script>
<script src="{% static "admin/js/jquery.init.js" %}"></script>
<script src="{% static "waves/admin/js/admin.js" %}"></script>
<script src="{% static "admin/waves/js/admin.js" %}"></script>
</head>
<body>
{% jet_popup_response_data as data %}
Expand Down
2 changes: 1 addition & 1 deletion waves/core/templates/admin/waves/service/service_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
crossorigin="anonymous">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-toggle/2.2.2/css/bootstrap-toggle.css"/>
<link rel="stylesheet" href="{% static 'waves/css/../../../../static/waves/admin/css/forms.css' %}">
<link rel="stylesheet" href="{% static 'admin/waves/css/forms.css' %}">
{% endblock %}

{% block scripts %}
Expand Down
2 changes: 1 addition & 1 deletion waves/core/templates/waves/api/service_api_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles crispy_forms_tags %}
<script src="{% static 'waves/js/services.js' %}"></script>
<link rel="stylesheet" href="{% static 'waves/admin/css/forms.css' %}">
<link rel="stylesheet" href="{% static 'admin/waves/css/forms.css' %}">
{% crispy form %}
2 changes: 1 addition & 1 deletion waves/core/templates/waves/services/service_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% block styles %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'waves/admin/css/forms.css' %}">
<link rel="stylesheet" href="{% static 'admin/waves/css/forms.css' %}">
{% endblock %}

{% block scripts %}
Expand Down
3 changes: 2 additions & 1 deletion waves_core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@
STATIC_URL = '/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
os.path.join(BASE_DIR, "waves", "core", "static"),
]

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
Expand Down

0 comments on commit 66e5150

Please sign in to comment.