Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cambios Windmy #7

Open
wants to merge 2 commits into
base: Circuit-Breaker
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions alarms/logic/logic_alarm.py

This file was deleted.

24 changes: 0 additions & 24 deletions alarms/models.py

This file was deleted.

25 changes: 0 additions & 25 deletions alarms/views.py

This file was deleted.

File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions alarms/apps.py → citas/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class AlarmsConfig(AppConfig):
class CitasConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'alarms'
name = 'citas'
17 changes: 17 additions & 0 deletions citas/logic/logic_cita.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from plantillas.models import Plantilla
from ..models import Cita

def get_citas():
queryset = Cita.objects.all().order_by('-dateTime')
return (queryset)

def get_plantillas_by_historia(historia):
queryset = Plantilla.objects.filter(historia=historia).order_by('-dateTime')[:10]
return (queryset)

def create_cita( historia, plantilla):
cita = Cita()
cita.historia = historia
cita.plantilla = plantilla
cita.save()
return cita
File renamed without changes.
19 changes: 19 additions & 0 deletions citas/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.db import models
from historias.models import Historia
from plantillas.models import Plantilla

class Cita(models.Model):
historia = models.ForeignKey(Historia, on_delete=models.CASCADE, default=None)
plantilla = models.ForeignKey(Plantilla, on_delete=models.CASCADE, default=None)
dateTime = models.DateTimeField(auto_now_add=True)

def __str__(self):
return '{"historia": %s}' % (self.historia.name)

def toJson(self):
cita = {
'historia': self.historia.name,
'historia': self.plantilla.nombre,
'dateTime': self.dateTime,
}
return cita
File renamed without changes.
4 changes: 2 additions & 2 deletions alarms/urls.py → citas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from . import views

urlpatterns = [
path('alarms/', views.alarm_list),
path('alarmsValidate/<int:variable_id>', views.generate_alarm),
path('citas/', views.cita_list),
path('citasValidate/<int:variable_id>', views.generate_cita),
]
25 changes: 25 additions & 0 deletions citas/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.http import JsonResponse
from django.shortcuts import render
from historias.logic.historia_logic import get_historia_by_name
from .logic.logic_cita import get_citas, get_plantillas_by_historia, create_cita


def cita_list(request):
citas = get_citas()
context = list(citas.values())
return JsonResponse(context, safe=False)

def generate_cita(request, historia_name):
historia = get_historia_by_name(historia_name)
plantillas = get_plantillas_by_historia(historia_name)
createcita = False
upperPlantilla = None
for plantilla in plantillas:
if plantilla.especificacion == 'Emergencia':
createCita = True
upperPlantilla = plantilla
if createcita:
cita = create_cita(historia, plantilla)
return JsonResponse(cita.toJson(), safe=False)
else:
return JsonResponse({'message': 'No cita created'}, status=200)
File renamed without changes.
4 changes: 4 additions & 0 deletions historias/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from . models import Historia

admin.site.register(Historia)
5 changes: 5 additions & 0 deletions historias/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class HistoriasConfig(AppConfig):
name = 'historias'
8 changes: 4 additions & 4 deletions variables/forms.py → historias/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django import forms
from .models import Variable
from .models import Historia

class VariableForm(forms.ModelForm):
class HistoriaForm(forms.ModelForm):
class Meta:
model = Variable
model = Historia
fields = [
'name',
]
labels = {
'name': 'Name',
}
}
16 changes: 16 additions & 0 deletions historias/logic/historia_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


from ..models import Historia

def get_historia_by_name(name):
queryset = Historia.objects.get(name=name)
return (queryset)

def get_historias():
queryset = Historia.objects.all()
return (queryset)

def create_historia(form):
plantilla = form.save()
plantilla.save()
return ()
File renamed without changes.
3 changes: 2 additions & 1 deletion variables/models.py → historias/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models

class Variable(models.Model):
class Historia(models.Model):
name = models.CharField(max_length=50)

def __str__(self):
return '{}'.format(self.name)


Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% extends 'base.html' %}
{% block content %}
<form method="POST">
{% extends 'base.html' %}
{% block content %}
<form method="POST">
{% csrf_token %}
<br>
{{ form.as_p }}
{{ form.as_p }}
<button type="submit" class="btn btn-success waves-effect waves-light">Create</button>
<button type="button" class="btn btn-primary waves-effect waves-light"
onClick=" window.location.href='/variables' ">Back
onClick=" window.location.href='/historias' ">Back
</button>
</form>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<div class="content">
<div class="">
<div class="page-header-title">
<h4 class="page-title">Variables</h4>
<h4 class="page-title">Historias</h4>
<div style="text-align:right;">
<button type="button" class="btn btn-success waves-effect waves-light"
onClick=" window.location.href='/variablecreate' " style="text-align:center;">+
onClick=" window.location.href='/historiacreate' " style="text-align:center;">+
</button>
</div>
</div>
Expand All @@ -25,14 +25,14 @@ <h4 class="page-title">Variables</h4>
<table class="table table-hover">
<thead>
<tr style="color:#0E2EB0">
<th>Variable</th>
<th>Historia</th>
</tr>
</thead>
<tbody>

{% for variable in variable_list %}
{% for historia in historia_list %}
<tr>
<td>{{ variable.name }}</td>
<td>{{ historia.name }}</td>
</tr>
{% endfor %}

Expand All @@ -51,4 +51,4 @@ <h4 class="page-title">Variables</h4>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
File renamed without changes.
9 changes: 9 additions & 0 deletions historias/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from django.views.decorators.csrf import csrf_exempt

from . import views

urlpatterns = [
path('historias/', views.historia_list, name='historiaList'),
path('historiacreate/', csrf_exempt(views.historia_create), name='historiaCreate'),
]
30 changes: 30 additions & 0 deletions historias/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.shortcuts import render
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.urls import reverse
from .forms import HistoriaForm
from .logic.historia_logic import get_historias, create_historia

def historia_list(request):
historias = get_historias()
context = {
'historia_list': historias
}
return render(request, 'Historia/historias.html', context)

def historia_create(request):
if request.method == 'POST':
form = HistoriaForm(request.POST)
if form.is_valid():
create_historia(form)
messages.add_message(request, messages.SUCCESS, 'Successfully created historia')
return HttpResponseRedirect(reverse('historiaCreate'))
else:
print(form.errors)
else:
form = HistoriaForm()

context = {
'form': form,
}
return render(request, 'Historia/historiaCreate.html', context)
28 changes: 14 additions & 14 deletions kong.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
_format_version: "2.1"

services:
- host: monitoring_upstream
name: monitoring_service
- host: windmy_upstream
name: windmy_service
protocol: http
routes:

- name: monitoring
- name: windmy
paths:
- /
strip_path: false

- host: alarms_upstream
name: alarms_service
- host: citas_upstream
name: citas_service
protocol: http
routes:

- name: alarms
- name: citas
paths:
- /alarms
- /alarmsValidate/
- /citas
- /citasValidate/
strip_path: false

upstreams:
- name: alarms_upstream
- name: citas_upstream
targets:
- target: <ip-privada-alarms-app-a>:8080
- target: <ip-privada-citas-app-a>:8080
weight: 100
- target: <ip-privada-alarms-app-b>:8080
- target: <ip-privada-citas-app-b>:8080
weight: 100
- target: <ip-privada-alarms-app-c>:8080
- target: <ip-privada-citas-app-c>:8080
weight: 100
#healthchecks:
# threshold: 0
Expand All @@ -43,9 +43,9 @@ upstreams:
# tcp_failures: 0
# interval: 0

- name: monitoring_upstream
- name: windmy_upstream
targets:
- target: <ip-privada-monitoring-app>:8080
- target: <ip-privada-windmy-app>:8080
weight: 100


2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "monitoring.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "windmy.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
Binary file removed measurements/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/admin.cpython-34.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/models.cpython-34.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/serializers.cpython-34.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/serializers.cpython-37.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/urls.cpython-34.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/views.cpython-34.pyc
Binary file not shown.
Binary file removed measurements/__pycache__/views.cpython-37.pyc
Binary file not shown.
5 changes: 0 additions & 5 deletions measurements/admin.py

This file was deleted.

5 changes: 0 additions & 5 deletions measurements/apps.py

This file was deleted.

Loading