diff --git a/hc/accounts/views.py b/hc/accounts/views.py index f0f2f122..6b5fb849 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -5,6 +5,7 @@ from django.contrib.auth import authenticate, login as auth_login from django.contrib.auth.models import User from django.core.mail import send_mail from django.core.urlresolvers import reverse +from django.http import HttpResponseBadRequest from django.shortcuts import redirect, render from hc.accounts.forms import EmailForm @@ -19,6 +20,11 @@ def login(request): if form.is_valid(): email = form.cleaned_data["email"] user = User.objects.get(email=email) + + # We don't want to reset passwords of staff users :-) + if user.is_staff: + return HttpResponseBadRequest() + token = str(uuid.uuid4()) user.set_password(token) user.save() diff --git a/hc/checks/__init__.py b/hc/api/__init__.py similarity index 100% rename from hc/checks/__init__.py rename to hc/api/__init__.py diff --git a/hc/api/admin.py b/hc/api/admin.py new file mode 100644 index 00000000..8a60577b --- /dev/null +++ b/hc/api/admin.py @@ -0,0 +1,7 @@ +from django.contrib import admin + +from hc.api.models import Check + +@admin.register(Check) +class ChecksAdmin(admin.ModelAdmin): + list_display = ("id", "code", "user", "last_ping") diff --git a/hc/checks/migrations/0001_initial.py b/hc/api/migrations/0001_initial.py similarity index 71% rename from hc/checks/migrations/0001_initial.py rename to hc/api/migrations/0001_initial.py index e3b7086d..77cd5512 100644 --- a/hc/checks/migrations/0001_initial.py +++ b/hc/api/migrations/0001_initial.py @@ -14,10 +14,11 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Canary', + name='Check', fields=[ - ('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')), + ('id', models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)), ('code', models.UUIDField(default=uuid.uuid4, editable=False)), + ('last_ping', models.DateTimeField(null=True, blank=True)), ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), ], ), diff --git a/hc/checks/migrations/__init__.py b/hc/api/migrations/__init__.py similarity index 100% rename from hc/checks/migrations/__init__.py rename to hc/api/migrations/__init__.py diff --git a/hc/checks/models.py b/hc/api/models.py similarity index 74% rename from hc/checks/models.py rename to hc/api/models.py index bc0f3483..43e43474 100644 --- a/hc/checks/models.py +++ b/hc/api/models.py @@ -4,10 +4,7 @@ from django.contrib.auth.models import User from django.db import models -class Canary(models.Model): - class Meta: - verbose_name_plural = "canaries" - +class Check(models.Model): code = models.UUIDField(default=uuid.uuid4, editable=False) user = models.ForeignKey(User) last_ping = models.DateTimeField(null=True, blank=True) diff --git a/hc/checks/tests.py b/hc/api/tests.py similarity index 100% rename from hc/checks/tests.py rename to hc/api/tests.py diff --git a/hc/checks/urls.py b/hc/api/urls.py similarity index 79% rename from hc/checks/urls.py rename to hc/api/urls.py index fd9d5260..35f2b894 100644 --- a/hc/checks/urls.py +++ b/hc/api/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import url -from hc.checks import views +from hc.api import views urlpatterns = [ url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping"), diff --git a/hc/checks/views.py b/hc/api/views.py similarity index 53% rename from hc/checks/views.py rename to hc/api/views.py index 04cbf639..ee527ada 100644 --- a/hc/checks/views.py +++ b/hc/api/views.py @@ -1,16 +1,16 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.utils import timezone -from hc.checks.models import Canary +from hc.api.models import Check def ping(request, code): try: - canary = Canary.objects.get(code=code) - except Canary.DoesNotExist: + check = Check.objects.get(code=code) + except Check.DoesNotExist: return HttpResponseBadRequest() - canary.last_ping = timezone.now() - canary.save() + check.last_ping = timezone.now() + check.save() return HttpResponse() diff --git a/hc/checks/admin.py b/hc/checks/admin.py deleted file mode 100644 index b19bd425..00000000 --- a/hc/checks/admin.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.contrib import admin - -from hc.checks.models import Canary - - -@admin.register(Canary) -class CanaryAdmin(admin.ModelAdmin): - list_display = ("id", "code", "user", "last_ping") diff --git a/hc/checks/migrations/0002_auto_20150610_1852.py b/hc/checks/migrations/0002_auto_20150610_1852.py deleted file mode 100644 index 13bb055b..00000000 --- a/hc/checks/migrations/0002_auto_20150610_1852.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('checks', '0001_initial'), - ] - - operations = [ - migrations.AlterModelOptions( - name='canary', - options={'verbose_name_plural': 'canaries'}, - ), - migrations.AddField( - model_name='canary', - name='last_ping', - field=models.DateTimeField(null=True, blank=True), - ), - ] diff --git a/hc/front/views.py b/hc/front/views.py index 13d8a014..6be2b4f2 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1,15 +1,15 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import render -from hc.checks.models import Canary +from hc.api.models import Check @login_required def checks(request): - canaries = Canary.objects.filter(user=request.user) + checks = Check.objects.filter(user=request.user) ctx = { - "canaries": canaries + "checks": checks } return render(request, "checks/index.html", ctx) diff --git a/hc/settings.py b/hc/settings.py index ee432dd7..0b0a451c 100644 --- a/hc/settings.py +++ b/hc/settings.py @@ -40,7 +40,7 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'hc.accounts', - 'hc.checks', + 'hc.api', 'hc.front' ) diff --git a/hc/urls.py b/hc/urls.py index 2b9afb16..5351cbea 100644 --- a/hc/urls.py +++ b/hc/urls.py @@ -4,6 +4,6 @@ from django.contrib import admin urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^accounts/', include('hc.accounts.urls')), - url(r'^', include('hc.checks.urls')), + url(r'^', include('hc.api.urls')), url(r'^', include('hc.front.urls')), ] diff --git a/templates/checks/index.html b/templates/checks/index.html index a43f63ae..3b4bd775 100644 --- a/templates/checks/index.html +++ b/templates/checks/index.html @@ -9,10 +9,10 @@ Code Last Ping - {% for canary in canaries %} + {% for check in checks %} - {{ canary.code }} - {{ canary.last_ping }} + {{ check.code }} + {{ check.last_ping }} {% endfor %}