def get_manage_list(self, now): return list( AccessCamOrder.objects( Q(end_date__gt=now) | Q(end_date__exists=False), is_controlled=True, camera=self, ).order_by('create_on'))
def get_show_info(self, access_user, now): if self.operator == access_user or self.owner == access_user: return None, None order = AccessCamOrder.objects( user=access_user, camera=self, ).order_by('-create_on').first() if order.tariff.is_packet: time_left = order.end_date - now else: time_left = timedelta(seconds=order.get_time_left()) return time_left, order
def can_manage(self, access_user, now): if not self.type.is_controlled: return False if self.owner == access_user: return True if not self.is_management_enabled: return False if not self.is_management_public: if not access_user.friends.contains(self.owner): return False if self.is_management_paid and self.operator == None: orders = AccessCamOrder.objects( Q(end_date__gt=now) | Q(end_date__exists=False), is_controlled=True, camera=self, ).order_by('create_on').count() return orders > 0 return self.operator == access_user
def can_show(self, access_user, now): """ return: True, ( owner | paid | free | operator ) False, ( disabled | not_friend | not_paid ) """ if self.owner == access_user: return True, 'owner' if not self.is_view_enabled: return False, 'disabled' if not self.is_view_public: if not access_user.friends.contains(self.owner): return False, 'not_friend' if self.is_view_paid: if self.operator == access_user: return True, 'operator' order = AccessCamOrder.objects( user=access_user, camera=self, ).order_by('-create_on').first() if not order or order.end_date is not None and order.end_date < now: return False, 'not_paid' return True, 'paid' return True, 'free'
def get_manage_list(self, now): return list(AccessCamOrder.objects( Q(end_date__gt=now) | Q(end_date__exists=False), is_controlled=True, camera=self, ).order_by('create_on'))