Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Mark all Off : set date triggered to today #90 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Demah committed Jun 14, 2015
1 parent de6478d commit 1db7432
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
6 changes: 2 additions & 4 deletions django_th/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ <h2><span class="glyphicon glyphicon-flash"></span>{% trans "My Triggers" %}</h2
</div>
{% endif %}
{% for trigger in triggers_list %}
<div class="trigger-record col-md-12">
<div id="trigger-record-{{ trigger.id }}"class="trigger-record col-md-12">
<div class="col-md-8 col-sm-6 trigger-text">
<h3><a href="{% url 'edit_trigger' trigger.id %}" title="{% trans 'Edit the description' %} ">{{ trigger.description|safe|escape }}</a></h3>
</div>
<div class="col-md-4 col-sm-6 trigger-button">
<div id="all-actions{{ trigger.id }}">

<a class="btn btn-sm btn-info" role="button" href="{% url 'edit_provider' trigger.id %}" title="{% trans 'Edit your service' %} {{ trigger.provider.name|service_readable|lower }}" ><span class="glyphicon glyphicon-pencil icon-white"></span> {{ trigger.provider.name|service_readable|lower }}</a>

Expand All @@ -59,7 +58,6 @@ <h3><a href="{% url 'edit_trigger' trigger.id %}" title="{% trans 'Edit the desc
{% endif %}
<a class="btn btn-sm btn-danger" role="button" href="{% url 'delete_trigger' trigger.id %}" title="{% trans 'Delete this trigger ?' %}"><span class="glyphicon glyphicon-trash icon-white"></span></a><br/>

</div>
</div>
<footer>
<div class="col-md-12">
Expand Down Expand Up @@ -127,7 +125,7 @@ <h3><a href="{% url 'edit_trigger' trigger.id %}" title="{% trans 'Edit the desc
success: showResponse,
});
function showResponse(response) {
$('#all-actions'+triggerId).html(response);
$('#trigger-record-'+triggerId).html(response);
}
});
//]]>
Expand Down
32 changes: 31 additions & 1 deletion django_th/templates/triggers/trigger_line.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
{% load i18n %}
{% load django_th_extras %}
<a class="btn btn-sm btn-info" role="button" href="{% url 'edit_provider' trigger.id %}" title="{{ title }} {{ trigger.provider.name|service_readable|lower }}" ><span class="glyphicon glyphicon-pencil icon-white"></span> {{ trigger.provider.name|service_readable|lower }}</a>
<!--a class="btn btn-sm btn-info" role="button" href="{% url 'edit_provider' trigger.id %}" title="{{ title }} {{ trigger.provider.name|service_readable|lower }}" ><span class="glyphicon glyphicon-pencil icon-white"></span> {{ trigger.provider.name|service_readable|lower }}</a>
<a class="btn btn-sm btn-info" role="button" href="{% url 'edit_consumer' trigger.id %}" title="{{ title }} {{ trigger.consumer.name|service_readable|lower }}" ><span class="glyphicon glyphicon-pencil icon-white"></span> {{ trigger.consumer.name|service_readable|lower }}</a>
<a class="btn btn-sm btn-{{ btn }}" data="{{ trigger.id }}" role="button" href="#" title="{{ title_trigger }}"><span class="glyphicon glyphicon-off icon-white"></span></a>
<a class="btn btn-sm btn-danger" role="button" href="{% url 'delete_trigger' trigger.id %}" title="{% trans 'Delete this trigger ?' %}"><span class="glyphicon glyphicon-trash icon-white"></span></a><br/-->


<div class="col-md-8 col-sm-6 trigger-text">
<h3><a href="{% url 'edit_trigger' trigger.id %}" title="{% trans 'Edit the description' %} ">{{ trigger.description|safe|escape }}</a></h3>
</div>
<div class="col-md-4 col-sm-6 trigger-button">

<a class="btn btn-sm btn-info" role="button" href="{% url 'edit_provider' trigger.id %}" title="{% trans 'Edit your service' %} {{ trigger.provider.name|service_readable|lower }}" ><span class="glyphicon glyphicon-pencil icon-white"></span> {{ trigger.provider.name|service_readable|lower }}</a>

<a class="btn btn-sm btn-info" role="button" href="{% url 'edit_consumer' trigger.id %}" title="{% trans 'Edit your service' %} {{ trigger.consumer.name|service_readable|lower }}" ><span class="glyphicon glyphicon-pencil icon-white"></span> {{ trigger.consumer.name|service_readable|lower }}</a>

{% if trigger.status %}
<a class="btn btn-sm btn-primary" data="{{ trigger.id }}" role="button" href="#" title="{% trans 'Set this trigger off' %}"><span class="glyphicon glyphicon-off icon-white"></span></a>
{% else %}
<a class="btn btn-sm btn-success" data="{{ trigger.id }}" role="button" href="#" title="{% trans 'Set this trigger on' %}"><span class="glyphicon glyphicon-off icon-white"></span></a>

{% endif %}
<a class="btn btn-sm btn-danger" role="button" href="{% url 'delete_trigger' trigger.id %}" title="{% trans 'Delete this trigger ?' %}"><span class="glyphicon glyphicon-trash icon-white"></span></a><br/>

</div>
<footer>
<div class="col-md-12">
<p>
<span class="glyphicon glyphicon-calendar"></span>&nbsp;{% trans "Created" %}&nbsp;{{ trigger.date_created }}
&nbsp;-&nbsp;
<span class="glyphicon glyphicon-calendar"></span>&nbsp;{% trans "Triggered" %}&nbsp;{% if trigger.date_triggered %}{{ trigger.date_triggered }}{% else %}&nbsp;{% trans "Never triggered" %}{% endif %}
</p>
</div>
</footer>

12 changes: 12 additions & 0 deletions django_th/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# coding: utf-8
from __future__ import unicode_literals

import arrow
from django.conf import settings
from django.shortcuts import render, redirect
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required
Expand Down Expand Up @@ -48,6 +51,7 @@ def trigger_on_off(request, trigger_id):
:param trigger_id: the trigger ID to switch the status to True or False
:type trigger_id: int
"""
now = arrow.utcnow().to(settings.TIME_ZONE).format('YYYY-MM-DD HH:mm:ss')
trigger = get_object_or_404(TriggerService, pk=trigger_id)
if trigger.status:
title = 'disabled'
Expand All @@ -59,6 +63,9 @@ def trigger_on_off(request, trigger_id):
title_trigger = _('Set this trigger off')
btn = 'primary'
trigger.status = True
# set the trigger to the current date when the
# the trigger is back online
trigger.date_triggered = now
trigger.save()

return render(request, 'triggers/trigger_line.html',
Expand Down Expand Up @@ -96,12 +103,17 @@ def trigger_switch_all_to(request, switch):
:param switch: the switch value
:type switch: string off or on
"""
now = arrow.utcnow().to(settings.TIME_ZONE).format('YYYY-MM-DD HH:mm:ss')
status = True
if switch == 'off':
status = False
triggers = TriggerService.objects.all()
for trigger in triggers:
trigger.status = status
# set the trigger to the current date when the
# the trigger is back online
if status:
trigger.date_triggered = now
trigger.save()

return HttpResponseRedirect(reverse('base'))
Expand Down

0 comments on commit 1db7432

Please sign in to comment.