Sort templates alphabetically

And also select the chosen template as the default one
This commit is contained in:
PCoder 2018-09-27 22:12:04 +02:00
parent 768f3532f7
commit a02c3c6973
2 changed files with 7 additions and 3 deletions

View file

@ -92,11 +92,14 @@ class DCLCalculatorPlugin(CMSPluginBase):
if ids: if ids:
context['templates'] = VMTemplate.objects.filter( context['templates'] = VMTemplate.objects.filter(
vm_type=instance.vm_type vm_type=instance.vm_type
).filter(opennebula_vm_template_id__in=ids) ).filter(opennebula_vm_template_id__in=ids).order_by('name')
else: else:
context['templates'] = VMTemplate.objects.filter( context['templates'] = VMTemplate.objects.filter(
vm_type=instance.vm_type vm_type=instance.vm_type
) ).order_by('name')
context['default_selected_template'] = (
instance.default_selected_template
)
return context return context

View file

@ -91,7 +91,8 @@
<label for="config">OS</label> <label for="config">OS</label>
<select name="config"> <select name="config">
{% for template in templates %} {% for template in templates %}
<option value="{{template.opennebula_vm_template_id}}">{{template.name}}</option>
<option value="{{template.opennebula_vm_template_id}}" {% if template.name|lower == default_selected_template|lower %}selected="selected"{% endif %}>{{template.name}}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>