示例#1
0
 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'))
示例#2
0
    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
示例#3
0
    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
示例#4
0
 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
示例#5
0
 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
示例#6
0
 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'
示例#7
0
 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'
示例#8
0
 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'))