{{ media.url|get_filename }}</a>
{% endif %}
{% else %}
- <a href="{% url telemeta-resource-related type resource.public_id media.id %}">
+ <a href="{% url telemeta-resource-related type resource.code media.id %}">
{% if media.title %}
{{ media.title }}</a>
{% else %}
<a href="{{ media.urlĀ }}" target="_blank">{{ media.url }}</a>
{% else %}
{% if media.file %}
- <a href="{% url telemeta-resource-related type resource.public_id media.id %}" target="_blank">
- {% url telemeta-resource-related type resource.public_id media.id %}
+ <a href="{% url telemeta-resource-related type resource.code media.id %}" target="_blank">
+ {% url telemeta-resource-related type resource.code media.id %}
</a>
{% endif %}
{% endif %}
</dl>
</td>
- <td style="padding-bottom: 1em;">{% if media.is_image %}
+ <td style="padding-bottom: 1em;">
+ {% if media.is_image %}
{% if media.url %}
<a href="{{ media.url }}">
<img src="{{ media.url }}" style="max-width: 420px; max-height: 200px;" /></a>
{% else %}
- <a href="{% url telemeta-resource-related type resource.public_id media.id %}">
- <img src="{% url telemeta-resource-related type resource.public_id media.id %}" style="max-width: 420px; max-height: 200px;" /></a>
+ <a href="{% url telemeta-resource-related type resource.code media.id %}">
+ <img src="{% url telemeta-resource-related type resource.code media.id %}" style="max-width: 420px; max-height: 200px;" /></a>
{% endif %}
{% else %}
{% if media.url %}
from telemeta.forms import *
+# TOOLS
+
def render(request, template, data = None, mimetype = None):
return render_to_response(template, data, context_instance=RequestContext(request),
mimetype=mimetype)
media.title = title.replace('\n', '').strip()
media.save()
+def auto_code(resources, base_code):
+ index = 1
+ while True:
+ code = base_code + '_' + str(index)
+ r = resources.filter(code=code)
+ if not r:
+ break
+ if index == 100:
+ break
+ index += 1
+ return code
+
class GeneralView(object):
"""Provide general web UI methods"""
"""Add an item"""
if public_id:
collection = MediaCollection.objects.get(public_id=public_id)
- item = MediaItem(collection=collection)
+ items = MediaItem.objects.filter(collection=collection)
+ code = auto_code(items, collection.code)
+ item = MediaItem(collection=collection, code=code)
else:
item = MediaItem()
if request.method == 'POST':
return HttpResponseRedirect('/archives/items/'+code)
else:
form = MediaItemForm(instance=item)
+
return render(request, template, {'item': item, 'form': form})