拍爱

models.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. import os
  4. import time
  5. from django.conf import settings
  6. from django.db import models
  7. from django.utils.translation import ugettext_lazy as _
  8. from pai2.basemodels import CreateUpdateMixin, PlatformMixin, VersionMixin
  9. def upload_path(instance, old_filename):
  10. extension = os.path.splitext(old_filename)[1].lower()
  11. today = datetime.datetime.today()
  12. return 'file/{year}{month}/{timestamp}{extension}'.format(
  13. year=today.year,
  14. month=today.month,
  15. timestamp=int(time.time()),
  16. extension=extension
  17. )
  18. class LatestAppInfo(CreateUpdateMixin):
  19. latest_version = models.CharField(_(u'latest_version'), max_length=255, help_text=u'最新版本')
  20. latest_app = models.FileField(_(u'latest_app'), upload_to=upload_path, blank=True, null=True, help_text=u'最新版 APP')
  21. latest_url = models.URLField(_(u'latest_url'), max_length=255, blank=True, null=True, help_text=u'最新版 APP 链接')
  22. class Meta:
  23. verbose_name = _('latestappinfo')
  24. verbose_name_plural = _('latestappinfo')
  25. def __unicode__(self):
  26. return u'{0.pk}'.format(self)
  27. @property
  28. def final_latest_url(self):
  29. return self.latest_url or u'{}{}'.format(settings.DOMAIN, self.latest_app and self.latest_app.url)
  30. @property
  31. def data(self):
  32. return {
  33. 'latest_version': self.latest_version,
  34. 'latest_url': self.final_latest_url,
  35. }
  36. class SplashInfo(CreateUpdateMixin):
  37. splash_image = models.ImageField(_(u'splash_image'), upload_to=upload_path, blank=True, null=True, help_text=u'启动页面图片')
  38. spalash_image_airtime = models.DateTimeField(_(u'spalash_image_airtime'), blank=True, null=True, help_text=u'启动页面图片开始日期')
  39. spalash_image_deadline = models.DateTimeField(_(u'spalash_image_deadline'), blank=True, null=True, help_text=u'启动页面图片截止日期')
  40. class Meta:
  41. verbose_name = _('splashinfo')
  42. verbose_name_plural = _('splashinfo')
  43. def __unicode__(self):
  44. return u'{0.pk}'.format(self)
  45. @property
  46. def splash_image_url(self):
  47. return self.splash_image and (settings.DOMAIN + self.splash_image.url)
  48. @property
  49. def data(self):
  50. return {
  51. 'splash_image_url': self.splash_image_url,
  52. 'spalash_image_airtime': self.spalash_image_airtime,
  53. 'spalash_image_deadline': self.spalash_image_deadline,
  54. }
  55. class FeedbackInfo(CreateUpdateMixin):
  56. user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  57. feedback = models.TextField(_(u'feedback'), blank=True, null=True, help_text=u'用户反馈')
  58. class Meta:
  59. verbose_name = _('feedbackinfo')
  60. verbose_name_plural = _('feedbackinfo')
  61. def __unicode__(self):
  62. return u'{0.pk}'.format(self)
  63. class GuestEntranceControlInfo(CreateUpdateMixin, PlatformMixin, VersionMixin):
  64. class Meta:
  65. verbose_name = _('guestentrancecontrolinfo')
  66. verbose_name_plural = _('guestentrancecontrolinfo')
  67. def __unicode__(self):
  68. return u'{0.pk}'.format(self)
  69. @property
  70. def data(self):
  71. return {
  72. 'platform': self.platform,
  73. 'min_adr': self.min_adr,
  74. 'min_ios': self.min_ios,
  75. 'max_adr': self.max_adr,
  76. 'max_ios': self.max_ios,
  77. }