Nessuna descrizione

models.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from datetime import datetime
  2. from django.contrib.auth.models import User
  3. from django.db import models
  4. from django.utils.translation import ugettext_lazy as _, get_language
  5. import arrow
  6. from babel.dates import format_timedelta
  7. # Link a SeumBook counter to a Telegram User
  8. class TelegramUser(models.Model):
  9. counter = models.ForeignKey('counter.Counter', verbose_name=_('counter'))
  10. telegram_user_id = models.BigIntegerField(_('telegram_user_id'), unique=True)
  11. class Meta:
  12. app_label = 'bot'
  13. verbose_name = _('telegram_user')
  14. verbose_name_plural = _('telegram_users')
  15. def __str__(self):
  16. return _('%(counter)s is %(telegram_user_id)d') % {'counter': self.counter, 'telegram_user_id': self.telegram_user_id}
  17. # When a user wants to link his SeumBook account to his Telegram account,
  18. # he/she send a message to the bot in a private chat, then the bot answers with
  19. # an URL to the SeumBook website containing a `verif_key`. The user then log in
  20. # on the SeumBook website, and based on the `verif_key` parameter, we find the
  21. # corresponding Telegram User.
  22. # This object remember which Telegram User received which `verif_key`
  23. class TelegramUserCheck(models.Model):
  24. telegram_user_id = models.BigIntegerField(_('telegram_user_id'))
  25. verif_key = models.TextField(_('verify_key'), unique=True)
  26. class Meta:
  27. app_label = 'bot'
  28. verbose_name = _('telegram_user_check')
  29. verbose_name_plural = _('telegram_user_checks')
  30. def __str__(self):
  31. return _('%(telegram_user_id)d has verif key %(verif_key)s') % {'telegram_user_id': self.telegram_user_id, 'verif_key': self.verif_key}
  32. # Memorize which telegram user is in which chat
  33. class TelegramUserChat(models.Model):
  34. telegram_user_id = models.BigIntegerField(_('telegram_user_id'))
  35. telegram_chat_id = models.BigIntegerField(_('telegram_chat_id'))
  36. class Meta:
  37. app_label = 'bot'
  38. verbose_name = _('telegram_user_chat')
  39. verbose_name_plural = _('telegram_user_chats')
  40. unique_together = ('telegram_user_id', 'telegram_chat_id')
  41. def __str__(self):
  42. return _('%(telegram_user_id)d is in the chat %(telegram_chat)d') % {'telegram_user_id': self.telegram_user_id, 'telegram_chat_id': self.telegram_chat_id}
  43. # Memorize the Telegram chats in which the bot are, and the options of them
  44. class TelegramChat(models.Model):
  45. chat_id = models.BigIntegerField(_('telegram_chat_id'), unique=True)
  46. # notify_only_members: True: only when somebody we know is in the chat has the
  47. # seum, we notify the channel
  48. # notify_only_members: False: we notify the channel for every new seum
  49. notify_only_members = models.BooleanField(_('notify_only_members'))
  50. class Meta:
  51. app_label = 'bot'
  52. verbose_name = _('telegram_chat')
  53. verbose_name_plural = _('telegram_chats')
  54. def __str__(self):
  55. return _('%(chat_id)d is a telegram chat, with option notify_only_members to %(notify_only_members)s') % {'chat_id': self.chat_id, 'notify_only_members': self.notify_only_members}