Files
postgres-web/pgweb/account/admin.py
2014-01-01 16:33:52 +01:00

28 lines
742 B
Python

from django.contrib import admin
from django import forms
import base64
from models import CommunityAuthSite
class CommunityAuthSiteAdminForm(forms.ModelForm):
class Meta:
model = CommunityAuthSite
def clean_cryptkey(self):
x = None
try:
x = base64.b64decode(self.cleaned_data['cryptkey'])
except TypeError, e:
raise forms.ValidationError("Crypto key must be base64 encoded")
if (len(x) != 16 and len(x) != 24 and len(x) != 32):
raise forms.ValidationError("Crypto key must be 16, 24 or 32 bytes before being base64-encoded")
return self.cleaned_data['cryptkey']
class CommunityAuthSiteAdmin(admin.ModelAdmin):
form = CommunityAuthSiteAdminForm
admin.site.register(CommunityAuthSite, CommunityAuthSiteAdmin)