~vila/uci-engine/nova-failure

« back to all changes in this revision

Viewing changes to ticket_system/ticket/api.py

  • Committer: Ubuntu CI Bot
  • Author(s): Celso Providelo
  • Date: 2014-11-15 00:10:07 UTC
  • mfrom: (885.8.1 ts-hydrate-subtickets)
  • Revision ID: ubuntu_ci_bot-20141115001007-u685wxtrnc0d9mcn
Fix TicketResource.subtickets *hydration* cycle to fill omitted fields in the bundle so PATCH will not override them with their default values. [r=Ursula Junque, PS Jenkins bot]

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from django.conf.urls import url
22
22
from django.core.urlresolvers import NoReverseMatch
 
23
from django.forms.models import model_to_dict
23
24
from tastypie import fields
24
25
from tastypie.authorization import Authorization
25
26
from tastypie.constants import (
148
149
            if not isinstance(sp, dict):
149
150
                continue
150
151
 
151
 
            # Set the 'id' attribute if the subticket already exists,
152
 
            # it will prevent tastypie to create a conflict one.
 
152
            # Set the all constant model attributes if the subticket
 
153
            # already exists, it will prevent tastypie to override them
 
154
            # or create a conflicting subticket.
153
155
            cls = SubTicketResource._meta.object_class
154
156
            try:
155
157
                obj = cls.objects.get(
156
158
                    ticket=bundle.obj, sourcepackage__name=sp['name'])
157
159
            except cls.DoesNotExist:
158
160
                continue
159
 
            subticket['id'] = obj.id
 
161
 
 
162
            obj_dict = model_to_dict(obj)
 
163
            obj_dict.pop('ticket')
 
164
            obj_dict.pop('sourcepackage')
 
165
            for k, v in obj_dict.iteritems():
 
166
                if k not in subticket.keys():
 
167
                    subticket[k] = v
160
168
 
161
169
        return bundle
162
170