~cjohnston/uci-engine/1318774

« back to all changes in this revision

Viewing changes to ticket_system/ticket/api.py

  • Committer: Ubuntu CI Bot
  • Author(s): Andy Doan
  • Date: 2014-05-12 15:49:28 UTC
  • mfrom: (466.2.4 ts-model)
  • Revision ID: ubuntu_ci_bot-20140512154928-ng6cll5viw6ylgji
[r=PS Jenkins bot, Chris Johnston] ticket-api: simplify status values

Simplifies the TicketWorkflowStepStatus values to be consistent
and let the user infer the workflow-step using the "current_workflow_step"
attribute of a ticket.  from Andy Doan

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
import json
17
 
import logging
18
17
 
19
18
from django.shortcuts import get_object_or_404
20
19
 
206
205
        return super(TicketUpdateStatusResource, self).patch_detail(request,
207
206
                                                                    **kwargs)
208
207
 
209
 
    def hydrate_status(self, bundle):
210
 
        fail = [
211
 
            TicketWorkflowStepStatus.PKG_BUILDING_FAILED.value,
212
 
            TicketWorkflowStepStatus.IMAGE_BUILDING_FAILED.value,
213
 
            TicketWorkflowStepStatus.IMAGE_TESTING_FAILED.value,
214
 
            TicketWorkflowStepStatus.PKG_PUBLISHING_FAILED.value,
215
 
        ]
216
 
 
217
 
        step = bundle.data["current_workflow_step"]
218
 
        if bundle.data['status'] in fail and step != TicketWorkflowStep.FAILED:
219
 
            logging.warn('Status detected as failure, failing workflow step')
220
 
            bundle.data["current_workflow_step"] = TicketWorkflowStep.FAILED
221
 
        return bundle
222
 
 
223
208
 
224
209
class TicketStatusResource(TicketTranslatedResource):
225
210
 
230
215
        allowed_methods = ['get']
231
216
        filtering = {
232
217
            "current_workflow_step": ALL,
 
218
            "status": ALL,
233
219
        }
234
220
 
235
221
 
236
 
class SubTicketUpdateStatusResource(TicketTranslatedResource):
 
222
class SubTicketUpdateStatusResource(SubTicketTranslatedResource):
237
223
 
238
224
    class Meta:
239
225
        queryset = SubTicket.objects.all()
246
232
        }
247
233
 
248
234
 
249
 
class SubTicketStatusResource(TicketTranslatedResource):
 
235
class SubTicketStatusResource(SubTicketTranslatedResource):
250
236
 
251
237
    class Meta:
252
238
        queryset = SubTicket.objects.all()
267
253
        resource_name = 'next'
268
254
 
269
255
    def get_object_list(self, request):
270
 
        exclude = [TicketWorkflowStep.NEW.value,
271
 
                   TicketWorkflowStep.FAILED.value,
272
 
                   TicketWorkflowStep.COMPLETED.value]
273
 
        in_progress = [TicketWorkflowStep.PKG_BUILDING.value,
274
 
                       TicketWorkflowStep.IMAGE_BUILDING.value,
275
 
                       TicketWorkflowStep.IMAGE_TESTING.value,
276
 
                       TicketWorkflowStep.PKG_PUBLISHING.value]
277
 
        qs = super(NextTicketResource, self).get_object_list(request).exclude(
278
 
            current_workflow_step__in=exclude).order_by('id')[:1]
279
 
        process = Ticket.objects.exclude(
280
 
            current_workflow_step__in=exclude,
281
 
        ).filter(current_workflow_step__in=in_progress)
282
 
        if process:
283
 
            qs = process
284
 
        else:
285
 
            qs = qs
 
256
        qs = Ticket.objects.filter(
 
257
            current_workflow_step=TicketWorkflowStep.QUEUED
 
258
        ).order_by('id')[:1]
286
259
        return qs
287
260
 
288
261