More links on handlepage!
This commit is contained in:
parent
b1854b3f3b
commit
6ac391b765
|
@ -3,7 +3,7 @@
|
||||||
{% for field in object|getFields:user %}
|
{% for field in object|getFields:user %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ field.0 }}</td>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if object|userCanEdit:user %}
|
{% if object|userCanEdit:user %}
|
||||||
|
|
|
@ -133,3 +133,20 @@ def findInDatabase(rawValue):
|
||||||
results.extend(obj)
|
results.extend(obj)
|
||||||
|
|
||||||
return results
|
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 import template
|
||||||
from django.utils.safestring import mark_safe
|
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()
|
register = template.Library()
|
||||||
|
|
||||||
|
@ -9,6 +11,22 @@ register = template.Library()
|
||||||
def linkObject(value):
|
def linkObject(value):
|
||||||
return mark_safe('<a href="%s">%s</a>' % (value.get_absolute_url(), str(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
|
@register.filter
|
||||||
def linkObjects(value):
|
def linkObjects(value):
|
||||||
links = []
|
links = []
|
||||||
|
@ -22,12 +40,9 @@ def linkObjects(value):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def getFields(value, user):
|
def getFields(value, user):
|
||||||
print("User is", user)
|
|
||||||
|
|
||||||
owner = value.canEdit(user)
|
owner = value.canEdit(user)
|
||||||
|
|
||||||
return getWhoisObjectFields(value, owner)
|
return getWhoisObjectFields(value, owner)
|
||||||
#return [("Handle", value.handle), ("Auth", value.auth)]
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
|
|
Loading…
Reference in New Issue