More links on handlepage!
This commit is contained in:
parent
b1854b3f3b
commit
6ac391b765
|
@ -3,7 +3,7 @@
|
|||
{% for field in object|getFields:user %}
|
||||
<tr>
|
||||
<td>{{ field.0 }}</td>
|
||||
<td>{% if field.1.through %}{{ field.1.all|linkObjects|default:"-" }}{% else %}{{ field.1|default:"-" }}{% endif %}</td>
|
||||
<td>{% if field.1.through %}{{ field.1.all|linkObjects|default:"-" }}{% else %}{{ field.1|tryLinkHandle|default:"-" }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% if object|userCanEdit:user %}
|
||||
|
|
|
@ -133,3 +133,20 @@ def findInDatabase(rawValue):
|
|||
results.extend(obj)
|
||||
|
||||
return results
|
||||
|
||||
def findHandleFromStr(rawValue):
|
||||
handleObjs = [
|
||||
whoisdb.models.Contact,
|
||||
whoisdb.models.Maintainer,
|
||||
whoisdb.models.InetNum,
|
||||
whoisdb.models.ASBlock,
|
||||
whoisdb.models.ASNumber,
|
||||
]
|
||||
|
||||
for handleObj in handleObjs:
|
||||
try:
|
||||
return handleObj.objects.get(handle=rawValue)
|
||||
except handleObj.DoesNotExist:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from whoisdb.helpers import getWhoisObjectFields
|
||||
from whoisdb.helpers import getWhoisObjectFields, findHandleFromStr
|
||||
from whoisdb.validators import HandleValidator
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
@ -9,6 +11,22 @@ register = template.Library()
|
|||
def linkObject(value):
|
||||
return mark_safe('<a href="%s">%s</a>' % (value.get_absolute_url(), str(value)))
|
||||
|
||||
@register.filter
|
||||
def tryLinkHandle(handle):
|
||||
try:
|
||||
if not handle:
|
||||
raise ValueError()
|
||||
HandleValidator()(str(handle))
|
||||
obj = findHandleFromStr(handle)
|
||||
if obj:
|
||||
return linkObject(obj)
|
||||
except:
|
||||
pass
|
||||
|
||||
return handle
|
||||
|
||||
|
||||
|
||||
@register.filter
|
||||
def linkObjects(value):
|
||||
links = []
|
||||
|
@ -22,12 +40,9 @@ def linkObjects(value):
|
|||
|
||||
@register.filter
|
||||
def getFields(value, user):
|
||||
print("User is", user)
|
||||
|
||||
owner = value.canEdit(user)
|
||||
|
||||
return getWhoisObjectFields(value, owner)
|
||||
#return [("Handle", value.handle), ("Auth", value.auth)]
|
||||
|
||||
|
||||
@register.filter
|
||||
|
|
Loading…
Reference in New Issue