...
 
Commits (2)
......@@ -17,6 +17,8 @@ from django.core.urlresolvers import reverse_lazy
from django.contrib.admin.views.decorators import staff_member_required
from pinax.messages.models import Thread
from pinax.messages.forms import Message
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# from usda_nutrition.models import FoodGroup, FoodDescription, NutrientDefinition, Weight
......@@ -146,14 +148,39 @@ class GoalView(TemplateView):
return context
@method_decorator(login_required, name='dispatch')
class GoalCreate(CreateView):
model = Gbw
form_class = GbwCreateForm
success_url = reverse_lazy('goal')
def get_initial(self):
initial = super(GoalCreate, self).get_initial()
initial.update({'user': self.request.user.id})
return initial
def form_valid(self, form):
"""Force the user to request.user"""
self.object = form.save(commit=False)
self.object.user_id = self.request.user.id
self.object.save()
return super(GoalCreate, self).form_valid(form)
@method_decorator(staff_member_required, name='dispatch')
class DrugList(ListView):
model = Drug
context_object_name = 'drugs'
paginate_by = 10
@method_decorator(login_required, name='dispatch')
class DrugView(TemplateView):
template_name = 'sites/drug.html'
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
......@@ -166,25 +193,7 @@ class DrugView(TemplateView):
context['drug'] = drug
return context
@method_decorator(login_required, name='dispatch')
class GoalCreate(CreateView):
model = Gbw
form_class = GbwCreateForm
success_url = reverse_lazy('goal')
def get_initial(self):
initial = super(GoalCreate, self).get_initial()
initial.update({'user': self.request.user.id})
return initial
def form_valid(self, form):
"""Force the user to request.user"""
self.object = form.save(commit=False)
self.object.user_id = self.request.user.id
self.object.save()
return super(GoalCreate, self).form_valid(form)
@method_decorator(login_required, name='dispatch')
......@@ -213,6 +222,7 @@ class WeightCreate(CreateView):
@method_decorator(login_required, name='dispatch')
class WeightList(ListView):
model = Weight
paginate_by = 10
def toinch(self, height):
return round(height /2.54,2) #last height in inch
......@@ -385,6 +395,7 @@ class ProfileUpdate(UpdateView):
@method_decorator(staff_member_required, name='dispatch')
class UserList(ListView):
model = User
paginate_by = 10
# @method_decorator(login_required, name='dispatch')
......
......@@ -44,7 +44,11 @@
</tr>
</thead>
<tbody>
<<<<<<< HEAD
{% for drug in drugs %}
=======
{% for drug in object_list %}
>>>>>>> 32c26fc420f6afb5ac788df9a4c94ca5aaf65572
<tr>
<td>{{ drug.id }}</td>
......@@ -62,21 +66,29 @@
{% endfor %}
</tbody>
</table>
{% if is_paginated %}
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Prev</a>
</li>
<li class="page-item active">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item"><a class="page-link" href="#">2</a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a>
</li>
<li class="page-item"><a class="page-link" href="#">4</a>
</li>
<li class="page-item"><a class="page-link" href="#">Next</a>
</li>
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">&laquo; قبل</a></li>
{% else %}
<li class="disabled"><span>&laquo; قبل</span></li>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">&raquo; بعد</a></li>
{% else %}
<li class="disabled"><span>&raquo; بعد</span></li>
{% endif %}
</ul>
{% endif %}
</div>
</div>
</div>
......
......@@ -145,21 +145,28 @@
{% endfor %}
</tbody>
</table>
{% if is_paginated %}
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Prev</a>
</li>
<li class="page-item active">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item"><a class="page-link" href="#">2</a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a>
</li>
<li class="page-item"><a class="page-link" href="#">4</a>
</li>
<li class="page-item"><a class="page-link" href="#">Next</a>
</li>
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">&laquo; قبل</a></li>
{% else %}
<li class="disabled"><span>&laquo; قبل</span></li>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<li class="page-item"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">&raquo; بعد</a></li>
{% else %}
<li class="disabled"><span>&raquo; بعد</span></li>
{% endif %}
</ul>
{% endif %}
</div>
</div>
</div>
......
......@@ -26,7 +26,7 @@
<div class="card" style="width:400px">
<div class="card-img-top" style="width:100%">
{% avatar user 256 class="img-circle img-responsive" id="user_avatar"%} </br>
{% avatar user 128 class="img-circle img-responsive" id="user_avatar"%} </br>
{% if object == request.user and request.user.is_authenticated %}
<a href="{% url 'avatar_change' %}">نمایه خود را تغییر دهید</a>
{% endif %}
......
......@@ -57,21 +57,28 @@
</tbody>
</table>
{% if is_paginated %}
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Prev</a>
</li>
<li class="page-item active">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item"><a class="page-link" href="#">2</a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a>
</li>
<li class="page-item"><a class="page-link" href="#">4</a>
</li>
<li class="page-item"><a class="page-link" href="#">Next</a>
</li>
{% if page_obj.has_previous %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">&laquo; قبل</a></li>
{% else %}
<li class="disabled"><span>&laquo; قبل</span></li>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<li class="page-item"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">&raquo; بعد</a></li>
{% else %}
<li class="disabled"><span>&raquo; بعد</span></li>
{% endif %}
</ul>
{% endif %}
</div>
</div>
</div>
......