Skip to content

Commit

Permalink
DigitalCampus#300: Changing the way the helper view is included
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed Apr 22, 2016
1 parent fcf0905 commit abc661b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
6 changes: 1 addition & 5 deletions oppia/forms.py
Expand Up @@ -130,6 +130,7 @@ def __init__(self, *args, **kwargs):
super(CohortForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.form_tag = False
self.helper.label_class = 'col-sm-3 col-md-2'
self.helper.field_class = 'col-sm-9 col-md-10 col-lg-9'
self.helper.layout = Layout(
Expand All @@ -142,11 +143,6 @@ def __init__(self, *args, **kwargs):
'students',
css_class='hidden-fields'
),
CohortHelperDiv(),
Div(
Submit('submit', _(u'Save'), css_class='btn btn-default'),
css_class='col-lg-offset-2 col-lg-4',
),
)


Expand Down
15 changes: 15 additions & 0 deletions oppia/templates/oppia/cohort-form.html
Expand Up @@ -16,8 +16,23 @@

<h2>{% trans 'Cohort' %}</h2>



<form class="form-horizontal" method="post">

{% crispy form %}

{% include "oppia/includes/cohort-helper.html" %}

<div class="col-lg-offset-2 col-lg-4">
<input type="submit" name="submit" value="Save" class="btn btn-primary btn btn-default" id="submit-id-submit">
</div>

</form>




{% endblock %}
{% block extra_scripts %}
<script src="{% static "oppia/js/oppia.chart-utils.js" %}"></script>
Expand Down
6 changes: 3 additions & 3 deletions oppia/templates/oppia/includes/cohort-helper.html
Expand Up @@ -37,7 +37,7 @@ <h4>{% trans 'Selected courses' %}</h4>
<div class="col-sm-6" id="add-courses-block" style="display:none;">
<h4>{% trans 'Available courses' %}</h4>
<div id="available-courses">
{% include "oppia/profile/export_users_table.html" %}

</div>
</div>
</div>
Expand Down Expand Up @@ -77,7 +77,7 @@ <h4>{% trans 'Selected teachers' %}</h4>
<div class="col-sm-6" id="add-teachers-block" style="display:none;">
<h4>{% trans 'Available students' %}</h4>
<div id="available-teachers">
{% include "oppia/profile/export_users_table.html" %}
{% include "oppia/profile/users-paginated-list.html" %}
</div>
</div>
</div>
Expand Down Expand Up @@ -117,7 +117,7 @@ <h4>{% trans 'Selected students' %}</h4>
<div class="col-sm-6" id="add-students-block" style="display:none;">
<h4>{% trans 'Available students' %}</h4>
<div id="available-students">
{% include "oppia/profile/export_users_table.html" %}
{% include "oppia/profile/users-paginated-list.html" %}
</div>
</div>
</div>
30 changes: 27 additions & 3 deletions oppia/views.py
Expand Up @@ -573,7 +573,24 @@ def cohort_list_view(request):
return render_to_response('oppia/course/cohorts-list.html',
{'cohorts':cohorts,},
context_instance=RequestContext(request))



def get_paginated_users(request):
default_order = 'date_joined'
ordering = request.GET.get('order_by', None)
if ordering is None:
ordering = default_order

users = User.objects.all().order_by(ordering).select_related('api_key__key')
paginator = Paginator(users, 5)

try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1

return ordering, paginator.page(page)

def cohort_add(request):
if not can_add_cohort(request):
return HttpResponse('Unauthorized', status=401)
Expand Down Expand Up @@ -626,8 +643,15 @@ def cohort_add(request):

else:
form = CohortForm() # An unbound form

return render(request, 'oppia/cohort-form.html',{'form': form,})
ordering, users = get_paginated_users(request)

print ordering
return render(request, 'oppia/cohort-form.html',{
'form': form,
'page': users,
'page_ordering':ordering,
'users_list_template':'default'
},context_instance=RequestContext(request))

def cohort_view(request,cohort_id):
cohort, response = can_view_cohort(request,cohort_id)
Expand Down

0 comments on commit abc661b

Please sign in to comment.