Commit 41c5d5e8 authored by freetux's avatar freetux

some fixes in template

parent ed0bdc1d
from django import forms
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from users.models import User
from body.models import Weight
class UserCreationForm(forms.ModelForm):
email = forms.EmailField(label='ایمیل', max_length=255)
password1 = forms.CharField(label='گذرواژه', widget=forms.PasswordInput)
......@@ -68,4 +68,5 @@ class UserAdminChangeForm(forms.ModelForm):
# Regardless of what the user provides, return the initial value.
# This is done here, rather than on the field, because the
# field does not have access to the initial value
return self.initial["password"]
\ No newline at end of file
return self.initial["password"]
......@@ -11,4 +11,8 @@ urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^home/$', views.home, name='dashboard'),
url(r'^weight/$', views.weight, name='weight'),
url(r'^weight/create$', views.weight_create, name='weight_create'),
# url(r'^weight/edit/(?P<id>\d+)$', views.weight_edit, name='weight_edit'),
# url(r'^weight/edit/update/(?P<id>\d+)$', views.weight_update, name='weight_update'),
# url(r'^weight/delete/(?P<id>\d+)$', views.weight_delete, name='weight_delete'),
]
\ No newline at end of file
......@@ -6,9 +6,11 @@ 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
from django.http import JsonResponse
from django.template.loader import render_to_string
from .forms import WeightForm
from users.models import User
from django.shortcuts import render, redirect
def index(request):
if request.user.is_authenticated():
......@@ -42,3 +44,42 @@ def weight(request):
template = loader.get_template('sites/weight.html')
return HttpResponse(template.render(weights, request))
# TODO: create crud for weight model
@login_required
def weight_create(request):
user_id = request.user.id
user = User.objects.get(id=user_id)
weights = Weight(user=None, weight=request.POST['weight'], height=request.POST['height'],text=request.POST['text'])
weights.user = user
weights.save()
return redirect('/weight/')
# @login_required
# def weight_edit(request, id):
# weights = Weight.objects.get(id=id)
# context = {'weights': weights}
# return render(request, 'sites/edit.html', context)
# @login_required
# def weight_update(request, id):
# user_id = request.user.id
# user = User.objects.get(id=user_id)
# weights = Weight.objects.get(id=id)
# weights.weight = request.POST['weight']
# weights.height = request.POST['height']
# weights.text = request.POST['text']
# weights.user = user
# weights.save()
# return redirect('/weight/')
# @login_required
# def weight_delete(request, id):
# weights = Weight.objects.get(id=id)
# weights.delete()
# return redirect('/weight/')
\ No newline at end of file
......@@ -44,6 +44,7 @@ INSTALLED_APPS = [
'rest_framework',
'rest_framework.authtoken',
'corsheaders',
'widget_tweaks',
'user',
'users',
'body',
......
......@@ -70,13 +70,7 @@
<ul class="nav navbar-nav pull-left hidden-md-down">
<li class="nav-item">
<a class="nav-link aside-toggle" href="#"><i class="icon-bell"></i><span class="tag tag-pill tag-danger">5</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="icon-list"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="icon-location-pin"></i></a>
</li>
</li>S
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle nav-link" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
<img src="{{user.avatar.url}}" class="img-avatar" alt="{{user.email}}">
......@@ -623,7 +617,7 @@
<script src="{% static "js/views/main.js" %}" ></script>
<!-- Grunt watch plugin -->
<script src="//localhost:8009/livereload.js" %}" ></script>
<script src="//localhost:8009/livereload.js" ></script>
{% endblock javascripts %}
{% endblock body %}
......
{% load static %}
<!--
* CoreUI - Open Source Bootstrap Admin Template
* @version v1.0.0-alpha.2
......
{% extends "sites/base_site.html" %}
{% load static %}
{% block title %} dash {% endblock title %}
{% block stylesheets %}
......@@ -20,6 +20,12 @@
<i class="fa fa-align-justify"></i> قد و وزن
</div>
<div class="card-block">
<p>
<button type="button" class="btn btn-primary js-create-book" data-url="{% url 'weight_create' %}">
<span class="glyphicon glyphicon-plus"></span>
وزن جدید
</button>
</p>
<table class="table">
<thead>
<tr>
......@@ -143,11 +149,17 @@
<!--/col-->
</div>
<!--/row-->
<!-- THE MODAL WE WILL BE USING -->
<div class="modal fade" id="modal-book">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
<!-- /.conainer-fluid -->
{% endblock content %}
{% block javascripts %}
<script src="{% static 'js/weight.js' %}"></script>
{{ 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