...
 
Commits (2)
......@@ -12,6 +12,7 @@ from django.template.loader import render_to_string
from users.models import User
from jdatetime import date
from django.utils.decorators import method_decorator
from users.decorators import patient_required, patient_required
from django.core.urlresolvers import reverse_lazy
from django.contrib.admin.views.decorators import staff_member_required
from pinax.messages.models import Thread
......@@ -99,7 +100,8 @@ class RxView(TemplateView):
return context
@method_decorator(login_required, name='dispatch')
@method_decorator([login_required, patient_required], name='dispatch')
class GoalView(TemplateView):
template_name = 'sites/goal.html'
def get_context_data(self, **kwargs):
......@@ -129,7 +131,7 @@ class DrugView(TemplateView):
@method_decorator(login_required, name='dispatch')
class WeightCreate(CreateView):
model = Weight
form_class = WeightCreateForm
......
<script src="https://code.highcharts.com/highcharts.src.js"></script>
<div id="container" style="height: 400px">
<script>
var categories = [
{% for entry in dataset %}'{{ entry.date_created|date:'Y-m-d' }}'{% if not forloop.last %}, {% endif %}{% endfor %}
]
Highcharts.chart('container', {
chart: {
type: 'line'
},
dateRangeGrouping: true,
title: {
text: 'آخرین تغییرات وزن شما'
},
xAxis: {
categories: [
{% for entry in dataset %}'{{ entry.date_created|date:'Y-m-d' }}'{% if not forloop.last %}, {% endif %}{% endfor %}
]
categories: categories
},
yAxis: {
title: {
text: 'کیلوگرم (kg)'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
// enableMouseTracking: false
}
},
series: [{
name: 'وزن',
data: [
......
......@@ -4,7 +4,8 @@
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
<link rel="stylesheet" type="text/css" href="https://rawgit.com/notryanb/highcharts_date_range_grouping/config-date-formats/dist/highcharts_date_range_grouping.css">
{% endblock stylesheets %}
{% block location %}
......@@ -18,7 +19,7 @@
<div class="col-sm-6 col-lg-6 offset-sm-3">
<div class="animated fadeIn">
{% if not request.user.is_staff %}
{% if request.user.is_patient %}
<div class="card">
<div class="card-header">
تغییرات وزن
......@@ -38,4 +39,4 @@
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
\ No newline at end of file
{% endblock javascripts %}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<li class="nav-item">
<a class="nav-link" href="/home/"><i class="icon-speedometer"></i> داشبورد </a>
</li>
{% if request.user.is_staff %}
{% if request.user.is_doctor %}
<li class="nav-title">
بیماران
......@@ -17,7 +17,7 @@
نسخه ها
</li>
<li class="nav-item">
<a class="nav-link" href="/rxs/list"><i class="fas fa-utensils"></i> لیست نسخه ها</a>
<a class="nav-link" href="/rx/"><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">
......@@ -35,7 +35,7 @@
<a class="nav-link" href="/program/create"><i class="fas fa-plus"></i> افزودن برنامه </a>
</li>
{% else %}
{% elif request.user.is_patient %}
<li class="nav-title">
تناسب اندام
......@@ -43,14 +43,14 @@
<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>
<a class="nav-link" href="/goal/"><i class="fas fa-plus"></i> هدف <span class="tag tag-info">بزودی</span></a>
</li>
<li class="nav-title">
تغذیه
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="icon-docs"></i> برنامه غذایی من</a>
<a class="nav-link" href="#"><i class="icon-docs"></i> برنامه غذایی من <span class="tag tag-info">بزودی</span></a>
</li>
<li class="nav-title">
......@@ -58,8 +58,7 @@
</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>
<a class="nav-link" href="#"><i class="fas fa-dumbbell"></i> برنامه ورزشی<span class="tag tag-info">بزودی</span> </a>
</li>
<li class="nav-title">
......@@ -70,7 +69,7 @@
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fas fa-clock"></i> یاداورها</a>
<a class="nav-link" href="#"><i class="fas fa-clock"></i> یاداورها <span class="tag tag-info">بزودی</span></a>
</li>
......
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test
def patient_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url='login'):
'''
Decorator for views that checks that the logged in user is a patient,
redirects to the log-in page if necessary.
'''
actual_decorator = user_passes_test(
lambda u: u.is_active and u.is_patient,
login_url=login_url,
redirect_field_name=redirect_field_name
)
if function:
return actual_decorator(function)
return actual_decorator
def doctor_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url='login'):
'''
Decorator for views that checks that the logged in user is a doctor,
redirects to the log-in page if necessary.
'''
actual_decorator = user_passes_test(
lambda u: u.is_active and u.is_doctor,
login_url=login_url,
redirect_field_name=redirect_field_name
)
if function:
return actual_decorator(function)
return actual_decorator
\ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-05 22:10
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Doctor',
fields=[
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='DoctorSpeciality',
fields=[
('specialty', models.CharField(max_length=30, primary_key=True, serialize=False)),
],
options={
'verbose_name_plural': 'Doctors specialties',
},
),
migrations.CreateModel(
name='Patient',
fields=[
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
('ssn', models.CharField(max_length=9, unique=True)),
('street', models.CharField(max_length=50)),
('city', models.CharField(max_length=20)),
('state', models.CharField(max_length=20)),
('zip_code', models.CharField(max_length=5)),
],
),
migrations.AddField(
model_name='user',
name='is_docktor',
field=models.BooleanField(default=False, verbose_name='docktor status'),
),
migrations.AddField(
model_name='user',
name='is_patient',
field=models.BooleanField(default=True, verbose_name='patient status'),
),
migrations.AddField(
model_name='doctor',
name='specialty',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.DoctorSpeciality'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-06 10:56
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0002_auto_20180606_0240'),
]
operations = [
migrations.RenameField(
model_name='user',
old_name='is_docktor',
new_name='is_doctor',
),
]
......@@ -74,6 +74,38 @@ class User(AbstractUser):
Concrete class of AbstractUser.
Use this if you don't need to extend User.
"""
is_doctor = models.BooleanField('docktor status', default=False)
is_patient = models.BooleanField('patient status', default=True)
class Meta(AbstractUser.Meta):
swappable = 'AUTH_USER_MODEL'
class Patient(models.Model):
user = models.OneToOneField(User, primary_key=True)
ssn = models.CharField(max_length=9, unique=True)
street = models.CharField(max_length=50)
city = models.CharField(max_length=20)
state = models.CharField(max_length=20)
zip_code = models.CharField(max_length=5)
def __unicode__(self):
return self.user.first_name + ' ' + self.user.last_name
class DoctorSpeciality(models.Model):
specialty = models.CharField(max_length=30, primary_key=True)
def __unicode__(self):
return self.specialty
class Meta:
verbose_name_plural = 'Doctors specialties'
class Doctor(models.Model):
user = models.OneToOneField(User, primary_key=True)
specialty = models.ForeignKey(DoctorSpeciality)
def __unicode__(self):
return self.user.first_name + ' ' + self.user.last_name
\ No newline at end of file