mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-10 07:27:30 +00:00
Renames
This commit is contained in:
parent
a965f4c605
commit
c8b24495b9
15 changed files with 31 additions and 51 deletions
|
@ -5,6 +5,7 @@ from django.contrib.auth import authenticate, login as auth_login
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.http import HttpResponseBadRequest
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
|
|
||||||
from hc.accounts.forms import EmailForm
|
from hc.accounts.forms import EmailForm
|
||||||
|
@ -19,6 +20,11 @@ def login(request):
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
email = form.cleaned_data["email"]
|
email = form.cleaned_data["email"]
|
||||||
user = User.objects.get(email=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())
|
token = str(uuid.uuid4())
|
||||||
user.set_password(token)
|
user.set_password(token)
|
||||||
user.save()
|
user.save()
|
||||||
|
|
7
hc/api/admin.py
Normal file
7
hc/api/admin.py
Normal 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")
|
|
@ -14,10 +14,11 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Canary',
|
name='Check',
|
||||||
fields=[
|
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)),
|
('code', models.UUIDField(default=uuid.uuid4, editable=False)),
|
||||||
|
('last_ping', models.DateTimeField(null=True, blank=True)),
|
||||||
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
|
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
),
|
),
|
|
@ -4,10 +4,7 @@ from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class Canary(models.Model):
|
class Check(models.Model):
|
||||||
class Meta:
|
|
||||||
verbose_name_plural = "canaries"
|
|
||||||
|
|
||||||
code = models.UUIDField(default=uuid.uuid4, editable=False)
|
code = models.UUIDField(default=uuid.uuid4, editable=False)
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
last_ping = models.DateTimeField(null=True, blank=True)
|
last_ping = models.DateTimeField(null=True, blank=True)
|
|
@ -1,6 +1,6 @@
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from hc.checks import views
|
from hc.api import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping"),
|
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping"),
|
|
@ -1,16 +1,16 @@
|
||||||
from django.http import HttpResponse, HttpResponseBadRequest
|
from django.http import HttpResponse, HttpResponseBadRequest
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from hc.checks.models import Canary
|
from hc.api.models import Check
|
||||||
|
|
||||||
|
|
||||||
def ping(request, code):
|
def ping(request, code):
|
||||||
try:
|
try:
|
||||||
canary = Canary.objects.get(code=code)
|
check = Check.objects.get(code=code)
|
||||||
except Canary.DoesNotExist:
|
except Check.DoesNotExist:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
canary.last_ping = timezone.now()
|
check.last_ping = timezone.now()
|
||||||
canary.save()
|
check.save()
|
||||||
|
|
||||||
return HttpResponse()
|
return HttpResponse()
|
|
@ -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")
|
|
|
@ -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),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,15 +1,15 @@
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from hc.checks.models import Canary
|
from hc.api.models import Check
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def checks(request):
|
def checks(request):
|
||||||
|
|
||||||
canaries = Canary.objects.filter(user=request.user)
|
checks = Check.objects.filter(user=request.user)
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"canaries": canaries
|
"checks": checks
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "checks/index.html", ctx)
|
return render(request, "checks/index.html", ctx)
|
||||||
|
|
|
@ -40,7 +40,7 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
|
||||||
'hc.accounts',
|
'hc.accounts',
|
||||||
'hc.checks',
|
'hc.api',
|
||||||
'hc.front'
|
'hc.front'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,6 @@ from django.contrib import admin
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
url(r'^accounts/', include('hc.accounts.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')),
|
url(r'^', include('hc.front.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
<th>Code</th>
|
<th>Code</th>
|
||||||
<th>Last Ping</th>
|
<th>Last Ping</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for canary in canaries %}
|
{% for check in checks %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ canary.code }}</td>
|
<td>{{ check.code }}</td>
|
||||||
<td>{{ canary.last_ping }}</td>
|
<td>{{ check.last_ping }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue