class BlockReward(TimeStampModel):
    """
    Represents the static reward given to the miner of a block in a range of
    block numbers.

    block_range -> Range of the block numbers
    reward -> Reward given
    """

    block_range = BigIntegerRangeField()
    reward = models.DecimalField(max_digits=120, decimal_places=0)
class Room(models.Model):
    class SeatingCount(models.IntegerChoices):
        HEADS_UP = 2, 'Heads-Up'
        THREE_MAX = 3, '3-Max'
        FOUR_MAX = 4, '4-Max'
        SIX_MAX = 6, '6-Max'
        NINE_MAX = 9, '9-Max'

    class Speed(models.TextChoices):
        SLOW = 'S', 'Slow'
        FAST = 'F', 'Fast'

    tables = {}

    name = models.CharField(max_length=255, unique=True)
    buy_in_range = BigIntegerRangeField()
    seating_count = models.PositiveBigIntegerField(
        choices=SeatingCount.choices,
    )
    speed = models.CharField(max_length=255, choices=Speed.choices)

    def __repr__(self):
        return f'room_{self.pk}'

    def __str__(self):
        return f'{self.get_seating_count_display()} ' \
               f'Room {self.name} ' \
               f'({self.get_speed_display()})'

    @property
    def speeds(self):
        if self.speed == self.Speed.SLOW:
            return 3, 2, 30
        elif self.speed == self.Speed.FAST:
            return 2, 1, 15
        else:
            raise ValueError(f'Unknown speed {self.speed}')

    @property
    def table(self):
        if self not in self.tables:
            self.tables[self] = Table(
                self, self.buy_in_range, self.seating_count, *self.speeds,
            )

        return self.tables[self]

    def get_absolute_url(self):
        return reverse('gamemaster:room_detail', kwargs={'pk': self.pk})
Exemple #3
0
class Institution(models.Model):
	name = models.CharField(max_length=255, unique=True, verbose_name=_("Name"))
	code = models.CharField(max_length=8, unique=True, verbose_name=_("Code"))
	as_range = BigIntegerRangeField(blank=True, null=True, verbose_name=_("AS Range"))
	abuse_email = models.EmailField(verbose_name=_("Abuse Email"))
	color = ColorField(default="#808080", verbose_name=_("Institution Color"))

	owners = models.ManyToManyField(User, related_name='institutions', verbose_name=_("Managers"))

	class Meta:
		ordering = ['code']
		verbose_name = ungettext_lazy("Institution", "Institutions", 1)
		verbose_name_plural = ungettext_lazy("Institution", "Institutions", 2)

	@classmethod
	def get_view_qs(cls, user):
		return cls.objects

	def __str__(self):
		return self.name

	def can_edit(self, user):
		return self.owners.filter(id=user.id).exists()
Exemple #4
0
 class RangesModel(models.Model):
     ints = IntegerRangeField(blank=True, null=True)
     bigints = BigIntegerRangeField(blank=True, null=True)
     floats = FloatRangeField(blank=True, null=True)
     timestamps = DateTimeRangeField(blank=True, null=True)
     dates = DateRangeField(blank=True, null=True)