Exemple #1
0
  def AssignDrink(self, drink, user):
    """Assigns, or re-assigns, a previously-recorded Drink.

    Statistics and session data will be recomputed as a side-effect
    of any change to user assignment.  (If the drink is already assigned
    to the given user, this method is a no-op).

    Args:
        drink: The Drink object (or drink id) to assign.
        user: The User object (or username) to set as the owner,
            or None for anonymous.

    Returns:
        The drink.
    """
    drink = get_drink(drink)
    if drink.user == user:
      return drink

    stats.invalidate(drink)
    drink.user = user
    drink.save()
    stats.generate(drink)

    self.cache.update_generation()

    return drink
Exemple #2
0
  def SetDrinkVolume(self, drink, volume_ml):
    """Updates the drink volume."""
    if volume_ml == drink.volume_ml:
      return

    drink.volume_ml = volume_ml
    drink.save()

    stats.invalidate(drink)
    drink.session.Rebuild()
    stats.generate(drink)
Exemple #3
0
  def handle(self, **options):
    stats.invalidate(None)

    drinks = models.Drink.objects.all().order_by('id')
    num_drinks = len(drinks)
    pos = 0
    for d in drinks:
      pos += 1
      progbar('regenerating stats', pos, num_drinks)
      stats.generate(d, invalidate_first=False)

    print ''
    print 'done!'
Exemple #4
0
    def handle(self, **options):
        stats.invalidate(None)

        drinks = models.Drink.objects.all().order_by('id')
        num_drinks = len(drinks)
        pos = 0
        for d in drinks:
            pos += 1
            progbar('regenerating stats', pos, num_drinks)
            stats.generate(d, invalidate_first=False)

        print ''
        print 'done!'
Exemple #5
0
    def CancelDrink(self, drink, spilled=False):
        """Permanently deletes a Drink from the system.

        Associated data, such as SystemEvent, PourPicture, and other data, will
        be destroyed along with the drink. Statistics and session data will be
        recomputed after the drink is destroyed.

        Args:
            drink_id: The Drink, or id of the Drink, to cancel.
            spilled: If True, after canceling the Drink, the drink's volume will
                be added to its Keg's "spilled" total.  This is is typically useful
                for removing test pours from the system while still accounting for
                the lost volume.

        Returns:
            The deleted drink.
        """
        if not isinstance(drink, models.Drink):
            drink = models.Drink.objects.get(id=drink)

        session = drink.session
        drink_id = drink.id
        keg = drink.keg
        volume_ml = drink.volume_ml

        keg_update_fields = ['served_volume_ml']
        keg.served_volume_ml -= volume_ml

        # Transfer volume to spillage if requested.
        if spilled and volume_ml and drink.keg:
            keg.spilled_ml += volume_ml
            keg_update_fields.append('spilled_ml')

        keg.save(update_fields=keg_update_fields)

        # Invalidate all statistics.
        stats.invalidate(drink)

        # Delete the drink, including any objects related to it.
        drink.delete()

        session.Rebuild()

        # Regenerate stats for any drinks following the just-deleted one.
        for drink in models.Drink.objects.filter(
                id__gt=drink_id).order_by('id'):
            stats.generate(drink)

        self.cache.update_generation()

        return drink
Exemple #6
0
    def cancel_drink(self, drink, spilled=False):
        """Permanently deletes a Drink from the system.

        Associated data, such as SystemEvent, PourPicture, and other data, will
        be destroyed along with the drink. Statistics and session data will be
        recomputed after the drink is destroyed.

        Args:
            drink_id: The Drink, or id of the Drink, to cancel.
            spilled: If True, after canceling the Drink, the drink's volume will
                be added to its Keg's "spilled" total.  This is is typically useful
                for removing test pours from the system while still accounting for
                the lost volume.

        Returns:
            The deleted drink.
        """
        if not isinstance(drink, models.Drink):
            drink = models.Drink.objects.get(id=drink)

        session = drink.session
        drink_id = drink.id
        keg = drink.keg
        volume_ml = drink.volume_ml

        keg_update_fields = ['served_volume_ml']
        keg.served_volume_ml -= volume_ml

        # Transfer volume to spillage if requested.
        if spilled and volume_ml and drink.keg:
            keg.spilled_ml += volume_ml
            keg_update_fields.append('spilled_ml')

        keg.save(update_fields=keg_update_fields)

        # Invalidate all statistics.
        stats.invalidate(drink)

        # Delete the drink, including any objects related to it.
        drink.delete()

        session.Rebuild()

        # Regenerate stats for any drinks following the just-deleted one.
        for drink in models.Drink.objects.filter(id__gt=drink_id).order_by('id'):
            stats.generate(drink)

        self.cache.update_generation()

        return drink
Exemple #7
0
    def set_drink_volume(self, drink, volume_ml):
        """Updates the drink volume."""
        if volume_ml == drink.volume_ml:
            return

        difference = volume_ml - drink.volume_ml
        drink.volume_ml = volume_ml
        drink.save(update_fields=['volume_ml'])

        keg = drink.keg
        keg.served_volume_ml += difference
        keg.save(update_fields=['served_volume_ml'])

        stats.invalidate(drink)
        drink.session.Rebuild()

        # Regenerate stats for this drink and all subsequent.
        for drink in models.Drink.objects.filter(id__gte=drink.id).order_by('id'):
            stats.generate(drink)

        self.cache.update_generation()
Exemple #8
0
    def SetDrinkVolume(self, drink, volume_ml):
        """Updates the drink volume."""
        if volume_ml == drink.volume_ml:
            return

        difference = volume_ml - drink.volume_ml
        drink.volume_ml = volume_ml
        drink.save(update_fields=['volume_ml'])

        keg = drink.keg
        keg.served_volume_ml += difference
        keg.save(update_fields=['served_volume_ml'])

        stats.invalidate(drink)
        drink.session.Rebuild()

        # Regenerate stats for this drink and all subsequent.
        for drink in models.Drink.objects.filter(
                id__gte=drink.id).order_by('id'):
            stats.generate(drink)

        self.cache.update_generation()
Exemple #9
0
    def AssignDrink(self, drink, user):
        """Assigns, or re-assigns, a previously-recorded Drink.

        Statistics and session data will be recomputed as a side-effect
        of any change to user assignment.  (If the drink is already assigned
        to the given user, this method is a no-op).

        Args:
            drink: The Drink object (or drink id) to assign.
            user: The User object (or username) to set as the owner,
                or None for anonymous.

        Returns:
            The drink.
        """
        drink = get_drink(drink)
        user = get_user(user)
        if drink.user == user:
            return drink

        drink.user = user
        drink.save()

        stats.invalidate(drink)

        for e in drink.events.all():
            e.user = user
            e.save()
        for p in drink.pictures.all():
            p.user = user
            p.save()

        drink.session.Rebuild()
        stats.generate(drink)

        self.cache.update_generation()
        return drink