def _get_num_views(self, start_date=None, end_date=None):
        """Returns the number of VideoSession objects that are associated with this Video object, optionally filtered by start and end dates."""

        session_filter = {'assignment__task__id__exact' : self.id}
        if start_date is not None:
            if pr_time.is_iso8601(start_date):
                start_date = pr_time.iso8601_to_datetime(start_date)
            session_filter['date_started__gte'] = start_date
        if end_date is not None:
            if pr_time.is_iso8601(end_date):
                end_date = pr_time.iso8601_to_datetime(end_date)
            session_filter['date_started__lte'] = end_date
        return VideoSession.objects.filter(**session_filter).count()
    def _get_num_views(self, start_date=None, end_date=None):
        """Returns the number of VideoSession objects that are associated with this Video object, optionally filtered by start and end dates."""

        session_filter = {'assignment__task__id__exact': self.id}
        if start_date is not None:
            if pr_time.is_iso8601(start_date):
                start_date = pr_time.iso8601_to_datetime(start_date)
            session_filter['date_started__gte'] = start_date
        if end_date is not None:
            if pr_time.is_iso8601(end_date):
                end_date = pr_time.iso8601_to_datetime(end_date)
            session_filter['date_started__lte'] = end_date
        return VideoSession.objects.filter(**session_filter).count()
 def watcher_report(self,
                    auth_token,
                    videos,
                    start_date=None,
                    end_date=None):
     """
     Returns a list of views of the given videos (optinally filtered by date)
     along with some information about the viewer.
     """
     filters = {'member': {'assignment__task__id': videos}}
     if start_date or end_date:
         filters = [filters]
         if start_date:
             if pr_time.is_iso8601(start_date):
                 start_date = pr_time.iso8601_to_datetime(start_date)
             filters.append(
                 {'greater_than_or_equal': {
                     'date_started': start_date
                 }})
         if end_date:
             if pr_time.is_iso8601(end_date):
                 end_date = pr_time.iso8601_to_datetime(end_date)
             filters.append(
                 {'less_than_or_equal': {
                     'date_started': end_date
                 }})
         filters = {'and': filters}
     views = self.get_filtered(auth_token, filters,
                               ['video', 'date_started', 'user'])
     views = Utils.merge_queries(views, facade.managers.VideoManager(),
                                 auth_token, ['name'], 'video')
     views = Utils.merge_queries(views, facade.managers.UserManager(),
                                 auth_token, [
                                     'first_name', 'last_name', 'email',
                                     'default_username_and_domain'
                                 ], 'user')
     return views