Commit 1ff01d32 authored by freetux's avatar freetux

admin dashboard and user list for admin and some permissions fix for profile

parent 6431b0f9
......@@ -15,8 +15,9 @@ urlpatterns = [
# The home page
url(r'^$', views.index, name='index'),
url(r'^weight/list$', views.WeightList.as_view(), name='weights_list'),
url(r'^users/list$', views.UserList.as_view(), name='users_list'),
url(r'^home/$', views.HomeView.as_view(), name='dashboard'),
url(r'^profile/$', views.ProfileView.as_view(), name='profile'),
url(r'^profile/(?P<pk>[\w]+)/$', views.ProfileView.as_view(), name='profile'),
url(r'^profile/edit/(?P<pk>[\w]+)/$', views.ProfileUpdate.as_view(), name='profile_edit'),
url(r'^rx/$', views.RxView.as_view(), name='rx'),
url(r'^goal/$', views.GoalView.as_view(), name='goal'),
......
......@@ -13,7 +13,7 @@ from users.models import User
from jdatetime import date
from django.utils.decorators import method_decorator
from django.core.urlresolvers import reverse_lazy
from django.contrib.admin.views.decorators import staff_member_required
......@@ -52,7 +52,8 @@ class HomeView(TemplateView):
return context
@method_decorator(login_required, name='dispatch')
class ProfileView(TemplateView):
class ProfileView(DetailView):
model = User
template_name = 'sites/profile.html'
......@@ -83,15 +84,16 @@ class GoalView(TemplateView):
@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
context = super().get_context_data(**kwargs)
rxs = Rx.objects.all()
rxs = Rx.objects.filter(user = self.request.user)
if rxs:
lastrx = rxs.reverse()[0]
drug = rxs.drugs
else:
lastrx = 'none'
context['lastrx'] = lastrx
drug = 'none'
context['drug'] = drug
return context
......@@ -268,3 +270,12 @@ class ProfileUpdate(UpdateView):
self.object.save()
return super(ProfileUpdate, self).form_valid(form)
@method_decorator(staff_member_required, name='dispatch')
class UserList(ListView):
model = User
\ No newline at end of file
This diff is collapsed.
<div class="sidebar">
<nav class="sidebar-nav">
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="/home/"><i class="icon-speedometer"></i> داشبورد <span class="tag tag-info">جدید</span></a>
</li>
{% if request.user.is_staff %}
<li class="nav-title">
بیماران
</li>
<li class="nav-item">
<a class="nav-link" href="/users/list"><i class="fas fa-user"></i> لیست بیماران</a>
<a class="nav-link" href="/users/create"><i class="fas fa-plus"></i> افزودن بیمار</a>
</li>
<li class="nav-title">
نسخه ها
</li>
<li class="nav-item">
<a class="nav-link" href="/rxs/list"><i class="fas fa-utensils"></i> لیست نسخه ها</a>
<a class="nav-link" href="/rxs/create"><i class="fas fa-plus"></i> افزودن نسخه </a>
</li>
<li class="nav-title">
دارو ها
</li>
<li class="nav-item">
<a class="nav-link" href="/drug/list"><i class="fas fa-pills"></i> لیست دارو ها</a>
<a class="nav-link" href="/drug/create"><i class="fas fa-plus"></i> افزودن دارو </a>
</li>
<li class="nav-title">
برنامه غذایی
</li>
<li class="nav-item">
<a class="nav-link" href="/program/list"><i class="icon-docs"></i> لیست برنامه ها</a>
<a class="nav-link" href="/program/create"><i class="fas fa-plus"></i> افزودن برنامه </a>
</li>
{% else %}
<li class="nav-title">
تناسب اندام
</li>
<li class="nav-item">
<a class="nav-link" href="/weight/list"><i class="fas fa-weight"></i> آنالیز وزن</a>
<a class="nav-link" href="/weight/create"><i class="fas fa-plus"></i> افزودن قد و وزن</a>
<a class="nav-link" href="/goal/"><i class="fas fa-plus"></i> هدف</a>
</li>
<li class="nav-title">
تناسب اندام
</li>
<li class="nav-item">
<a class="nav-link" href="/weight/list"><i class="fas fa-weight"></i> آنالیز وزن</a>
<a class="nav-link" href="/weight/create"><i class="fas fa-plus"></i> افزودن قد و وزن</a>
<a class="nav-link" href="/goal/"><i class="fas fa-plus"></i> هدف</a>
</li>
<li class="nav-title">
تغذیه
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="icon-docs"></i> برنامه غذایی من</a>
</li>
<li class="nav-title">
مراقبت پزشکی
</li>
<li class="nav-item">
<a class="nav-link" href="/rx/"><i class="fas fa-utensils"></i> نسخه های من</a>
<a class="nav-link" href="/drug/"><i class="fas fa-pills"></i> داروهای من</a>
<a class="nav-link" href="#"><i class="fas fa-dumbbell"></i></i> برنامه ورزشی</a>
</li>
<li class="nav-title">
یادآورها
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-clock"></i> یاداورها</a>
</li>
<!--<li class="nav-item nav-dropdown">
<a class="nav-link nav-dropdown-toggle" href="#"><i class="icon-puzzle"></i> ثبت کاربر جدید</a>
<ul class="nav-dropdown-items">
<li class="nav-item">
<a class="nav-link" href="components-buttons.html"><i class="icon-puzzle"></i> لیست کاربران</a>
</li>
<li class="nav-item">
<a class="nav-link" href="components-social-buttons.html"><i class="icon-puzzle"></i> Social Buttons</a>
</li>
<li class="nav-item">
<a class="nav-link" href="components-cards.html"><i class="icon-puzzle"></i> Cards</a>
</li>
<li class="nav-item">
<a class="nav-link" href="components-forms.html"><i class="icon-puzzle"></i> Forms</a>
</li>
<li class="nav-item">
<a class="nav-link" href="components-switches.html"><i class="icon-puzzle"></i> Switches</a>
</li>
<li class="nav-item">
<a class="nav-link" href="components-tables.html"><i class="icon-puzzle"></i> Tables</a>
</li>
</ul>
</li>-->
<!--<li class="nav-item nav-dropdown">
<a class="nav-link nav-dropdown-toggle" href="#"><i class="icon-star"></i> Icons</a>
<ul class="nav-dropdown-items">
<li class="nav-item">
<a class="nav-link" href="icons-font-awesome.html"><i class="icon-star"></i> Font Awesome</a>
</li>
<li class="nav-item">
<a class="nav-link" href="icons-simple-line-icons.html"><i class="icon-star"></i> Simple Line Icons</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="widgets.html"><i class="icon-calculator"></i> Widgets <span class="tag tag-info">NEW</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="charts.html"><i class="icon-pie-chart"></i> Charts</a>
</li>-->
<!--<li class="divider"></li>
<li class="nav-title">
Extras
</li>
<li class="nav-item nav-dropdown">
<a class="nav-link nav-dropdown-toggle" href="#"><i class="icon-star"></i> Pages</a>
<ul class="nav-dropdown-items">
<li class="nav-item">
<a class="nav-link" href="pages-login.html" target="_top"><i class="icon-star"></i> Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages-register.html" target="_top"><i class="icon-star"></i> Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages-404.html" target="_top"><i class="icon-star"></i> Error 404</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages-500.html" target="_top"><i class="icon-star"></i> Error 500</a>
</li>
</ul>
</li>-->
</ul>
</nav>
</div>
{% endif %}
\ No newline at end of file
{% extends "sites/base_site.html" %}
{% load static %}
{% load jformat %}
{% block title %} لیست کاربران {% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% block location %}
لیست کاربران
{% endblock location %}
{% block content %}
<!--/.container-fluid-->
<div class="container-fluid">
<div class="animated fadeIn">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<i class="fa fa-align-justify"></i> لیست کاربران
</div>
<div class="card-block">
<p>
<a class="btn btn-outline-primary" href="#" role="button">
<span class="fas fa-plus"></span>
کاربر جدید
</a>
</p>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>نام و نام خانوادگی</th>
<th>جنسیت</th>
<th>تاریخ پیوستن</th>
</tr>
</thead>
<tbody>
{% for user in object_list %}
<tr>
<td>{{ user.id }}</td>
<td><a href="/profile/{{user.id}}/">{{ user.get_full_name }}</td>
<td>{{ user.get_gender_display }}</td>
<td>{{ user.date_joined|jformat:"%A %d %B %Y %H:%M" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<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>
</ul>
</div>
</div>
</div>
<!--/col-->
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment