2018-08-13 07:02:14 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
The main quest models.
|
|
|
|
"""
|
2018-08-10 08:39:51 -04:00
|
|
|
from django.db import models
|
2018-08-13 07:02:14 -04:00
|
|
|
from django.conf import settings
|
2018-08-23 11:57:37 -04:00
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
2018-10-02 11:35:39 -04:00
|
|
|
from taggit.managers import TaggableManager
|
2018-08-10 08:39:51 -04:00
|
|
|
|
2018-08-13 07:02:14 -04:00
|
|
|
class Quest(models.Model):
|
|
|
|
"""
|
|
|
|
The meta quest object. Contains general information about the quest.
|
|
|
|
"""
|
2018-10-03 12:17:57 -04:00
|
|
|
title = models.CharField(max_length=100)
|
2018-08-13 07:02:14 -04:00
|
|
|
owner = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
on_delete=models.CASCADE)
|
2018-09-21 14:18:54 -04:00
|
|
|
anon_name = models.CharField(max_length=20, default="Anonymous")
|
2018-10-05 08:48:07 -04:00
|
|
|
live = models.BooleanField(default=False)
|
2018-09-30 15:20:42 -04:00
|
|
|
live_time = models.DateTimeField(blank=True, null=True)
|
2018-10-02 11:35:39 -04:00
|
|
|
tags = TaggableManager()
|
2018-10-04 14:44:07 -04:00
|
|
|
anonymize = models.BooleanField(default=True)
|
2018-10-05 08:48:07 -04:00
|
|
|
description = models.CharField(max_length=256, blank=True, null=True)
|
2018-08-13 07:02:14 -04:00
|
|
|
|
|
|
|
|
2018-08-24 21:51:03 -04:00
|
|
|
class Message(models.Model):
|
|
|
|
"""
|
|
|
|
Represents a chat message.
|
|
|
|
"""
|
|
|
|
quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
|
|
|
|
user = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
blank=True,
|
|
|
|
null=True)
|
|
|
|
timestamp = models.DateTimeField(auto_now=True)
|
|
|
|
message = models.TextField(max_length=512)
|
|
|
|
|
|
|
|
|
2018-09-25 11:58:07 -04:00
|
|
|
class Page(models.Model):
|
|
|
|
"""
|
|
|
|
Represents the title of a quest page.
|
|
|
|
"""
|
|
|
|
quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
|
|
|
|
page_num = models.CharField(max_length=4)
|
|
|
|
title = models.CharField(max_length=200)
|
2018-09-30 15:20:42 -04:00
|
|
|
appendix = models.BooleanField()
|
2018-09-25 11:58:07 -04:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
|
2018-08-13 07:02:14 -04:00
|
|
|
class Post(models.Model):
|
|
|
|
"""
|
|
|
|
An object for arbituary posts. Contains all post data, type, etc.
|
|
|
|
"""
|
|
|
|
quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
|
2018-09-25 11:58:07 -04:00
|
|
|
page = models.ForeignKey(Page, on_delete=models.CASCADE)
|
2018-08-13 07:02:14 -04:00
|
|
|
POST_TYPES = (
|
|
|
|
('text', 'Text'),
|
|
|
|
('dice', 'Dice'),
|
2018-08-23 11:57:37 -04:00
|
|
|
('poll', 'Poll')
|
|
|
|
)
|
2018-08-13 07:02:14 -04:00
|
|
|
post_type = models.CharField(max_length=4, choices=POST_TYPES)
|
|
|
|
post_text = models.TextField()
|
|
|
|
timestamp = models.DateTimeField(auto_now=True)
|
|
|
|
|
2018-08-23 11:57:37 -04:00
|
|
|
|
|
|
|
class DiceCall(models.Model):
|
|
|
|
"""
|
|
|
|
An object representing dice calls made by the QM.
|
|
|
|
"""
|
|
|
|
post = models.OneToOneField(
|
|
|
|
Post,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
primary_key=True,
|
|
|
|
)
|
2018-09-24 09:59:11 -04:00
|
|
|
dice_roll = models.CharField(max_length=16)
|
2018-08-23 11:57:37 -04:00
|
|
|
strict = models.BooleanField()
|
|
|
|
dice_challenge = models.IntegerField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
validators=[
|
2018-09-24 09:59:11 -04:00
|
|
|
MinValueValidator(1),
|
|
|
|
MaxValueValidator(65536),
|
2018-08-23 11:57:37 -04:00
|
|
|
]
|
|
|
|
)
|
|
|
|
rolls_taken = models.IntegerField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
validators=[
|
2018-09-24 09:59:11 -04:00
|
|
|
MinValueValidator(1),
|
|
|
|
MaxValueValidator(256),
|
2018-08-23 11:57:37 -04:00
|
|
|
]
|
|
|
|
)
|
2018-08-29 14:01:31 -04:00
|
|
|
open = models.BooleanField()
|
2018-08-23 11:57:37 -04:00
|
|
|
|
|
|
|
|
2018-08-24 21:51:03 -04:00
|
|
|
class DiceRoll(models.Model):
|
|
|
|
"""
|
|
|
|
Represents a dice roll made on a valid dicecall.
|
|
|
|
"""
|
|
|
|
dicecall = models.ForeignKey(DiceCall, on_delete=models.CASCADE)
|
|
|
|
message = models.OneToOneField(
|
|
|
|
Message,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
primary_key=True,
|
|
|
|
)
|
2018-09-24 09:59:11 -04:00
|
|
|
roll = models.CharField(max_length=16)
|
2018-08-24 21:51:03 -04:00
|
|
|
results = models.TextField()
|
|
|
|
total = models.IntegerField()
|
|
|
|
|
|
|
|
|
2018-08-29 14:01:31 -04:00
|
|
|
class Poll(models.Model):
|
|
|
|
"""
|
|
|
|
An object representing polls made by the QM.
|
|
|
|
"""
|
|
|
|
post = models.OneToOneField(
|
|
|
|
Post,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
primary_key=True,
|
|
|
|
)
|
|
|
|
multi_choice = models.BooleanField()
|
|
|
|
allow_writein = models.BooleanField()
|
|
|
|
open = models.BooleanField()
|
|
|
|
|
|
|
|
|
|
|
|
class PollOption(models.Model):
|
|
|
|
"""
|
|
|
|
Represents options (choices) attached to a given poll. These can be
|
|
|
|
added by the QM upon creation, or by users through write-ins.
|
|
|
|
"""
|
|
|
|
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
|
|
|
|
text = models.CharField(max_length=200)
|
|
|
|
|
|
|
|
|
|
|
|
class PollVote(models.Model):
|
|
|
|
"""
|
|
|
|
Represents a user voting for an option.
|
|
|
|
"""
|
|
|
|
option = models.ForeignKey(PollOption, on_delete=models.CASCADE)
|
|
|
|
user = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
2018-09-03 17:59:41 -04:00
|
|
|
on_delete=models.CASCADE,
|
|
|
|
blank=True,
|
|
|
|
null=True)
|
2018-08-29 14:01:31 -04:00
|
|
|
ip_address = models.GenericIPAddressField()
|
|
|
|
|
2018-09-04 08:30:20 -04:00
|
|
|
class Meta:
|
|
|
|
unique_together = ('option', 'ip_address')
|