~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/models.py

[r=adeuring,abentley][bug=1199790][author=adeuring] Return dummy data for Charm.last_change and Charm.first_change, if a branch does not have any commits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
470
470
        """The list of revision info dicts from the charm's branch."""
471
471
        return self._representation['changes']
472
472
 
 
473
    def _get_change(self, name):
 
474
        # Some view functions assume that last_change and first_change
 
475
        # always exist, but this is not true for empty branches. Return
 
476
        # some default data in this case.
 
477
        change = self._representation[name]
 
478
        if change is None:
 
479
            return {
 
480
                'authors': [],
 
481
                'revno': 0,
 
482
                'committer': '',
 
483
                'created': None,
 
484
                'message': '',
 
485
            }
 
486
        return change
 
487
 
473
488
    @property
474
489
    def first_change(self):
475
490
        """The revision dict of the first change to the charm's branch."""
476
 
        return self._representation['first_change']
 
491
        return self._get_change('first_change')
477
492
 
478
493
    @property
479
494
    def last_change(self):
480
495
        """The revision dict of the last change to the charm's branch."""
481
 
        return self._representation['last_change']
 
496
        return self._get_change('last_change')
482
497
 
483
498
    @property
484
499
    def revision(self):