Skip to content

Commit

Permalink
add more rows to data extraction text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorfs committed Sep 9, 2015
1 parent 71ef56e commit 0e3a9c9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ $(function () {
});
}

$(".data-extraction-panel input[type=text]").change(function () {
$(".data-extraction-panel input[type='text'], .data-extraction-panel select, .data-extraction-panel textarea").change(function () {
save_data_extraction_field($(this));
});

$(".data-extraction-panel select").change(function () {
save_data_extraction_field($(this));
});

$(".data-extraction-panel input[type=checkbox]").click(function () {
$(".data-extraction-panel input[type='checkbox']").click(function () {
save_data_extraction_field($(this));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load staticfiles %}

{% block javascript %}
<script type="text/javascript" src="{% static 'js/conducting_data_extraction.js' %}?_=2"></script>
<script type="text/javascript" src="{% static 'js/conducting_data_extraction.js' %}?_=3"></script>
{% endblock javascript %}

{% block tab_content %}
Expand Down
20 changes: 12 additions & 8 deletions parsifal/reviews/conducting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def build_data_extraction_field_row(article, field):
except Exception, e:
extraction = None

if field.field_type == field.BOOLEAN_FIELD:
if field.field_type == DataExtractionField.BOOLEAN_FIELD:
true = u''
false = u''
if extraction != None:
Expand All @@ -279,14 +279,14 @@ def build_data_extraction_field_row(article, field):
<option value="False"{1}>False</option>
</select>'''.format(true, false)

elif field.field_type == field.DATE_FIELD:
elif field.field_type == DataExtractionField.DATE_FIELD:
if extraction != None:
value = extraction.get_date_value_as_string()
else:
value = u''
str_field = u'<input type="text" class="form-control" name="{0}-{1}-value" maxlength="10" value="{2}">'.format(article.id, field.id, escape(value))

elif field.field_type == field.SELECT_ONE_FIELD:
elif field.field_type == DataExtractionField.SELECT_ONE_FIELD:
str_field = u'''<select name="{0}-{1}-value" class="form-control">
<option value="">Select...</option>'''.format(article.id, field.id)
for value in field.get_select_values():
Expand All @@ -297,20 +297,24 @@ def build_data_extraction_field_row(article, field):
str_field += u'''<option value="{0}"{1}>{2}</option>'''.format(value.id, selected, escape(value.value))
str_field += u'</select>'

elif field.field_type == field.SELECT_MANY_FIELD:
elif field.field_type == DataExtractionField.SELECT_MANY_FIELD:
for value in field.get_select_values():
if extraction != None and value in extraction.get_value():
checked = ' checked'
else:
checked = ''
str_field += u'<label class="checkbox-inline"><input type="checkbox" name="{0}-{1}-value" value="{2}"{3}>{4}</label> '.format(article.id, field.id, value.id, checked, escape(value.value))

else:
elif field.field_type == DataExtractionField.STRING_FIELD:
value = ''
if extraction != None:
value = extraction.get_value()
else:
value = u''
str_field = u'<input type="text" class="form-control" name="{0}-{1}-value" maxlength="1000" value="{2}">'.format(article.id, field.id, escape(value))
str_field = u'<textarea class="form-control expanding" name="{0}-{1}-value" rows="1">{2}</textarea>'.format(article.id, field.id, escape(value))
else:
value = ''
if extraction != None:
value = extraction.get_value()
str_field = u'<input type="text" class="form-control" maxlength="30" name="{0}-{1}-value" value="{2}">'.format(article.id, field.id, escape(value))

return str_field

Expand Down
19 changes: 19 additions & 0 deletions parsifal/reviews/migrations/0030_auto_20150909_1749.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('reviews', '0029_article_finished_data_extraction'),
]

operations = [
migrations.AlterField(
model_name='dataextraction',
name='value',
field=models.TextField(null=True, blank=True),
),
]
2 changes: 1 addition & 1 deletion parsifal/reviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ class DataExtraction(models.Model):
user = models.ForeignKey(User, null=True)
article = models.ForeignKey(Article)
field = models.ForeignKey(DataExtractionField)
value = models.CharField(max_length=1000, blank=True)
value = models.TextField(blank=True, null=True)
select_values = models.ManyToManyField(DataExtractionLookup)

def _set_boolean_value(self, value):
Expand Down

0 comments on commit 0e3a9c9

Please sign in to comment.