Skip to content

Commit

Permalink
Added a filter to list only unpublished survey responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Ann-Cathrin Näsström committed Jul 4, 2014
1 parent 93f3cd1 commit 23ea986
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 10 additions & 1 deletion libstat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,22 @@ def __unicode__(self):

class SurveyResponseQuerySet(QuerySet):

def by_year_or_group(self, sample_year=None, target_group=None ):
def by_year_or_group(self, sample_year=None, target_group=None):
filters = {}
if target_group:
filters["target_group"] = target_group
if sample_year:
filters["sample_year"] = int(sample_year)
return self.filter(__raw__=filters)

def unpublished_by_year_or_group(self, sample_year=None, target_group=None):
filters = {}
if target_group:
filters["target_group"] = target_group
if sample_year:
filters["sample_year"] = int(sample_year)
filters["published_at__isnull"] = True
return self.filter(__raw__=filters)


class SurveyObservation(EmbeddedDocument):
Expand Down
6 changes: 3 additions & 3 deletions libstat/templates/libstat/survey_responses.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ <h3 class="panel-title">{% trans "Enkätsvar uppdelat på målgrupp och år" %}<
<option value="school" {% ifequal target_group "school" %}selected="selected"{% endifequal %}>{% trans "Skolbibliotek" %}</option>
</select>
</div>
<!-- <div class="form-group">
<input type="checkbox" name="unpublished_only" value="true"/>
<div class="form-group">
<input type="checkbox" name="unpublished_only" value="True" {% if unpublished_only == True %}checked="checked"{% endif %}/>
{% trans "Endast opublicerade" %}
</div> -->
</div>
<div class="form-group">
<button type="submit" name="action" value="list" class="btn btn-default">{% trans "Lista enkätsvar" %}</button>
</div>
Expand Down
12 changes: 11 additions & 1 deletion libstat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,25 @@ def survey_responses(request):
action = request.GET.get("action", "")
target_group = request.GET.get("target_group", "")
sample_year = request.GET.get("sample_year", "")
unpublished_only = request.GET.get("unpublished_only", False);
if "True" == unpublished_only:
unpublished_only = True
else:
unpublished_only = False

if action == "list":
s_responses = SurveyResponse.objects.by_year_or_group(sample_year=sample_year, target_group=target_group).order_by("library")
# TODO: Pagination
if unpublished_only:
s_responses = SurveyResponse.objects.unpublished_by_year_or_group(sample_year=sample_year, target_group=target_group).order_by("library")
else:
s_responses = SurveyResponse.objects.by_year_or_group(sample_year=sample_year, target_group=target_group).order_by("library")

context = {
'sample_years': sample_years,
'survey_responses': s_responses,
'target_group': target_group,
'sample_year': sample_year,
'unpublished_only': unpublished_only,
'bibdb_library_base_url': u"{}/library".format(settings.BIBDB_BASE_URL)
}
return render(request, 'libstat/survey_responses.html', context)
Expand Down

0 comments on commit 23ea986

Please sign in to comment.