2017-11-16 00:55:49 +01:00
|
|
|
import datetime
|
2017-11-02 12:39:10 +01:00
|
|
|
from typing import Text
|
2016-07-30 00:33:29 +02:00
|
|
|
|
2017-11-16 00:55:49 +01:00
|
|
|
from django.db import models
|
|
|
|
|
2018-01-13 19:37:13 +01:00
|
|
|
from zerver.models import AbstractPushDeviceToken, Realm
|
2013-10-17 16:33:04 +02:00
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def get_remote_server_by_uuid(uuid: Text) -> 'RemoteZulipServer':
|
2016-10-27 23:55:31 +02:00
|
|
|
return RemoteZulipServer.objects.get(uuid=uuid)
|
|
|
|
|
|
|
|
class RemoteZulipServer(models.Model):
|
2017-05-07 20:14:30 +02:00
|
|
|
uuid = models.CharField(max_length=36, unique=True) # type: Text
|
|
|
|
api_key = models.CharField(max_length=64) # type: Text
|
2016-10-27 23:55:31 +02:00
|
|
|
|
2017-05-07 20:14:30 +02:00
|
|
|
hostname = models.CharField(max_length=128, unique=True) # type: Text
|
|
|
|
contact_email = models.EmailField(blank=True, null=False) # type: Text
|
2017-05-16 01:59:07 +02:00
|
|
|
last_updated = models.DateTimeField('last updated', auto_now=True) # type: datetime.datetime
|
2016-10-27 23:55:31 +02:00
|
|
|
|
|
|
|
# Variant of PushDeviceToken for a remote server.
|
2018-01-13 19:37:13 +01:00
|
|
|
class RemotePushDeviceToken(AbstractPushDeviceToken):
|
2018-01-29 08:17:31 +01:00
|
|
|
server = models.ForeignKey(RemoteZulipServer, on_delete=models.CASCADE) # type: RemoteZulipServer
|
2016-10-27 23:55:31 +02:00
|
|
|
# The user id on the remote server for this device device this is
|
2017-10-19 06:21:27 +02:00
|
|
|
user_id = models.BigIntegerField(db_index=True) # type: int
|
|
|
|
token = models.CharField(max_length=4096, db_index=True) # type: bytes
|
|
|
|
|
2017-11-05 11:33:09 +01:00
|
|
|
class Meta:
|
2017-10-19 06:21:27 +02:00
|
|
|
unique_together = ("server", "token")
|
2018-01-13 19:37:13 +01:00
|
|
|
|
|
|
|
class Customer(models.Model):
|
|
|
|
stripe_customer_id = models.CharField(max_length=255, unique=True)
|
2018-01-31 06:33:08 +01:00
|
|
|
realm = models.OneToOneField(Realm, on_delete=models.CASCADE)
|