Permalink
Browse files

Merge branch 'master' into selectest

  • Loading branch information...
2 parents ed3573d + 68364a7 commit f2079523d7ebdf7fe214422184f60517343ad84d @marc1s committed Apr 12, 2012
@@ -46,12 +46,10 @@ class GenericTabbedAdmin(SchemaModelAdmin):
show_tabbed_fieldsets = True
class LexicalConceptualResourceInfoAdmin(SchemaModelAdmin):
- hidden_fields = ('lexicalConceptualResourceMediaType', )
readonly_fields = ('lexicalConceptualResourceMediaType', )
show_tabbed_fieldsets = True
class LanguageDescriptionInfoAdmin(SchemaModelAdmin):
- hidden_fields = ('languageDescriptionMediaType', )
readonly_fields = ('languageDescriptionMediaType', )
show_tabbed_fieldsets = True
@@ -70,8 +68,8 @@ def __init__(self, model, admin_site):
except:
pass
- def build_fieldsets_from_schema(self, include_inlines=False):
- fieldsets = super(CorpusAudioModelAdmin, self).build_fieldsets_from_schema(include_inlines)
+ def build_fieldsets_from_schema(self, include_inlines=False, inlines=()):
+ fieldsets = super(CorpusAudioModelAdmin, self).build_fieldsets_from_schema(include_inlines, inlines)
for fieldset in fieldsets:
# name = fieldset[0]
values = fieldset[1]
@@ -417,7 +417,7 @@ def uploaddata_view(self, request, object_id, extra_context=None):
context_instance)
- def build_fieldsets_from_schema(self, include_inlines=False):
+ def build_fieldsets_from_schema(self, include_inlines=False, inlines=()):
"""
Builds fieldsets using SchemaModel.get_fields().
"""
@@ -458,17 +458,11 @@ def build_fieldsets_from_schema(self, include_inlines=False):
_visible_content_fields_verbose_names = []
for _field_name in _fields[_field_status]:
- # Two possible reasons why a field might be encoded as an inline:
- # - either it's a OneToOneField and we have put
- # it into tht eexclusion list;
- # - or it's a reverse foreigh key, so it is not a field.
- # In both cases, we only include it in visible fields if
- # include_inlines is requested.
_is_visible = False
- if self.is_field(_field_name) and _field_name not in exclusion_list:
+ if self.is_visible_as_normal_field(_field_name, exclusion_list):
_is_visible = True
_fieldname_to_append = _field_name
- elif include_inlines:
+ elif self.is_visible_as_inline(_field_name, include_inlines, inlines):
_is_visible = True
_fieldname_to_append = encode_as_inline(_field_name)
@@ -6,15 +6,14 @@
from metashare.repository.editor.editorutils import encode_as_inline
-
class SchemaModelLookup(object):
show_tabbed_fieldsets = False
def is_field(self, name):
- return not name.endswith('_set')
+ return not self.is_inline(name)
def is_inline(self, name):
- return not self.is_field(name)
+ return name.endswith('_set')
def is_required_field(self, name):
@@ -26,7 +25,13 @@ def is_required_field(self, name):
return name in _fields['required']
- def build_fieldsets_from_schema_plain(self, include_inlines=False):
+ def is_visible_as_normal_field(self, field_name, exclusion_list):
+ return self.is_field(field_name) and field_name not in exclusion_list
+
+ def is_visible_as_inline(self, field_name, include_inlines, inlines):
+ return include_inlines and (field_name in inlines or self.is_inline(field_name))
+
+ def build_fieldsets_from_schema_plain(self, include_inlines=False, inlines=()):
"""
Builds fieldsets using SchemaModel.get_fields().
"""
@@ -56,30 +61,17 @@ def build_fieldsets_from_schema_plain(self, include_inlines=False):
_visible_fields = []
for _field_name in _fields:
- if _field_name in exclusion_list:
- continue
- # Two possible reasons why a field might be encoded as an inline:
- # - either it's a OneToOneField and we have put
- # it into tht eexclusion list;
- # - or it's a reverse foreigh key, so it is not a field.
- # In both cases, we only include it in visible fields if
- # include_inlines is requested.
- _is_visible = False
- if self.is_field(_field_name):
- _is_visible = True
- _fieldname_to_append = _field_name
- elif include_inlines:
- _is_visible = True
- _fieldname_to_append = encode_as_inline(_field_name)
- if _is_visible:
- _visible_fields.append(_fieldname_to_append)
+ if self.is_visible_as_normal_field(_field_name, exclusion_list):
+ _visible_fields.append(_field_name)
+ elif self.is_visible_as_inline(_field_name, include_inlines, inlines):
+ _visible_fields.append(encode_as_inline(_field_name))
_fieldsets = ((None,
{'fields': _visible_fields + list(_hidden_fields)}
),)
return _fieldsets
- def build_fieldsets_from_schema_tabbed(self, include_inlines):
+ def build_fieldsets_from_schema_tabbed(self, include_inlines=False, inlines=()):
"""
Builds fieldsets using SchemaModel.get_fields(),
for tabbed viewing (required/recommended/optional).
@@ -116,29 +108,17 @@ def build_fieldsets_from_schema_tabbed(self, include_inlines):
_visible_fields_verbose_names = []
for _field_name in _fields[_field_status]:
- if _field_name in exclusion_list:
- continue
-
- # Two possible reasons why a field might be encoded as an inline:
- # - either it's a OneToOneField and we have put
- # it into tht eexclusion list;
- # - or it's a reverse foreigh key, so it is not a field.
- # In both cases, we only include it in visible fields if
- # include_inlines is requested.
- _is_visible = False
- if self.is_field(_field_name):
- _is_visible = True
- _fieldname_to_append = _field_name
- elif include_inlines:
- _is_visible = True
- _fieldname_to_append = encode_as_inline(_field_name)
-
- # And now put the field where it belongs:
- if _is_visible:
- _visible_fields.append(_fieldname_to_append)
- _visible_fields_verbose_names.append(
- self.model.get_verbose_name(_field_name))
-
+ if self.is_visible_as_normal_field(_field_name, exclusion_list):
+ _visible_fields.append(_field_name)
+ is_visible = True
+ elif self.is_visible_as_inline(_field_name, include_inlines, inlines):
+ _visible_fields.append(encode_as_inline(_field_name))
+ is_visible = True
+ else:
+ is_visible = False
+
+ if is_visible:
+ _visible_fields_verbose_names.append(self.model.get_verbose_name(_field_name))
if len(_visible_fields) > 0:
_detail = ', '.join(_visible_fields_verbose_names)
@@ -151,17 +131,18 @@ def build_fieldsets_from_schema_tabbed(self, include_inlines):
return _fieldsets
- def build_fieldsets_from_schema(self, include_inlines=False):
+ def build_fieldsets_from_schema(self, include_inlines=False, inlines=()):
if self.show_tabbed_fieldsets:
- return self.build_fieldsets_from_schema_tabbed(include_inlines)
- return self.build_fieldsets_from_schema_plain(include_inlines)
+ return self.build_fieldsets_from_schema_tabbed(include_inlines, inlines)
+ return self.build_fieldsets_from_schema_plain(include_inlines, inlines)
def get_fieldsets(self, request, obj=None):
- return self.build_fieldsets_from_schema(include_inlines=False)
+ return self.build_fieldsets_from_schema()
def get_fieldsets_with_inlines(self, request, obj=None):
- return self.build_fieldsets_from_schema(include_inlines=True)
+ inline_names = [inline.parent_fk_name for inline in self.inline_instances if hasattr(inline, 'parent_fk_name') ]
+ return self.build_fieldsets_from_schema(include_inlines=True, inlines=inline_names)
def get_inline_classes(self, model, status):
@@ -67,7 +67,7 @@ def __init__(self, model, admin_site):
if not has_widget:
self.filter_horizontal.append(fld)
super(SchemaModelAdmin, self).__init__(model, admin_site)
- # Revers inline code:
+ # Reverse inline code:
self.no_inlines = self.no_inlines or []
self.exclude = self.exclude or []
# Prepare inlines for the required one2one fields:
@@ -7,6 +7,7 @@
from metashare.repository.models import corpusInfoType_model, \
toolServiceInfoType_model, lexicalConceptualResourceInfoType_model, \
languageDescriptionInfoType_model
+from metashare.settings import MEDIA_URL
register = template.Library()
@@ -85,23 +86,22 @@ def render(self, context):
result = list(set(result))
result.sort()
- image_tag = ""
- # Use images instead of plain text when displaying media type
+ # use images instead of plain text when displaying media types
+ image_tag = ""
if "text" in result:
- image_tag = '<img src="/site_media/css/sexybuttons/images' + \
- '/icons/silk/page_white_text_media_type.png" title="text" />'
+ image_tag = '<img src="{}css/sexybuttons/images/icons/silk/page' \
+ '_white_text_media_type.png" title="text" />'.format(MEDIA_URL)
if "audio" in result:
- image_tag = image_tag + ' <img src="/site_media/css/sexybuttons' + \
- '/images/icons/silk/music.png" title="audio" />'
+ image_tag = image_tag + ' <img src="{}css/sexybuttons/images/' \
+ 'icons/silk/music.png" title="audio" />'.format(MEDIA_URL)
if "image" in result:
- image_tag = image_tag + ' <img src="/site_media/css/sexybuttons' + \
- '/images/icons/silk/picture.png" title="image" />'
+ image_tag = image_tag + ' <img src="{}css/sexybuttons/images/' \
+ 'icons/silk/picture.png" title="image" />'.format(MEDIA_URL)
if "video" in result:
- image_tag = image_tag + ' <img src="/site_media/css/sexybuttons' + \
- '/images/icons/silk/film.png" title="video" />'
-
-
+ image_tag = image_tag + ' <img src="{}css/sexybuttons/images/' \
+ 'icons/silk/film.png" title="video" />'.format(MEDIA_URL)
+
return image_tag
def resource_media_types(parser, token):
@@ -242,6 +242,14 @@ def test_one2one_distribution_uses_related_widget(self):
self.assertContains(response, 'related-widget-wrapper-change-link" id="edit_id_distributionInfo"',
msg_prefix='One-to-one field "distributionInfo" not rendered using related widget')
+ def test_licenceinfo_inline_is_present(self):
+ client = self.client_with_user_logged_in(self.editor_login)
+ resource = self.import_test_resource()
+ response = client.get('{}repository/distributioninfotype_model/{}/'.format(ADMINROOT, resource.distributionInfo.id))
+ self.assertContains(response, '<div class="inline-group" id="licenceinfotype_model_set-group">',
+ msg_prefix='expected licence info inline')
+
+
def test_one2one_sizepervalidation_is_hidden(self):
client = self.client_with_user_logged_in(self.editor_login)
resource = self.import_test_resource()
@@ -266,6 +274,14 @@ def test_backref_is_hidden(self):
self.assertContains(response, 'type="hidden" name="back_to_corpusmediatypetype_model"',
msg_prefix='Back reference should have been hidden')
+ def test_linguality_inline_is_present(self):
+ client = self.client_with_user_logged_in(self.editor_login)
+ resource = self.import_test_resource()
+ corpustextinfo = resource.resourceComponentType.corpusMediaType.corpustextinfotype_model_set.all()[0]
+ response = client.get('{}repository/corpustextinfotype_model/{}/'.format(ADMINROOT, corpustextinfo.id))
+ self.assertContains(response, '<div class="form-row lingualityType">',
+ msg_prefix='expected linguality inline')
+
def test_hidden_field_is_not_referenced_in_fieldset_label(self):
client = self.client_with_user_logged_in(self.editor_login)
resource = self.import_test_resource(LEX_CONC_RES_XML)
@@ -138,9 +138,66 @@ <h1><a href="#">Administrative Information</a></h1>
}
$("h1").not("h1:contains('General')").not("h1:contains('Tool')").not("div[id$=protodiv] h1").children("a:contains('Edit')").attr('class', '');
-
</script>
+
+ <script>
+ //for text fields and calendar
+ $('div.form-row.errors div input').change(textfield);
+ //for related-widget-wrapper
+ $("div.field-box.errors input.related-widget-wrapper").change(oneToOne);
+
+ function textfield() {
+ var input_value = $(this).attr('value');
+ if( input_value ) {
+ $(this).parents('div').siblings(".errorlist").remove();
+ $(this).parents('fieldset .form-row').removeClass("errors");
+ }
+ }
+ function oneToOne() {
+ var input_value = $(this).attr('value');
+ if( input_value ) {
+ $(this).siblings(".errorlist").remove();
+ $(this).parents('div.field-box').removeClass("errors");
+ }
+ }
+
+ $("fieldset .module div div ul li input").each(function() {
+ $(this).trigger('change');
+ });
+
+ //for calendar when user inserts input in textfield
+ $("div.form-row div input").each(function() {
+ $(this).trigger('change');
+ });
+
+ //for calendar when user clicks on calendar options
+ $('div.form-row.errors div span.datetimeshortcuts a').live("click",function(){
+ $(this).parents('div').siblings(".errorlist").remove();
+ $(this).parents('div').removeClass("errors");
+ });
+
+ //related-widget-wrapper
+ $("div.field-box.errors input.related-widget-wrapper").each(function() {
+ $(this).trigger('change');
+ });
+
+ //for many-to-many widgets (errors disappear only when you click directly on selector-chosen field)
+ $(document).on("change", "div.form-row div.errors div.selector-chosen select.filtered", function() {
+ if( $(this).children().length > 0 ) {
+ $(this).parents('div').siblings(".errorlist").remove();
+ $(this).parents('div').removeClass("errors");
+ }
+ });
+
+ //for drop-down menus
+ $(document).on("change", "div.form-row.errors select", function() {
+ $(this).parents('div').siblings(".errorlist").remove();
+ $(this).parents('div').removeClass("errors");
+ });
+
+ </script>
+
<script>
var link;
$("ul.errorlist").each(function() {
@@ -155,7 +212,6 @@ <h1><a href="#">Administrative Information</a></h1>
});
</script>
-
{% block after_field_sets %}{% endblock %}
{% block after_related_objects %}{% endblock %}
Oops, something went wrong.

0 comments on commit f207952

Please sign in to comment.