Commit a5f056fa authored by freetux's avatar freetux

go to first light version

parent 6d7bcc9c
......@@ -3,7 +3,7 @@ from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _
from users.models import User
from rest_framework import serializers
from body.models import Weight, Drug, Rx
from body.models import Weight
class UserLoginSerializer(serializers.Serializer):
......@@ -68,14 +68,3 @@ class WeightSerializer(serializers.ModelSerializer):
model = Weight
fields = ("id", "user", "text", "weight", "height", "date_created")
class DrugSerializer(serializers.ModelSerializer):
class Meta:
model = Drug
fields = ("id", "name", "description")
class RxSerializer(serializers.ModelSerializer):
user = WeightUserSerializer(read_only=True)
class Meta:
model = Rx
fields = ("id", "user", "drugs", "date_created")
\ No newline at end of file
from django.conf.urls import url, include
from .views import UserRegistrationAPIView, WeightListCreateAPIView, WeightDetailAPIView, DrugListCreateAPIView, RxListCreateAPIView, RxDetailAPIView, DrugDetailAPIView
from .views import UserRegistrationAPIView, WeightListCreateAPIView, WeightDetailAPIView
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
api_user = [
......@@ -12,11 +12,6 @@ api_user = [
api_body = [
url(r'^weight/$', WeightListCreateAPIView.as_view(), name="list"),
url(r'^weight/(?P<pk>[0-9]+)/$', WeightDetailAPIView.as_view(), name="detail"),
url(r'^drug/$', DrugListCreateAPIView.as_view(), name="list"),
url(r'^drug/(?P<pk>[0-9]+)/$', DrugDetailAPIView.as_view(), name="detail"),
url(r'^rx/$', RxListCreateAPIView.as_view(), name="list"),
url(r'^rx/(?P<pk>[0-9]+)/$', RxDetailAPIView.as_view(), name="detail"),
]
......
from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView, CreateAPIView, CreateAPIView, GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework import status, permissions
from body.models import Weight, Drug, Rx
from body.models import Weight
from .permissions import UserIsOwnerWeight, IsOwnerOrAdmin
from rest_framework.permissions import IsAdminUser
from .serializers import WeightSerializer, DrugSerializer, RxSerializer
from .serializers import WeightSerializer
from rest_framework.response import Response
from rest_framework.views import APIView
from .serializers import UserSerializer, UserLoginSerializer
......@@ -48,51 +48,3 @@ class WeightDetailAPIView(RetrieveUpdateDestroyAPIView):
queryset = Weight.objects.all()
permission_classes = (IsAuthenticated, UserIsOwnerWeight)
class DrugListCreateAPIView(ListCreateAPIView):
serializer_class = DrugSerializer
permission_classes = (IsAdminUser,)
def get_queryset(self):
return Drug.objects.all()
def perform_create(self, serializer):
serializer.save()
class DrugDetailAPIView(RetrieveUpdateDestroyAPIView):
serializer_class = DrugSerializer
queryset = Drug.objects.all()
permission_classes = (IsAdminUser)
class RxListCreateAPIView(ListCreateAPIView):
serializer_class = RxSerializer
permission_classes = (IsAdminUser,)
def get_queryset(self):
return Rx.objects.all()
def perform_create(self, serializer):
serializer.save()
class RxDetailAPIView(RetrieveUpdateDestroyAPIView):
serializer_class = RxSerializer
queryset = Rx.objects.all()
permission_classes = (IsOwnerOrAdmin)
class UserRxtDetailAPIView(RetrieveUpdateDestroyAPIView):
serializer_class = RxSerializer
queryset = Rx.objects.all()
permission_classes = (IsAuthenticated, UserIsOwnerWeight)
# def bmi(self, height, weight):
# data = Weight.objects.latest('date_added')
# weight = data.weight
# height = data.height/100
# return weight/height**2
......@@ -20,29 +20,6 @@ class Weight(models.Model):
def __unicode__(self):
return smart_unicode(self.text)
class Drug(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(_("نام دارو"), max_length=255)
salt = models.CharField(_("ملح"), max_length=255)
dosage_form = models.CharField(_("شکل دارویی"), max_length=255)
strengh = models.CharField(_("مقدار دارو"), max_length=255)
route_of_admin = models.CharField(_("راه مصرف"), max_length=255)
atcـcode = models.CharField(_("دسته دارو"), max_length=255)
ingredient = models.CharField(_("ترکیبات"), max_length=255)
remarks = models.CharField(_("توضیحات"), max_length=255)
date = jmodels.jDateTimeField(_("تاریخ ایجاد"), null=True)
# this is for food program
class FoodProgram(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
breakfest = models.CharField(_("صبحانه"), max_length=255)
bm = models.CharField(_("میان وعده صبحانه"), max_length=255)
lounch = models.CharField(_(" نهار"), max_length=255)
lm = models.CharField(_("میان وعده نهار"), max_length=255)
dinner = models.CharField(_(" شام"), max_length=255)
dm = models.CharField(_(" میان وعده شام"), max_length=255)
date = jmodels.jDateTimeField(_("تاریخ ایجاد"), null=True)
#goal body weight
......@@ -69,42 +46,3 @@ class UserActivity(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
activity = models.CharField(_('میزان فعالیت روزانه'), max_length=2, choices=ACTIVITY_CHOICES)
class Rx(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
drugs = models.ManyToManyField(Drug, related_name="rxs")
date_created = jmodels.jDateTimeField(_("Date Created"), auto_now_add=True)
class Meta:
verbose_name = _("Rx")
verbose_name_plural = _("Rxs")
def __unicode__(self):
return "{}-{}-{}-{}".format(self.id, self.user, self.date_created, self.drugs)
class Food(models.Model):
UNIT_CHOICES = (
('GR', 'گرم'),
('LT', 'لیتر'),
('NM', ' عدد')
)
id = models.AutoField(primary_key=True)
name = models.CharField(_('نام'), max_length=255, null=True)
amount = models.FloatField(_('مقدار'))
unit = models.CharField(_('واحد اندازه گیری'), max_length=2, choices=UNIT_CHOICES)
calories = models.FloatField(_('کالری'))
details = models.CharField(_('توضیح'), max_length=255, null=True)
# def bmi(self):
# return self.weight / (self.height/100) ** 2
#TODO:add BMI calculator
#TODO:add BMR calculator
#TODO:add BodyFat calculator
#TODO:add WHR calculator
#TODO:add IBW calculator
#TODO:add HRtR calculator
\ No newline at end of file
......@@ -3,7 +3,7 @@ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from users.models import User
from django.conf import settings
from body.models import Weight, Gbw, Drug, Food, FoodProgram
from body.models import Weight, Gbw
from django_select2.forms import Select2MultipleWidget
class UserCreationForm(forms.ModelForm):
......@@ -40,20 +40,6 @@ class WeightCreateForm(forms.ModelForm):
# user will be set in views.ResumeNew
# other fields will be set as model default
class DrugCreateForm(forms.ModelForm):
"""
Use to create Weight
"""
salt = forms.CharField(label="ملح" , max_length=255, required=False)
dosage_form = forms.CharField(label= "شکل دارویی", max_length=255, required=False)
strengh = forms.CharField(label="مقدار دارو", max_length=255, required=False)
route_of_admin = forms.CharField(label="راه مصرف", max_length=255, required=False)
atcـcode = forms.CharField(label="دسته دارو", max_length=255, required=False)
ingredient = forms.CharField(label="ترکیبات", max_length=255, required=False)
remarks = forms.CharField(label="توضیحات", max_length=255, required=False)
class Meta(object):
model = Drug
fields = ('name', 'salt', 'dosage_form', 'strengh', 'route_of_admin', 'atcـcode', 'ingredient', 'remarks')
class GbwCreateForm(forms.ModelForm):
......@@ -64,29 +50,6 @@ class GbwCreateForm(forms.ModelForm):
model = Gbw
fields = ('gbw',)
class FoodCreateForm(forms.ModelForm):
"""
Use to create Food
"""
class Meta(object):
model = Food
fields = ('name','amount', 'unit', 'calories', 'details')
class FoodProgramForm(forms.ModelForm):
"""
this is for food program
"""
breakfest = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
bm = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
lounch = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
lm = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
dinner = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
dm = forms.ModelMultipleChoiceField(queryset=Food.objects.values_list('name', flat=True).all(), widget=Select2MultipleWidget)
class Meta(object):
model = FoodProgram
fields = ('breakfest','bm', 'lounch', 'lm', 'dinner','dm')
class UserAdminCreationForm(forms.ModelForm):
"""A form for creating new users. Includes all the required
......
from django.conf.urls import url
from sites import views
from body.models import Weight, Drug, Food
from body.models import Weight
......@@ -14,26 +14,12 @@ urlpatterns = [
# The home page
url(r'^$', views.index, name='index'),
url(r'^weight/list$', views.WeightList.as_view(), name='weights_list'),
# url(r'^food/list$', views.FoodList.as_view(), name='food_list'),
url(r'^users/list$', views.UserList.as_view(), name='users_list'),
url(r'^home/$', views.HomeView.as_view(), name='dashboard'),
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'),
url(r'^goal/create$', views.GoalCreate.as_view(), name='gbw_create'),
url(r'^program/create$', views.FoodProgramCreate.as_view(), name='program_create'),
url(r'^food/$', views.FoodList.as_view(), name='food_list'),
url(r'^food/create$', views.FoodCreate.as_view(), name='food_create'),
url(r'^food/(?P<pk>[\w]+)/$', views.FoodShow.as_view(), name='food_show'),
url(r'^food/update/(?P<pk>[\w]+)/$', views.FoodUpdate.as_view(
model=Food,
), name='food_update'),
url(r'^food/delete/(?P<pk>[\w]+)/$', views.FoodDelete.as_view(
model=Food,
), name='food_delete'),
url(r'^drug/$', views.DrugList.as_view(), name='drug'),
url(r'^drug/create$', views.CreateDrug.as_view(), name='drug_create'),
url(r'^weight/create$', views.WeightCreate.as_view(), name='weight_create'),
url(r'^weight/(?P<pk>[\w]+)/$', views.WeightShow.as_view(), name='weight_show'),
url(r'^weight/update/(?P<pk>[\w]+)/$', views.WeightUpdate.as_view(
......
......@@ -2,11 +2,11 @@ from django.shortcuts import render, redirect
from django.template import loader
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic import TemplateView, CreateView, DetailView, UpdateView, DeleteView, ListView
from .forms import UserCreationForm, WeightCreateForm, ProfileUpdateForm, GbwCreateForm, DrugCreateForm, FoodCreateForm, FoodProgramForm
from .forms import UserCreationForm, WeightCreateForm, ProfileUpdateForm, GbwCreateForm
from django.contrib.auth import login
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from body.models import Weight, Rx, Drug, Gbw, Food, FoodProgram
from body.models import Weight, Gbw
from django.http import JsonResponse
from django.template.loader import render_to_string
from users.models import User
......@@ -91,15 +91,7 @@ class ProfileView(DetailView):
@method_decorator(login_required, name='dispatch')
class RxView(TemplateView):
template_name = 'sites/rxs.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.filter(user = self.request.user)
context['rxs'] = rxs
return context
......@@ -168,88 +160,10 @@ class GoalCreate(CreateView):
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
context = super().get_context_data(**kwargs)
rxs = Rx.objects.filter(user = self.request.user)
if rxs:
drug = rxs.drugs
else:
drug = 'none'
context['drug'] = drug
return context
@method_decorator(login_required, name='dispatch')
class FoodProgramCreate(CreateView):
model = FoodProgram
form_class = FoodProgramForm
success_url = reverse_lazy('food_list')
@method_decorator(login_required, name='dispatch')
class FoodCreate(CreateView):
model = Food
form_class = FoodCreateForm
success_url = reverse_lazy('food_list')
@method_decorator(login_required, name='dispatch')
class FoodList(ListView):
model = Food
context_object_name = 'foods'
paginate_by = 10
@method_decorator(login_required, name='dispatch')
class FoodShow(DetailView):
model = Food
def get_queryset(self):
return self.model.objects
@method_decorator(login_required, name='dispatch')
class FoodUpdate(UpdateView):
model = Food
success_url = reverse_lazy('food_list')
form_class = FoodCreateForm
def get_queryset(self):
return self.model.objects
def get_initial(self):
initial = super(FoodUpdate, self).get_initial()
initial.update()
return initial
def form_valid(self, form):
"""Force the user to request.user"""
self.object = form.save(commit=False)
self.object.save()
return super(FoodUpdate, self).form_valid(form)
@method_decorator(login_required, name='dispatch')
class FoodDelete(DeleteView):
success_url = reverse_lazy('food_list')
def get_object(self, queryset=None):
""" Hook to ensure object is owned by request.user. """
obj = super(FoodDelete, self).get_object()
return obj
......@@ -364,23 +278,6 @@ class WeightList(ListView):
@method_decorator(login_required, name='dispatch')
class CreateDrug(CreateView):
model = Drug
form_class = DrugCreateForm
success_url = reverse_lazy('Drug_create')
def form_valid(self, form):
"""Force the user to request.user"""
self.object = form.save(commit=False)
self.object.save()
return super(CreateDrug, self).form_valid(form)
@method_decorator(login_required, name='dispatch')
class WeightShow(DetailView):
......
{% extends "sites/base_site.html" %}
{% block title %}
{% if object_list %}
ویرایش دارو
{% else %}
افزودن دارو
{% endif %}
{% endblock title %}
{% block stylesheets %}
{{ block.super }}
{% endblock stylesheets %}
{% if object_list %}
{% block location %}
{% if object_list %}
ویرایش دارو
{% else %}
افزودن دارو
{% endif %}
{% endblock location %}
{% endif %}
{% block content %}
<div class="row">
<div class="col-md-4 offset-sm-4">
<div class="card">
<div class="card-header">
{% if object_list %}
ویرایش <strong> دارو </strong>
{% else %}
افزودن <strong> دارو </strong>
{% endif %}
</div>
<div class="card-block">
<form action="" method="post" enctype="multipart/form-data" class="form-horizontal ">{% csrf_token %}
{% if form.errors %}
{% include "users/partials/errors.html" %}
{% endif %}
{% csrf_token %}
{% for field in form %}
<div class="input-group m-b-1">
{% include "users/partials/field.html" %}
</div>
{% endfor %}
<div class="card-footer">
<button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i>
{% if object_list %}
ویرایش
{% else %}
افزودن
{% endif %}
</button>
<button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> بازنشانی</button>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
\ 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 %}
<!-- Calculates user weight status according to bmi and show allerts -->
<!--/.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="{% url 'drug_create' %}" role="button">
<span class="fas fa-plus"></span>
دارو جدید
</a>
</p>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>نام</th>
<th>ملح</th>
<th>شکل دارویی</th>
<th>مقدار دارو</th>
<th>راه مصرف</th>
</tr>
</thead>
<tbody>
{% for drug in drugs %}
<tr>
<td>{{ drug.id }}</td>
<td>{{ drug.name }}</td>
<td>{{ drug.salt }}</td>
<td>{{ drug.dosage_form }}</td>
<td>{{ drug.strengh }}</td>
<td>{{ drug.route_of_admin }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if is_paginated %}
<ul class="pagination">
{% 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>
{% 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>
<!--/col-->
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
{% 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 %}
<div class="container-fluid">
<div class="row">
<div class="col-md-4 center-block">
<div class="card-block mx-auto">
<form action="" method="post">{% csrf_token %}
<div class="alert alert-danger alert-dismissible fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>هشدار!</strong>
</br>
از حذف "{{ object }}" مطمئنید؟
</div>
<button type="submit" class="btn btn-danger ">تایید</button>
</form>
</div>
</div>
</div>
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
{{ block.super }}
{% endblock javascripts %}
{% 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 %}
<div class="container-fluid">
<div class="col-sm-6 col-md-4 offset-sm-4">
<div class="card">
<div class="card-header">