+ |
+ Additional Resources |
+
+ {% if can_edit_stream_info or can_edit_individual %}
+ Edit
+ {% endif %}
+ |
+
+ {% if resources or doc.group and doc.group.list_archive %}
+
+
+ {% for resource in resources|dictsort:"display_name" %}
+ {% if resource.name.type.slug == 'url' or resource.name.type.slug == 'email' %}
+ - {% firstof resource.display_name resource.name.name %} |
+ {# Maybe make how a resource displays itself a method on the class so templates aren't doing this switching #}
+ {% else %}
+ - {% firstof resource.display_name resource.name.name %}: {{resource.value}} |
+ {% endif %}
+ {% endfor %}
+ {% if doc.group and doc.group.list_archive %}
+ - Mailing list discussion | |
+ {% endif %}
+
+
+ {% endif %}
+ |
+
+ {% endif %}
+ {% endwith %}
diff --git a/ietf/utils/validators.py b/ietf/utils/validators.py
index 9bf179ae3..68bee7608 100644
--- a/ietf/utils/validators.py
+++ b/ietf/utils/validators.py
@@ -6,10 +6,12 @@ from __future__ import absolute_import, print_function, unicode_literals
import os
import re
from pyquery import PyQuery
+from urllib.parse import urlparse
+
from django.conf import settings
from django.core.exceptions import ValidationError
-from django.core.validators import RegexValidator
+from django.core.validators import RegexValidator, URLValidator, EmailValidator
from django.template.defaultfilters import filesizeformat
from django.utils.deconstruct import deconstructible
@@ -84,3 +86,37 @@ def validate_no_html_frame(file):
q = PyQuery(file.read())
if q("frameset") or q("frame") or q("iframe"):
raise ValidationError('Found content with html frames. Please upload a file that does not use frames')
+
+# instantiations of sub-validiators used by the external_resource validator
+
+validate_url = URLValidator()
+validate_http_url = URLValidator(schemes=['http','https'])
+validate_email = EmailValidator()
+
+def validate_external_resource_value(name, value):
+ """ validate a resource value using its name's properties """
+
+ if name.type.slug == 'url':
+
+ if name.slug in ( 'github_org', 'github_repo' ):
+ validate_http_url(value)
+ if urlparse(value).netloc.lower() != 'github.com':
+ raise ValidationError('URL must be a github url')
+ elif name.slug == 'jabber_room':
+ pass
+ # TODO - build a xmpp URL validator. See XEP-0032.
+ # It should be easy to build one by copyhacking URLValidator,
+ # but reading source says it would be better to wait to do that
+ # until after we make the Django 2 transition
+ else:
+ validate_url(value)
+
+ elif name.type.slug == 'email':
+ validate_email(value)
+
+ elif name.type.slug == 'string':
+ pass
+
+ else:
+ raise ValidationError('Unknown resource type '+name.type.name)
+