diff --git a/server/plugins/activity/activity.py b/server/plugins/activity/activity.py index 3a0aa472..1b81d7d6 100644 --- a/server/plugins/activity/activity.py +++ b/server/plugins/activity/activity.py @@ -6,10 +6,11 @@ from django.shortcuts import get_object_or_404 import server.utils as utils from datetime import datetime, timedelta, date +import django.utils.timezone -now = datetime.now() +now = django.utils.timezone.now() hour_ago = now - timedelta(hours=1) -today = date.today() +today = now - timedelta(hours=24) week_ago = today - timedelta(days=7) month_ago = today - timedelta(days=30) three_months_ago = today - timedelta(days=90) diff --git a/server/plugins/newmachines/newmachines.py b/server/plugins/newmachines/newmachines.py new file mode 100644 index 00000000..a41018ad --- /dev/null +++ b/server/plugins/newmachines/newmachines.py @@ -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 diff --git a/server/plugins/newmachines/newmachines.yapsy-plugin b/server/plugins/newmachines/newmachines.yapsy-plugin new file mode 100644 index 00000000..55f0ad7d --- /dev/null +++ b/server/plugins/newmachines/newmachines.yapsy-plugin @@ -0,0 +1,8 @@ +[Core] +Name = NewMachines +Module = newmachines + +[Documentation] +Author = Graham Gilbert +Version = 0.1 +Website = http://grahamgilbert.com \ No newline at end of file diff --git a/server/plugins/newmachines/templates/front.html b/server/plugins/newmachines/templates/front.html new file mode 100644 index 00000000..fe195642 --- /dev/null +++ b/server/plugins/newmachines/templates/front.html @@ -0,0 +1,24 @@ +
+
+
+ {{ title }} +
+ + +
+
\ No newline at end of file diff --git a/server/plugins/newmachines/templates/id.html b/server/plugins/newmachines/templates/id.html new file mode 100644 index 00000000..f993c6ef --- /dev/null +++ b/server/plugins/newmachines/templates/id.html @@ -0,0 +1,24 @@ +
+
+
+ {{ title }} +
+ + +
+
\ No newline at end of file diff --git a/server/plugins/puppetstatus/puppetstatus.py b/server/plugins/puppetstatus/puppetstatus.py index 5aa92d6b..adf2326c 100644 --- a/server/plugins/puppetstatus/puppetstatus.py +++ b/server/plugins/puppetstatus/puppetstatus.py @@ -7,10 +7,11 @@ import server.utils as utils from django.db.models import Q from datetime import datetime, timedelta, date +import django.utils.timezone -now = datetime.now() +now = django.utils.timezone.now() hour_ago = now - timedelta(hours=1) -today = date.today() +today = now - timedelta(hours=24) week_ago = today - timedelta(days=7) month_ago = today - timedelta(days=30) three_months_ago = today - timedelta(days=90) diff --git a/server/plugins/status/status.py b/server/plugins/status/status.py index 0edb9197..467093d7 100644 --- a/server/plugins/status/status.py +++ b/server/plugins/status/status.py @@ -6,8 +6,10 @@ from django.shortcuts import get_object_or_404 import server.utils as utils from datetime import datetime, timedelta, date +import django.utils.timezone -today = date.today() +now = django.utils.timezone.now() +today = now - timedelta(hours=24) week_ago = today - timedelta(days=7) month_ago = today - timedelta(days=30) three_months_ago = today - timedelta(days=90) diff --git a/server/views.py b/server/views.py index c964dda1..26c513ef 100644 --- a/server/views.py +++ b/server/views.py @@ -24,6 +24,7 @@ import pytz import watson import unicodecsv as csv +import django.utils.timezone # This will only work if BRUTE_PROTECT == True try: import axes.utils @@ -82,9 +83,9 @@ def index(request): profile.level = 'GA' profile.save() user_level = user.userprofile.level - now = datetime.now() + now = django.utils.timezone.now() hour_ago = now - timedelta(hours=1) - today = date.today() + today = now - timedelta(hours=24) week_ago = today - timedelta(days=7) month_ago = today - timedelta(days=30) three_months_ago = today - timedelta(days=90) @@ -500,9 +501,9 @@ def bu_dashboard(request, bu_id): else: is_editor = False machines = utils.getBUmachines(bu_id) - now = datetime.now() + now = django.utils.timezone.now() hour_ago = now - timedelta(hours=1) - today = date.today() + today = now - timedelta(hours=24) week_ago = today - timedelta(days=7) month_ago = today - timedelta(days=30) three_months_ago = today - timedelta(days=90) @@ -541,9 +542,9 @@ def overview_list_all(request, req_type, data, bu_id=None): activity = None inactivity = None disk_space = None - now = datetime.now() + now = django.utils.timezone.now() hour_ago = now - timedelta(hours=1) - today = date.today() + today = now - timedelta(hours=24) week_ago = today - timedelta(days=7) month_ago = today - timedelta(days=30) three_months_ago = today - timedelta(days=90)