0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-03 04:15:29 +00:00
This commit is contained in:
Pēteris Caune 2015-06-12 19:33:15 +03:00
parent a965f4c605
commit c8b24495b9
15 changed files with 31 additions and 51 deletions

View file

@ -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()

7
hc/api/admin.py Normal file
View file

@ -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")

View file

@ -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)),
],
),

View file

@ -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)

View file

@ -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"),

View file

@ -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()

View file

@ -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")

View file

@ -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),
),
]

View file

@ -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)

View file

@ -40,7 +40,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'hc.accounts',
'hc.checks',
'hc.api',
'hc.front'
)

View file

@ -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')),
]

View file

@ -9,10 +9,10 @@
<th>Code</th>
<th>Last Ping</th>
</tr>
{% for canary in canaries %}
{% for check in checks %}
<tr>
<td>{{ canary.code }}</td>
<td>{{ canary.last_ping }}</td>
<td>{{ check.code }}</td>
<td>{{ check.last_ping }}</td>
</tr>
{% endfor %}