-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New machines widget, fix some timezone errors
- Loading branch information
1 parent
788ec3a
commit 43341bc
Showing
8 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from yapsy.IPlugin import IPlugin | ||
from yapsy.PluginManager import PluginManager | ||
from django.template import loader, Context | ||
from django.db.models import Count | ||
from server.models import * | ||
from django.shortcuts import get_object_or_404 | ||
import server.utils as utils | ||
from datetime import datetime, timedelta, date | ||
import django.utils.timezone | ||
|
||
now = django.utils.timezone.now() | ||
this_day = now - timedelta(hours=24) | ||
week_ago = this_day - timedelta(days=7) | ||
month_ago = this_day - timedelta(days=30) | ||
|
||
class NewMachines(IPlugin): | ||
def plugin_type(self): | ||
return 'builtin' | ||
|
||
def show_widget(self, page, machines=None, theid=None): | ||
# The data is data is pulled from the database and passed to a template. | ||
|
||
# There are three possible views we're going to be rendering to - front, bu_dashbaord and group_dashboard. If page is set to bu_dashboard, or group_dashboard, you will be passed a business_unit or machine_group id to use (mainly for linking to the right search). | ||
if page == 'front': | ||
t = loader.get_template('newmachines/templates/front.html') | ||
|
||
if page == 'bu_dashboard': | ||
t = loader.get_template('newmachines/templates/id.html') | ||
|
||
if page == 'group_dashboard': | ||
t = loader.get_template('newmachines/templates/id.html') | ||
|
||
if machines: | ||
print this_day | ||
today = machines.filter(first_checkin__gte=this_day).count() | ||
this_week = machines.filter(first_checkin__gte=week_ago).count() | ||
this_month = machines.filter(first_checkin__gte=month_ago).count() | ||
else: | ||
today = 0 | ||
this_week = 0 | ||
this_month = 0 | ||
|
||
c = Context({ | ||
'title': 'New Machines', | ||
'today_label': 'Today', | ||
'today_count': today, | ||
'week_label': 'This Week', | ||
'week_count': this_week, | ||
'month_label': 'This Month', | ||
'month_count': this_month, | ||
'plugin': 'NewMachines', | ||
'theid': theid, | ||
'page': page | ||
}) | ||
return t.render(c), 4 | ||
|
||
def filter_machines(self, machines, data): | ||
if data == 'day': | ||
machines = machines.filter(first_checkin__gte=this_day) | ||
title = 'Machines first seen today' | ||
|
||
elif data == 'week': | ||
machines = machines.filter(first_checkin__gte=week_ago) | ||
title = 'Machines first seen this week' | ||
|
||
elif data == 'month': | ||
machines = machines.filter(first_checkin__gte=month_ago) | ||
title = 'Machines first seen this month' | ||
|
||
else: | ||
machines = None | ||
|
||
return machines, title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Core] | ||
Name = NewMachines | ||
Module = newmachines | ||
|
||
[Documentation] | ||
Author = Graham Gilbert | ||
Version = 0.1 | ||
Website = http://grahamgilbert.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="col-md-4"> | ||
<div class="panel panel-default panel-traffic-light"> | ||
<div class="panel-heading"> | ||
{{ title }} | ||
</div> | ||
<!-- /.panel-heading --> | ||
<div class="panel-body"> | ||
<a href="{% url 'machine_list_front' plugin 'day' %}" class="btn btn-info"> | ||
<span class="bigger"> {{ today_count }} </span><br /> | ||
{{ today_label }} | ||
</a> | ||
|
||
<a href="{% url 'machine_list_front' plugin 'week' %}" class="btn btn-info"> | ||
<span class="bigger"> {{ week_count }} </span><br /> | ||
{{ week_label }} | ||
</a> | ||
|
||
<a href="{% url 'machine_list_front' plugin 'month' %}" class="btn btn-info"> | ||
<span class="bigger"> {{ month_count }} </span><br /> | ||
{{ month_label }} | ||
</a> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="col-md-4"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
{{ title }} | ||
</div> | ||
<!-- /.panel-heading --> | ||
<div class="panel-body"> | ||
<a href="{% url 'machine_list_id' plugin 'day' page theid %}" class="btn btn-info"> | ||
<span class="bigger"> {{ today_count }} </span><br /> | ||
{{ today_label }} | ||
</a> | ||
|
||
<a href="{% url 'machine_list_id' plugin 'week' page theid %}" class="btn btn-info"> | ||
<span class="bigger"> {{ week_count }} </span><br /> | ||
{{ week_label }} | ||
</a> | ||
|
||
<a href="{% url 'machine_list_id' plugin 'month' page theid %}" class="btn btn-info"> | ||
<span class="bigger"> {{ month_count }} </span><br /> | ||
{{ month_label }} | ||
</a> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters