Changeset 5addd73


Ignore:
Timestamp:
21/05/2012 17:59:19 (2 years ago)
Author:
yomguy <yomguy@…>
Branches:
master, crem, crem2, dev, dev2, diadems, feature/breadcrumbs, feature/ts-0.5, feature/ts-0.5.4, feature/writecache, generic, lam, lam2, mapsv3, merge, nlivemulti, release/1.4.4, sabiod, server, storage, telecaster
Children:
57fd750
Parents:
c89e8e54
git-author:
yomguy <yomguy@…> (21/05/2012 17:59:19)
git-committer:
yomguy <yomguy@…> (21/05/2012 17:59:19)
Message:

fix item copy with format

Location:
telemeta
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • telemeta/templates/telemeta/mediaitem_copy.html

    r566f17d r5addd73  
    1919 
    2020{% block content %} 
    21   {% block infos %}     
     21  {% block infos %} 
    2222    <div class="infos"> 
    2323     <form enctype="multipart/form-data" id="_mediaItemCopyForm" method="post" action="">{% csrf_token %} 
    2424     <ul>{% for error in form.non_field_errors %}<li class="error">{{ error }}</li>{% endfor %}</ul> 
    2525      <table> 
     26      {% for form in forms %} 
    2627       {% for field in form %} 
    2728            <tr> 
    28             {% if field.html_name == "copied_from_item" %} 
     29            {% if field.html_name in hidden_fields %} 
    2930                <td>{{ field.label_tag.as_hidden }}{{ field.as_hidden }}</td> 
    3031            {% else %} 
     
    4142            </tr> 
    4243       {% endfor %} 
     44       {% endfor %} 
    4345       </table> 
    4446       <div align="center" style="margin-top:3ex;"> 
     
    4951     </form> 
    5052    </div> 
    51   {% endblock infos %}   
     53  {% endblock infos %} 
    5254{% endblock %} 
    5355 
  • telemeta/views/base.py

    rc89e8e54 r5addd73  
    802802            source_item = MediaItem.objects.get(public_id=public_id) 
    803803            item = MediaItem() 
    804             form = MediaItemForm(data=request.POST, files=request.FILES, instance=item) 
    805             if form.is_valid(): 
    806                 form.save() 
    807                 code = form.cleaned_data['code'] 
     804            format = Format() 
     805            item_form = MediaItemForm(data=request.POST, files=request.FILES, instance=item, prefix='item') 
     806            format_form = FormatForm(data=request.POST, instance=format, prefix='format') 
     807 
     808            if item_form.is_valid(): 
     809                item_form.save() 
     810                code = item_form.cleaned_data['code'] 
    808811                if not code: 
    809812                    code = str(item.id) 
     813                if format_form.is_valid(): 
     814                    format.item = item 
     815                    format_form.save() 
    810816 
    811817                performances = MediaItemPerformance.objects.filter(media_item=source_item) 
     
    830836            item.code = auto_code(items, item.collection.code) 
    831837            item.approx_duration = '' 
    832             form = MediaItemForm(instance=item) 
    833             form.code = item.code 
    834             form.file = None 
    835  
    836         return render(request, template, {'item': item, "form": form}) 
     838            item_form = MediaItemForm(instance=item, prefix='item') 
     839            format, created = Format.objects.get_or_create(item=item) 
     840            format_form = FormatForm(instance=format, prefix='format') 
     841            item_form.code = item.code 
     842            item_form.file = None 
     843 
     844        forms = [item_form, format_form] 
     845        hidden_fields = ['item-copied_from_item', 'format-item'] 
     846 
     847        return render(request, template, {'item': item, "forms": forms, 'hidden_fields': hidden_fields,}) 
    837848 
    838849    @method_decorator(permission_required('telemeta.delete_mediaitem')) 
Note: See TracChangeset for help on using the changeset viewer.