mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-02-02 01:44:40 +00:00
pyi2phosts/postkey/admin.py: add name/key validation
This commit is contained in:
parent
d017333906
commit
08fa9c1ae7
@ -1,14 +1,37 @@
|
||||
from django.contrib import admin
|
||||
from django import forms
|
||||
|
||||
from pyi2phosts.lib.utils import get_b32
|
||||
from pyi2phosts.postkey.models import i2phost
|
||||
from pyi2phosts.postkey.models import PendingHost
|
||||
from django.contrib import admin
|
||||
from pyi2phosts.lib.validation import validate_hostname
|
||||
from pyi2phosts.lib.validation import validate_b64hash
|
||||
|
||||
|
||||
class i2phostAdminForm(forms.ModelForm):
|
||||
""" Custom form for editing hosts via admin interface """
|
||||
class Meta:
|
||||
model = i2phost
|
||||
|
||||
def clean_name(self):
|
||||
"""Validate hostname"""
|
||||
data = self.cleaned_data['name']
|
||||
data = validate_hostname(data)
|
||||
return data
|
||||
|
||||
def clean_b64hash(self):
|
||||
"""Validate base64 hash"""
|
||||
data = self.cleaned_data['b64hash']
|
||||
data = validate_b64hash(data)
|
||||
return data
|
||||
|
||||
|
||||
class i2phostAdmin(admin.ModelAdmin):
|
||||
def url(self, hostname):
|
||||
return '<a href=http://' + get_b32(hostname.b64hash) + '>b32</a>'
|
||||
return '<a href="http://' + get_b32(hostname.b64hash) + '">b32</a>'
|
||||
|
||||
form = i2phostAdminForm
|
||||
url.allow_tags = True
|
||||
|
||||
list_display = ('url', 'name', 'description', 'date_added', 'last_seen', 'expires',
|
||||
'activated', 'external')
|
||||
list_display_links = ['name']
|
||||
@ -16,6 +39,7 @@ class i2phostAdmin(admin.ModelAdmin):
|
||||
search_fields = ['name']
|
||||
ordering = ['-date_added']
|
||||
|
||||
|
||||
class PendingAdmin(i2phostAdmin):
|
||||
def queryset(self, request):
|
||||
qs = super(PendingAdmin, self).queryset(request)
|
||||
@ -25,5 +49,6 @@ class PendingAdmin(i2phostAdmin):
|
||||
list_display = ('url', 'name', 'description', 'date_added', 'last_seen', 'expires', 'approved')
|
||||
list_editable = ['approved']
|
||||
|
||||
|
||||
admin.site.register(i2phost, i2phostAdmin)
|
||||
admin.site.register(PendingHost, PendingAdmin)
|
||||
|
Loading…
x
Reference in New Issue
Block a user