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

Commit

Permalink
pep8 + fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Demah committed May 29, 2015
1 parent 46572d1 commit 7574ff0
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 137 deletions.
1 change: 1 addition & 0 deletions django_th/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.apps import AppConfig


class DjangoThConfig(AppConfig):
name = 'django_th'
verbose_name = "Trigger Happy"
12 changes: 6 additions & 6 deletions django_th/forms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class UserServiceForm(forms.ModelForm):
"""
Form to deal with my own activated service
"""
def save(self, user=None):
self.myobject = super(UserServiceForm, self).save(commit=False)
self.myobject.user = user
self.myobject.save()

def activated_services(self, user):
"""
get the activated services added from the administrator
Expand All @@ -43,8 +38,8 @@ def activated_services(self, user):
if UserService.objects.filter(name__exact=class_name.name,
user__exact=user):
continue
else:
# 2nd array position contains the name of the service
else:
data = (class_name.name, class_name.name.rsplit('Service', 1)[1])
all_datas = (data,) + all_datas
return all_datas
Expand All @@ -56,6 +51,11 @@ def __init__(self, *args, **kwargs):
self.initial['user'])
self.fields['name'].widget.attrs['class'] = 'form-control'

def save(self, user=None):
self.myobject = super(UserServiceForm, self).save(commit=False)
self.myobject.user = user
self.myobject.save()

class Meta:
"""
meta to add/override anything we need
Expand Down
4 changes: 2 additions & 2 deletions django_th/local_settings_sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sample for dev purpose
# to be used by the command :
# python manage.py --settings=my_app.local_settings
# to be used by the command :
# python manage.py --settings=my_app.local_settings
from .settings import *

DEBUG = True
Expand Down
27 changes: 13 additions & 14 deletions django_th/management/commands/fire_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class Command(BaseCommand):

help = 'Trigger all the services'

def update_trigger(self, service):
Expand Down Expand Up @@ -69,7 +68,7 @@ def handle(self, *args, **options):
service_consumer = default_provider.get_service(service_name)

# check if the service has already been triggered
# if date_triggered is None, then it's the first run
# if date_triggered is None, then it's the first run
if service.date_triggered is None:
logger.debug("first run for %s => %s " % (str(
service.provider.name),
Expand All @@ -90,9 +89,9 @@ def handle(self, *args, **options):

# 2) for each one
for data in datas:
# if in a pool of data once of them does not have
# a date, will take the previous date for this one
# if it's the first one, set it to 00:00:00
#  if in a pool of data once of them does not have
#  a date, will take the previous date for this one
#  if it's the first one, set it to 00:00:00

# let's try to determine the date contained in
# the data...
Expand All @@ -102,31 +101,31 @@ def handle(self, *args, **options):
# get the published date of the provider
published = arrow.get(str(published), 'YYYY-MM-DD HH:mm:ss').to(settings.TIME_ZONE)
# store the date for the next loop
# if published became 'None'
#  if published became 'None'
which_date = published
#... otherwise set it to 00:00:00 of the current date
# ... otherwise set it to 00:00:00 of the current date
if which_date == '':
# current date
which_date = arrow.utcnow().replace(hour=0, minute=0, second=0).to(settings.TIME_ZONE)
published = which_date
if published is None and which_date != '':
published = which_date
# 3) check if the previous trigger is older than the
# date of the data we retrieved
# if yes , process the consumer
#  date of the data we retrieved
#  if yes , process the consumer

# add the TIME_ZONE settings
# to localize the current date
date_triggered = arrow.get(str(service.date_triggered), 'YYYY-MM-DD HH:mm:ss').to(settings.TIME_ZONE)
date_triggered = arrow.get(str(service.date_triggered), 'YYYY-MM-DD HH:mm:ss').to(
settings.TIME_ZONE)

# if the published date if greater or equal to the last
# triggered event ... :
if date_triggered is not None and \
published is not None and \
published >= date_triggered:
if date_triggered is not None and published is not None and published >= date_triggered:

if 'title' in data:
logger.info("date {} >= date triggered {} title {}".format(published, date_triggered, data['title']))
logger.info("date {} >= date triggered {} title {}".format(published, date_triggered,
data['title']))
else:
logger.info("date {} >= date triggered {} ".format(published, date_triggered))

Expand Down
19 changes: 8 additions & 11 deletions django_th/management/commands/fire_th_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def to_datetime(data):


class Command(BaseCommand):

@asyncio.coroutine
def update_trigger(self, service):
"""
Expand Down Expand Up @@ -99,18 +98,18 @@ def my_consumer(self, service_consumer, token, service_id, date_triggered):
# flag to know if we can push data to the consumer

# 2) for each one
# if in a pool of data once of them does not have
# a date, will take the previous date for this one
# if it's the first one, set it to 00:00:00
#  if in a pool of data once of them does not have
#  a date, will take the previous date for this one
#  if it's the first one, set it to 00:00:00
# let's try to determine the date contained in the data...
published = to_datetime(data)
if published is not None:
# get the published date of the provider
published = arrow.get(str(published), 'YYYY-MM-DD HH:mm:ss').to(settings.TIME_ZONE)
# store the date for the next loop
# if published became 'None'
#  if published became 'None'
which_date = published
#... otherwise set it to 00:00:00 of the current date
# ... otherwise set it to 00:00:00 of the current date
if which_date == '':
# current date
which_date = arrow.utcnow().replace(
Expand All @@ -119,18 +118,16 @@ def my_consumer(self, service_consumer, token, service_id, date_triggered):
if published is None and which_date != '':
published = which_date
# 3) check if the previous trigger is older than the
# date of the data we retreived
# if yes , process the consumer
#  date of the data we retreived
#  if yes , process the consumer

# add the TIME_ZONE settings
my_date_triggered = arrow.get(
str(date_triggered), 'YYYY-MM-DD HH:mm:ss').to(settings.TIME_ZONE)

# if the published date if greater or equal to the last
# triggered event ... :
if date_triggered is not None and \
published is not None and \
published >= date_triggered:
if date_triggered is not None and published is not None and published >= date_triggered:

if 'title' in data:
logger.info("date {} >= date triggered {} title {}".format(
Expand Down
8 changes: 4 additions & 4 deletions django_th/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def show(self):
self.auth_required, self.description)

def __str__(self):
return "%s" % (self.name)
return "%s" % self.name


@python_2_unicode_compatible
Expand All @@ -35,10 +35,10 @@ class UserProfile(models.Model):
user = models.OneToOneField(User)

def show(self):
return "User profile %s" % (self.user_id)
return "User profile %s" % self.user_id

def __str__(self):
return "%s" % (self.user)
return "%s" % self.user


@python_2_unicode_compatible
Expand All @@ -55,7 +55,7 @@ def show(self):
return "User Service %s %s %s" % (self.user, self.token, self.name)

def __str__(self):
return "%s" % (self.name)
return "%s" % self.name


@python_2_unicode_compatible
Expand Down
2 changes: 1 addition & 1 deletion django_th/models/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Services(models.Model):
description = models.CharField(max_length=255)

def __unicode__(self):
return "%s" % (self.name)
return "%s" % self.name

def show(self):
return "Services Model %s %s %s " % (self.name, self.status, self.description)
Expand Down
2 changes: 1 addition & 1 deletion django_th/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ServicesMgr(object):
data = {}

def __unicode__(self):
return "%s" % (self.name)
return "%s" % self.name

def set_title(self, string):
self.title = string
Expand Down
21 changes: 10 additions & 11 deletions django_th/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!--link rel="stylesheet" href="{% static "bootstrap/css/bootstrap.min.css" %}" type="text/css" media="screen" /-->
<link rel="stylesheet" href="{% static "css/th.css" %}" type="text/css" media="screen" />
<link rel="stylesheet" href="{% static 'css/th.css' %}" type="text/css" media="screen" />
<!--link rel="stylesheet" href="{% static "bootstrap/css/bootstrap-responsive.min.css" %}" type="text/css" media="screen" /-->
<meta name="author" content="FoxMaSk">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
Expand All @@ -36,40 +36,39 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'base' %}" title="{% trans "Home" %}">Trigger Happy</a>
<a class="navbar-brand" href="{% url 'base' %}" title="{% trans 'Home' %}">Trigger Happy</a>
</div>
<div class="navbar-collapse collapse">
{% if user.is_authenticated %}
<ul class="nav navbar-nav">
<li>
<a href="{% url 'base' %}" title="{% trans "Home" %}"><span class="glyphicon glyphicon-home"></span>&nbsp;&nbsp;Home</a>
<a href="{% url 'base' %}" title="{% trans 'Home' %}"><span class="glyphicon glyphicon-home"></span>&nbsp;&nbsp;Home</a>
</li>
<li>
{% if nb_services > 1 %}
<a href="{% url 'create_service' %}" title="{% trans "Create a new trigger" %}">
<a href="{% url 'create_service' %}" title="{% trans 'Create a new trigger' %}"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Add trigger</a>
{% else %}
<a href="#" title="You can't create a new trigger until 2 services are activated">
<a href="#" title="{% trans 'You can not create a new trigger until 2 services are activated' %}"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Add trigger</a>
{% endif %}
<span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Add trigger</a>
</li>
<li>
<a href="{% url 'user_services' %}" title="{% trans "List of your own activated services" %}"><span class="glyphicon glyphicon-tasks"></span>&nbsp;&nbsp;Activated services</a>
<a href="{% url 'user_services' %}" title="{% trans 'List of your own activated services' %}"><span class="glyphicon glyphicon-tasks"></span>&nbsp;&nbsp;Activated services</a>
</li>
{% block filter_trigger %}
{% include "filter.html" with trigger_filter_by=trigger_filter_by %}
{% endblock %}
<li class="dropdown">
<a class="dropdown-toggle" title="{% trans "Order by..." %}" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-sort-by-attributes"></span> <b class="caret"></b></a>
<a class="dropdown-toggle" title="{% trans 'Order by...' %}" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-sort-by-attributes"></span> <b class="caret"></b></a>
<ul class="dropdown dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" title="{% trans "Sort by " %}" href="{% url 'trigger_order_by' 'provider' %}">{% trans "Service Provider" %}</a></li>
<li role="presentation"><a role="menuitem" title="{% trans "Sort by " %}" href="{% url 'trigger_order_by' 'consumer' %}">{% trans "Service Consumer" %}</a></li>
<li role="presentation"><a role="menuitem" title="{% trans 'Sort by ' %}" href="{% url 'trigger_order_by' 'provider' %}">{% trans "Service Provider" %}</a></li>
<li role="presentation"><a role="menuitem" title="{% trans 'Sort by ' %}" href="{% url 'trigger_order_by' 'consumer' %}">{% trans "Service Consumer" %}</a></li>
</ul>
</li>
{% url 'profiles_profile_detail' request.user.username as profiles_profile_detail %}
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="{% url 'logout' %}" title="{% trans "log out" %}"><span class="glyphicon glyphicon-off"></span></a>
<a href="{% url 'logout' %}" title="{% trans 'log out' %}"><span class="glyphicon glyphicon-off"></span></a>
</li>
</ul>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions django_th/templates/filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{% load django_th_extras %}

<li class="dropdown">
<a class="dropdown-toggle" title="{% trans "Filter by one of the service you have activated" %}" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-filter"></span> <b class="caret"></b></a>
<a class="dropdown-toggle" title="{% trans 'Filter by one of the service you have activated' %}" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-filter"></span> <b class="caret"></b></a>
<ul class="dropdown dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
{% for trigger_filter in trigger_filter_by %}
<li role="presentation"><a role="menuitem" title="{% trans "Filter by " %}" href="{% url 'trigger_filter_by' trigger_filter.name.name %}">{{ trigger_filter.name|service_readable }}</a></li>
<li role="presentation"><a role="menuitem" title="{% trans 'Filter by ' %}" href="{% url 'trigger_filter_by' trigger_filter.name.name %}">{{ trigger_filter.name|service_readable }}</a></li>
{% endfor %}
</ul>
</li>
4 changes: 2 additions & 2 deletions django_th/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h2><span class="glyphicon glyphicon-flash"></span>{% trans "My Triggers" %}</h2
<span class="label label-info">{{ nb_triggers.enabled }}</span> {% trans "enabled" %} <span class="label label-default">{% trans "triggers" %}</span>
<span class="label label-warning">{{ nb_triggers.disabled }}</span> {% trans "disabled" %} <span class="label label-default">{% trans "triggers" %}</span>
<hr/>
{% trans "Actions" %} : <a href="{% url 'trigger_switch_all_to' 'off' %}" title="{% trans "this action will set all the triggers off"%}">{% trans "Mark all Off" %}</a> - <a href="{% url 'trigger_switch_all_to' 'on' %}" title="{% trans "this action will set all the triggers on"%}">{% trans "Mark all On" %}</a>
{% trans "Actions" %} : <a href="{% url 'trigger_switch_all_to' 'off' %}" title="{% trans 'this action will set all the triggers off' %}">{% trans "Mark all Off" %}</a> - <a href="{% url 'trigger_switch_all_to' 'on' %}" title="{% trans 'this action will set all the triggers on' %}">{% trans 'Mark all On' %}</a>
</div>
</div>
{% if triggers_list %}
Expand Down Expand Up @@ -57,7 +57,7 @@ <h3><a href="{% url 'edit_trigger' trigger.id %}" title="{% trans 'Edit the desc
<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/>
<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>
Expand Down
2 changes: 1 addition & 1 deletion django_th/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="page-header">{% trans "Log in" %}</h1>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" value="{% trans "Log in" %}" />
<input type="submit" class="btn btn-primary" value="{% trans 'Log in' %}" />
<input type="hidden" name="next" value="{{ next }}" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion django_th/templates/services/delete_service.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3>{% trans 'Deletion of your service' %}</h3>
<form method="post" role="form" class="form-horizontal" action="">
{% csrf_token %}
<div class="form-actions">
<input class="btn btn-danger" name="ok" type="submit" value="{% trans "Yes" %}" />
<input class="btn btn-danger" name="ok" type="submit" value="{% trans 'Yes' %}" />
<a href="{% url 'user_services' %}" class="btn btn-primary">{% trans "No" %}</a>
</div>
</form>
Expand Down

0 comments on commit 7574ff0

Please sign in to comment.