diff --git a/django_usta/settings.py b/django_usta/settings.py index 98a19ac6632deb2b0c11d6b74daf18636cd78742..32fe1fe3ee45b083cb0cfb70d044f0509cb67bf5 100644 --- a/django_usta/settings.py +++ b/django_usta/settings.py @@ -284,7 +284,7 @@ CKEDITOR_CONFIGS = { 'toolbar_Custom': [ ['Save', 'Undo', 'Redo', 'Maximize', 'ShowBlocks'], ['Image', 'Table', 'HorizontalRule', 'SpecialChar', 'Tickets', - 'Youtube'], + 'Hotels', 'Youtube'], ['Cut', 'Copy', 'Paste', 'Find', 'Replace'], ['Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat'], ['NumberedList', 'BulletedList', 'Outdent', 'Indent', @@ -293,7 +293,7 @@ CKEDITOR_CONFIGS = { ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], ['Link', 'Unlink', 'NodeLink'], ], - 'extraPlugins': 'youtube,nodelink,tickets', + 'extraPlugins': 'youtube,nodelink,tickets,hotels', 'removePlugins': 'iframe', 'stylesSet': [ {'name': 'Boys 16', 'element': 'span', 'attributes': { diff --git a/htmleditor/templates/htmleditor/news_article.html b/htmleditor/templates/htmleditor/news_article.html index 84ff43e12674301e2bcabcff5ecd7c9a0a762769..ff5e06d7477369c1abb169806e037b45e232bae7 100644 --- a/htmleditor/templates/htmleditor/news_article.html +++ b/htmleditor/templates/htmleditor/news_article.html @@ -3,7 +3,7 @@ {% if news.image.url %} <img class="news-image" alt="{{ news.image.alt }}" src="{{ news.image.url }}"> {% endif %} - {{ news.content|nodelinks }} + {% docreplace news.content %} <p class="news-source">Source{{ news.sources.count|pluralize }}: {% for source in news.sources.all %} {{ source }}{% if not forloop.last %} &{% endif %} diff --git a/htmleditor/templates/htmleditor/news_summary.html b/htmleditor/templates/htmleditor/news_summary.html index 035f9082f8aed6cea513d7c466a12caf498dc039..72d93f662a12faa705c035de7da9bdd6f48f5f70 100644 --- a/htmleditor/templates/htmleditor/news_summary.html +++ b/htmleditor/templates/htmleditor/news_summary.html @@ -11,7 +11,7 @@ </a> <div class="news-date">{{ news.date_created|date }}</div> </div> - <div class="news-content">{% if perms.htmleditor.change_newsarticle %}<a href="{% url 'admin:htmleditor_newsarticle_change' news.pk %}?next={{ request.get_full_path|urlencode }}">✍</a> {% endif %}{{ news.content|nodelinks|truncatewords_html:20 }}</div> + <div class="news-content">{% if perms.htmleditor.change_newsarticle %}<a href="{% url 'admin:htmleditor_newsarticle_change' news.pk %}?next={{ request.get_full_path|urlencode }}">✍</a> {% endif %}{% docreplace news.content as content %}{{ content|truncatewords_html:20 }}</div> <p class="news-source">Source{{ news.sources.count|pluralize }}: {% for source in news.sources.all %} {{ source }}{% if not forloop.last %} &{% endif %} diff --git a/htmleditor/templates/htmleditor/view.html b/htmleditor/templates/htmleditor/view.html index 1cbf2e9556d6978705fb3a6e6daed9d4397da962..8c8c5c2918b35c98153150249c2ab047c27bf634 100644 --- a/htmleditor/templates/htmleditor/view.html +++ b/htmleditor/templates/htmleditor/view.html @@ -6,7 +6,7 @@ {% block main %} {% if document %} <h1>{{ document.name }} {% if perms.htmleditor.change_document %}<a href="{% url 'admin:htmleditor_document_change' document.pk %}?next={{ request.get_full_path|urlencode }}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %}</h1> - {{ document.content|nodelinks }} + {% docreplace document.content %} {% else %} <h1>{{ node.name }}</h1> {% endif %} @@ -23,7 +23,7 @@ <div id="tab-{{ tab.pk }}" class="content"> <h1>{{ tab.document.name }} {% if perms.htmleditor.change_document %}<a href="{% url 'admin:htmleditor_document_change' tab.document.pk %}?next={{ request.get_full_path|urlencode }}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %}</h1> <br> - {{ tab.document.content|nodelinks }} + {% docreplace tab.document.content %} </div> {% endfor %} </div> diff --git a/htmleditor/templatetags/htmleditor_tags.py b/htmleditor/templatetags/htmleditor_tags.py index 5e454dbec9973640e9f5c9689ef6e0db68f6a7fb..2afb4c6cc26fd40c41c1698f0d04bbe5ac5578f0 100644 --- a/htmleditor/templatetags/htmleditor_tags.py +++ b/htmleditor/templatetags/htmleditor_tags.py @@ -9,13 +9,14 @@ from django.core.urlresolvers import reverse from django.conf import settings from htmleditor.models import NewsArticle, NavigationNode, Image +from usta.templatetags import usta_tags register = template.Library() NODE_PATTERN = re.compile(r'\{\{\s+NODE:(?P<pk>\d+)\s+\}\}') TICKET_PATTERN = re.compile(r'<div\s+class="ticket-seating">\s+<p>Ticket Seating Widget</p>\s+</div>') - +HOTEL_PATTERN = re.compile(r'<div\s+class="hotels-table">\s+<p>Hotels Widget</p>\s+</div>') @register.filter def has_content(node, str_list): @@ -30,8 +31,9 @@ def has_content(node, str_list): return node.has_content() or node.children_have_content() -@register.filter -def nodelinks(content): +@register.simple_tag(takes_context=True) +def docreplace(context, content): + "Add widgets and links to htmleditor docs" def repl(match): if match.group(1) == '0': return '/' @@ -46,6 +48,10 @@ def nodelinks(content): template = loader.get_template('htmleditor/ticket_seating.html') return template.render() content = TICKET_PATTERN.sub(repl, content) + def repl(match): + t = template.Template("{% load usta_tags %}{% hotels_table false %}") + return t.render(context) + content = HOTEL_PATTERN.sub(repl, content) return mark_safe(content) diff --git a/static/ckeditor/ckeditor/plugins/hotels/icons/hotels.png b/static/ckeditor/ckeditor/plugins/hotels/icons/hotels.png new file mode 100644 index 0000000000000000000000000000000000000000..5a544aa3cc8541041fced09bd9a7a7144cb2bde3 Binary files /dev/null and b/static/ckeditor/ckeditor/plugins/hotels/icons/hotels.png differ diff --git a/static/ckeditor/ckeditor/plugins/hotels/plugin.js b/static/ckeditor/ckeditor/plugins/hotels/plugin.js new file mode 100644 index 0000000000000000000000000000000000000000..6002272793335faffe264dc4c632a782a367f65d --- /dev/null +++ b/static/ckeditor/ckeditor/plugins/hotels/plugin.js @@ -0,0 +1,22 @@ +CKEDITOR.plugins.add('hotels', { + requires: 'widget', + icons: 'hotels', + + init: function(editor) { + editor.addContentsCss(this.path + 'styles/hotels.css'); + editor.widgets.add('hotels', { + button: 'Add Hotels Widget', + allowedContent: 'div(!hotels-table)', + requiredContent: 'div(hotels-table)', + + upcast: function(element) { + return element.name == 'div' && element.hasClass('hotels-table'); + }, + + template: + '<div class="hotels-table">' + + '<p>Hotels Widget</p>' + + '</div>' + }); + } +}); diff --git a/static/ckeditor/ckeditor/plugins/hotels/styles/hotels.css b/static/ckeditor/ckeditor/plugins/hotels/styles/hotels.css new file mode 100644 index 0000000000000000000000000000000000000000..492b10eca12fad88984934eb87a704f2307b6117 --- /dev/null +++ b/static/ckeditor/ckeditor/plugins/hotels/styles/hotels.css @@ -0,0 +1,11 @@ +.hotels-table { + padding: 8px; + margin: auto; + background: #eee; + border-radius: 20px; + border: 1px solid #ddd; + width: 554px; + height: 525px; + text-align: center; + font-size: large; +} diff --git a/usta/templates/usta/college_coaches.html b/usta/templates/usta/college_coaches.html index d808752b2d25060ac26ecc0792361be9ec8baf4e..9a8bf5526869465fb192fa5e1996fcbb269c2ab6 100644 --- a/usta/templates/usta/college_coaches.html +++ b/usta/templates/usta/college_coaches.html @@ -41,7 +41,7 @@ {% if document %} <div id="coach-registration" class="content"> {% if perms.htmleditor.change_document %}<a href="{% url 'admin:htmleditor_document_change' document.pk %}?next={{ request.get_full_path|urlencode }}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %} - {{ document.content|nodelinks }} + {% docreplace document.content %} </div> {% endif %} </div> diff --git a/usta/templates/usta/hotels_tag.html b/usta/templates/usta/hotels_tag.html new file mode 100644 index 0000000000000000000000000000000000000000..82ec6224c1cda2521dc70c38960cd499d40fc5d1 --- /dev/null +++ b/usta/templates/usta/hotels_tag.html @@ -0,0 +1,31 @@ +{% load static htmleditor_tags %} +{% if show_title %} + <h2 class="map-header">Hotels {% if perms.htmleditor.change_document %}<a href="{% url 'admin:htmleditor_document_change' hotels_information.pk %}?next={{ request.get_full_path|urlencode }}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %}</h2> +{% else %} + {% if perms.htmleditor.change_document %}<h2><a href="{% url 'admin:htmleditor_document_change' hotels_information.pk %}?next={{ request.get_full_path|urlencode }}">Edit This Section <img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a></h2>{% endif %} +{% endif %} +{% docreplace hotels_information.content %}<br> +<table id="map-table-hotels" class="map-table"> + <tr> + <th>Name</th> + <th class="map-address">Address</th> + <th>Rate</th> + <th class="map-description">Description</th> + </tr> + {% if radisson %}{# Host hotel comes first #} + <tr> + <td class="">{% if radisson.link %}<a href="{{ radisson.link }}">{% endif %}{{ radisson.name }}{% if radisson.link %}</a>{% endif %}</td> + <td class=" map-address"><a target="_blank" title="Directions" href='http://maps.google.com/?q=%22{{ radisson.address|urlencode:"" }}%22'>{{ radisson.address }}</a><br>{{ radisson.phone }}</td> + <td class="">{{ radisson.rate }}</td> + <td class="map-description">{{ radisson.description }}</td> + </tr> + {% endif %} + {% for location in locations %} + <tr> + <td class="">{% if location.link %}<a href="{{ location.link }}">{% endif %}{{ location.name }}{% if location.link %}</a>{% endif %}</td> + <td class=" map-address"><a target="_blank" title="Directions" href='http://maps.google.com/?q=%22{{ location.address|urlencode:"" }}%22'>{{ location.address }}</a><br>{{ location.phone }}</td> + <td class="">{{ location.rate }}</td> + <td class="map-description">{{ location.description }}</td> + </tr> + {% endfor %} +</table> diff --git a/usta/templates/usta/index.html b/usta/templates/usta/index.html index 7a6e0b7b997adbec366726a7b5eeb18c5b6f62da..e8c8fafe29f591b48bb5f02eefc39f67f07a83ec 100644 --- a/usta/templates/usta/index.html +++ b/usta/templates/usta/index.html @@ -54,7 +54,7 @@ </div> <div id="front-page-center"> {% if document %} - {{ document.content|nodelinks }} + {% docreplace document.content %} {% endif %} </div> </div> diff --git a/usta/templates/usta/map.html b/usta/templates/usta/map.html index 7c75928fca1521478328a87a5ac6aefdbf7cdbc8..6c66cedf23e0f03c9bce69b65ef0aec15f83768f 100644 --- a/usta/templates/usta/map.html +++ b/usta/templates/usta/map.html @@ -1,5 +1,5 @@ {% extends "usta/base.html" %} -{% load i18n staticfiles htmleditor_tags %} +{% load i18n staticfiles htmleditor_tags usta_tags %} {% block title %}{{ block.super }} | Map{% endblock %} {% block comment %} @@ -72,7 +72,7 @@ {% if category.1 == "Parking" %} <div class="map-divider"> <h2 class="map-header">Parking {% if perms.htmleditor.change_document %}<a href="{% url 'admin:htmleditor_document_change' parking_information.pk %}?next={{ request.get_full_path|urlencode }}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %}</h2> - {{ parking_information.content|nodelinks }}<br> + {% docreplace parking_information.content %}<br> <table id="map-table-parking" class="map-table"> <tr> <th>Name</th> @@ -93,35 +93,7 @@ {% endif %} {% if category.1 == "Hotel" %} <div class="map-divider"> - <h2 class="map-header">Hotels {% if perms.htmleditor.change_document %}<a href="{% url 'admin:htmleditor_document_change' hotels_information.pk %}?next={{ request.get_full_path|urlencode }}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %}</h2> - {{ hotels_information.content|nodelinks }}<br> - <table id="map-table-hotels" class="map-table"> - <tr> - <th>Name</th> - <th class="map-address">Address</th> - <th>Rate</th> - <th class="map-phone">Phone</th> - <th class="map-description">Description</th> - </tr> - {% if radisson %}{# Host hotel comes first #} - <tr> - <td class="">{% if radisson.link %}<a href="{{ radisson.link }}">{% endif %}{{ radisson.name }}{% if radisson.link %}</a>{% endif %}</td> - <td class=" map-address"><a target="_blank" title="Directions" href='http://maps.google.com/?q=%22{{ radisson.address|urlencode:"" }}%22'>{{ radisson.address }}</a></td> - <td class="">{{ radisson.rate }}</td> - <td>{{ radisson.phone }}</td> - <td class="map-description">{{ radisson.description }}</td> - </tr> - {% endif %} - {% for location in places %} - <tr> - <td class="">{% if location.link %}<a href="{{ location.link }}">{% endif %}{{ location.name }}{% if location.link %}</a>{% endif %}</td> - <td class=" map-address"><a target="_blank" title="Directions" href='http://maps.google.com/?q=%22{{ location.address|urlencode:"" }}%22'>{{ location.address }}</a></td> - <td class="">{{ location.rate }}</td> - <td>{{ location.phone }}</td> - <td class="map-description">{{ location.description }}</td> - </tr> - {% endfor %} - </table> + {% hotels_table %} </div> {% endif %} {% if category.1 == "Hospital" %} diff --git a/usta/templatetags/usta_tags.py b/usta/templatetags/usta_tags.py index 58cd4fff2914564beb8a2ca36193fd98f25f41b1..04dbb3049daff857c396d4addc9c121e432fe4a2 100644 --- a/usta/templatetags/usta_tags.py +++ b/usta/templatetags/usta_tags.py @@ -18,6 +18,7 @@ from usta.models import ( YOUTUBE_PATTERN, TournamentDate, PlayerOfTheDay, + MapLocation, ) from htmleditor.models import get_random_generic_banner, Banner from sponsors.models import get_random_sponsor @@ -405,3 +406,24 @@ def potd_drilldown(): return { 'years': years, } + +@register.inclusion_tag('usta/hotels_tag.html', takes_context=True) +def hotels_table(context, show_title=True): + "Show the hotels doc and table" + locations = MapLocation.objects.filter( + category=MapLocation.HOTEL).order_by('name').exclude( + name__contains="Radisson") + + site_settings = get_site_settings() + hotels_information = site_settings.get_setting('hotels_document', None) + + radisson = MapLocation.objects.filter(name__contains="Radisson").first() + + context.update({ + 'radisson': radisson, + 'locations': locations, + 'hotels_information': hotels_information, + 'show_title': show_title, + }) + + return context diff --git a/usta/views.py b/usta/views.py index a692f71297412b1e2d9ef9eff0800628d8f15291..12b0db8fda92b083d2e36cef365af5c038344ae0 100644 --- a/usta/views.py +++ b/usta/views.py @@ -244,24 +244,19 @@ def map_view(request): letter = MapLocation.static_get_category_letter(category) icon = 'images/map_pins/{0}.png'.format(letter.lower()) key = (name, name.replace(' ', '_'), icon) - locations[key] = MapLocation.objects.filter( - category=category).order_by('name').exclude( - name__contains="Radisson") + locations[key] = MapLocation.objects.filter(category=category) map_center = "{lat: 42.291, lng: -85.598}" site_settings = get_site_settings() hotels_information = site_settings.get_setting('hotels_document', None) parking_information = site_settings.get_setting('parking_document', None) - radisson = MapLocation.objects.filter(name__contains="Radisson").first() - return render(request, 'usta/map.html', { 'locations': locations, 'map_center': map_center, 'GOOGLE_API_KEY': getattr(settings, 'GOOGLE_API_KEY', ''), 'hotels_information': hotels_information, 'parking_information': parking_information, - 'radisson': radisson, 'title': 'Map Locations', 'show_generic': True, }) diff --git a/volunteer/templates/volunteer/view_volunteer_topics.html b/volunteer/templates/volunteer/view_volunteer_topics.html index e9438d34efc30a9ff9b375b7269568489e357324..12e0876deab90d49debdcb0d1eee7e12fcf70e10 100644 --- a/volunteer/templates/volunteer/view_volunteer_topics.html +++ b/volunteer/templates/volunteer/view_volunteer_topics.html @@ -45,7 +45,7 @@ <section id="{{ topic.name|slugify }}"> <h1>{{ topic.name }} {% if perms.volunteer.change_volunteertopic %}<a href="{% url 'volunteer:edit_volunteer_topic' topic.pk %}"><img alt="Pencil" title="Edit" src="{% static 'usta/edit.png' %}"></a>{% endif %}</h1> - {{ topic.content|nodelinks }} + {% docreplace topic.content %} </section> {% endfor %} </div>