拍爱

models.py 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django.db import models
  4. from django.utils.translation import ugettext_lazy as _
  5. from pai2.basemodels import CreateUpdateMixin
  6. class GroupInfo(CreateUpdateMixin):
  7. APP_GROUP = 0
  8. SESSION_GROUP = 1
  9. GROUP_FROM = (
  10. (APP_GROUP, u'APP 建群'),
  11. (SESSION_GROUP, u'SESSION 建群'),
  12. )
  13. group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识', db_index=True, unique=True)
  14. admin_id = models.CharField(_(u'admin_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  15. group_name = models.CharField(_(u'group_name'), max_length=255, blank=True, null=True, help_text=u'群组名称')
  16. group_desc = models.TextField(_(u'group_desc'), blank=True, null=True, help_text=u'群组描述')
  17. group_from = models.IntegerField(_(u'group_from'), choices=GROUP_FROM, default=APP_GROUP, help_text=u'群组来源')
  18. session_id = models.CharField(_(u'session_id'), max_length=255, blank=True, null=True, help_text=u'照片组唯一标识', db_index=True)
  19. group_lock = models.BooleanField(_(u'group_lock'), default=False, help_text=u'群组锁定')
  20. class Meta:
  21. verbose_name = _(u'groupinfo')
  22. verbose_name_plural = _(u'groupinfo')
  23. def __unicode__(self):
  24. return unicode(self.group_id)
  25. @property
  26. def data(self):
  27. return {
  28. 'group_id': self.group_id,
  29. 'group_name': self.group_name,
  30. 'group_desc': self.group_desc,
  31. 'group_from': self.group_from,
  32. 'group_lock': self.group_lock,
  33. 'created_at': self.created_at,
  34. }
  35. def users(self, user_id):
  36. all_users = GroupUserInfo.objects.filter(group_id=self.group_id)
  37. passed_users = all_users.filter(user_status=GroupUserInfo.PASSED)
  38. passed_count = passed_users.count()
  39. passed = [passed.user_info for passed in passed_users]
  40. if self.admin_id != user_id:
  41. return {
  42. 'passed_count': passed_count,
  43. 'passed': passed,
  44. }
  45. applying_users = all_users.filter(user_status=GroupUserInfo.APPLYING)
  46. applying_count = applying_users.count()
  47. applying = [applying.user_info for applying in applying_users]
  48. return {
  49. 'applying_count': applying_count,
  50. 'passed_count': passed_count,
  51. 'applying': applying,
  52. 'passed': passed,
  53. }
  54. class GroupUserInfo(CreateUpdateMixin):
  55. APPLYING = 0
  56. PASSED = 1
  57. REFUSED = 2
  58. DELETED = 3
  59. USER_STATUS = (
  60. (APPLYING, u'申请中'),
  61. (PASSED, u'已通过'),
  62. (REFUSED, u'已拒绝'),
  63. (DELETED, u'已删除')
  64. )
  65. group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识', db_index=True)
  66. user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  67. current_id = models.IntegerField(_(u'current_id'), default=-1, help_text=u'当前群组照片ID')
  68. nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
  69. avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
  70. admin = models.BooleanField(_(u'admin'), default=False, help_text=u'群组管理员')
  71. user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS, default=APPLYING)
  72. passed_at = models.DateTimeField(_(u'passed_at'), blank=True, null=True, help_text=_(u'通过时间'))
  73. refused_at = models.DateTimeField(_(u'refused_at'), blank=True, null=True, help_text=_(u'拒绝时间'))
  74. deleted_at = models.DateTimeField(_(u'deleted_at'), blank=True, null=True, help_text=_(u'删除时间'))
  75. class Meta:
  76. verbose_name = _(u'groupuserinfo')
  77. verbose_name_plural = _(u'groupuserinfo')
  78. def __unicode__(self):
  79. return unicode(self.pk)
  80. @property
  81. def user_info(self):
  82. return {
  83. 'user_id': self.user_id,
  84. 'nickname': self.nickname,
  85. 'avatar': self.avatar,
  86. 'admin': self.admin,
  87. }
  88. class GroupPhotoInfo(CreateUpdateMixin):
  89. group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识', db_index=True)
  90. user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  91. nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
  92. photo_path = models.CharField(_(u'photo_path'), max_length=255, blank=True, null=True, help_text=u'照片存放路径')
  93. photo_thumbnail_path = models.CharField(_(u'photo_thumbnail_path'), max_length=255, blank=True, null=True, help_text=u'照片缩略图存放路径')
  94. class Meta:
  95. verbose_name = _(u'groupphotoinfo')
  96. verbose_name_plural = _(u'groupphotoinfo')
  97. def __unicode__(self):
  98. return unicode(self.pk)
  99. @property
  100. def photo_url(self):
  101. return u'{0}/{1}'.format(settings.IMG_DOMAIN, self.photo_path) if self.photo_path else ''
  102. @property
  103. def photo_thumbnail_url(self):
  104. return u'{0}/{1}'.format(settings.IMG_DOMAIN, self.photo_thumbnail_path) if self.photo_thumbnail_path else ''
  105. @property
  106. def photo_info(self):
  107. return {
  108. 'photo_id': self.pk,
  109. 'photo_path': self.photo_url,
  110. 'photo_thumbnail_path': self.photo_thumbnail_url,
  111. }
  112. class PhotoCommentInfo(CreateUpdateMixin):
  113. photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识', db_index=True)
  114. user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  115. nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
  116. avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
  117. comment = models.TextField(_(u'comment'), blank=True, null=True, help_text=u'用户评论')
  118. class Meta:
  119. verbose_name = _(u'photocommentinfo')
  120. verbose_name_plural = _(u'photocommentinfo')
  121. def __unicode__(self):
  122. return unicode(self.pk)
  123. @property
  124. def comment_info(self):
  125. return {
  126. 'user_id': self.user_id,
  127. 'nickname': self.nickname,
  128. 'avatar': self.avatar,
  129. 'comment': self.comment,
  130. 'created_at': self.created_at,
  131. }
  132. class PhotoThumbUpInfo(CreateUpdateMixin):
  133. photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识', db_index=True)
  134. user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  135. nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户群组昵称')
  136. avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
  137. thumbup = models.BooleanField(_(u'thumbup'), default=True, help_text=u'用户点赞', db_index=True)
  138. class Meta:
  139. verbose_name = _(u'photothumbupinfo')
  140. verbose_name_plural = _(u'photothumbupinfo')
  141. def __unicode__(self):
  142. return unicode(self.pk)
  143. @property
  144. def thumbup_info(self):
  145. return {
  146. 'user_id': self.user_id,
  147. 'nickname': self.nickname,
  148. 'avatar': self.avatar,
  149. }