Add Interface + Patient add

parent 64d185e4
......@@ -14,3 +14,9 @@ class DoctorForm(forms.ModelForm):
class Meta:
model = Doctor
fields = ('first_name', 'last_name','email','address')
class RaspiForm(forms.ModelForm):
class Meta:
model = Raspi
fields = ('ip','status',)
# Generated by Django 2.1.2 on 2018-10-26 19:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0002_auto_20181025_0913'),
]
operations = [
migrations.CreateModel(
name='Raspi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ip', models.CharField(max_length=50)),
],
),
]
# Generated by Django 2.1.2 on 2018-10-26 19:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0003_raspi'),
]
operations = [
migrations.AddField(
model_name='raspi',
name='status',
field=models.CharField(default='UP', max_length=5),
preserve_default=False,
),
]
......@@ -15,3 +15,7 @@ class Patient(models.Model):
def __str__(self):
return self.last_name + self.first_name
class Raspi(models.Model):
ip = models.CharField(max_length=50)
status = models.CharField(max_length=5)
......@@ -36,9 +36,9 @@
<div class="col-sm-4">
<a href="{% url 'dashboard' %}">
<div class="card mx-auto">
<img class="card-img-top" src="{% static "dashboard.png" %}" alt="dashboard">
<img class="card-img-top" src="{% static "computer.png" %}" alt="interface">
<div class="card-body mx-auto">
<a href="{% url 'dashboard' %}" class="btn btn-success">My Dashboard</a>
<a href="{% url 'interface' %}" class="btn btn-success">My Interface</a>
</div>
</div>
</a>
......
{% extends 'base.html' %}
{% block content %}
<div class="container">
<div class="jumbotron mt-5">
<h1>My Interface</h1>
</div>
{% load static %}
<div class="row mt-5">
{% for pi in raspis %}
<div class="col">
<div class="card" style="width: 10rem;">
<img class="card-img-top" src="{% static "pi.png" %}" alt="raspi">
<div class="card-body ">
<center>
<h5 class="card-title">{{pi.ip}}</h5>
{% if pi.status == "UP" %}
<a href="#" class="btn btn-success">UP</a>
{% else %}
<a href="#" class="btn btn-danger ">DOWN</a>
{% endif %}
</center>
</div>
</div>
</div>
{% if forloop.counter|divisibleby:"6" or forloop.last %}
</div> <!--end row-->
{% endif %}
{% endfor %}
</div>
{% endblock %}
......@@ -7,12 +7,14 @@
{% for patient in patients %}
<div class="col">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{% static "patient.jpg" %}" alt="patient">
<img class="card-img-top" src="{% static "patient.png" %}" alt="patient">
<div class="card-body mx-auto">
<center>
<h5 class="card-title">{{patient.first_name}} {{patient.last_name}}</h5>
<p class="card-text">date_of_birth : {{patient.date_of_birth}}</p>
<p class="card-text">Doctor : {{patient.doctor}}</p>
<a href="#" class="btn btn-primary">fdp</a>
<a href="#" class="btn btn-primary">Details</a>
</center>
</div>
</div>
</div>
......
{% extends 'base.html' %}
{% block content %}
<div class="container">
<div class="jumbotron mt-5">
<div class="container">
<h1 class="display-4">New Raspberry Pi</h1>
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-success">Save</button>
</form>
</div>
</div>
{% endblock %}
......@@ -12,10 +12,10 @@ urlpatterns = [
url(r'^home/$', views.home, name='home'),
path('patient/new', views.patient_new, name='patient_new'),
path('doctor/new', views.doctor_new, name='doctor_new'),
path('raspi/new', views.raspi_new, name='raspi_new'),
path('doctors', views.doctors, name='doctors'),
path('patients', views.patients, name='patients'),
path('interface', views.interface, name='interface'),
path('dashboard', views.dashboard, name='dashboard'),
url('login', views.login, name='login'),
]
......@@ -7,7 +7,18 @@ from .models import *
import random
def patient_new(request):
form = PatientForm()
if request.method == "POST":
form = PatientForm(request.POST)
if form.is_valid():
patient = Patient()
patient.first_name = form.cleaned_data['first_name']
patient.last_name = form.cleaned_data['last_name']
patient.date_of_birth = form.cleaned_data['date_of_birth']
patient.doctor = form.cleaned_data['doctor']
patient.save()
return redirect('patients')
else:
form = PatientForm()
return render(request, 'patient_add.html', {'form': form})
@login_required
......@@ -38,6 +49,18 @@ def doctor_new(request):
form = DoctorForm()
return render(request, 'doctor_add.html', {'form': form})
def raspi_new(request):
if request.method == "POST":
form = RaspiForm(request.POST)
if form.is_valid():
pi = Raspi()
pi.ip = form.cleaned_data['ip']
pi.save()
return redirect('interface')
else:
form = RaspiForm()
return render(request, 'raspi_add.html', {'form': form})
@login_required
def api(request):
return HttpResponse("API")
......@@ -45,6 +68,9 @@ def api(request):
def login(request):
return redirect('/admin/login')
def interface(request):
raspis = Raspi.objects.all()
return render(request, 'interface.html', {'raspis': raspis})
def home(request):
return render(request, 'home.html')
......
No preview for this file type
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