Annotates configurations indicating if they are runnable. Args: user (User, optional): The user to check. Defaults to None. Returns: PythonConfigQuerySet: The annotated queryset.
(self, user: User = None)
| 842 | ) |
| 843 | |
| 844 | def annotate_runnable(self, user: User = None) -> "PythonConfigQuerySet": |
| 845 | """ |
| 846 | Annotates configurations indicating if they are runnable. |
| 847 | |
| 848 | Args: |
| 849 | user (User, optional): The user to check. Defaults to None. |
| 850 | |
| 851 | Returns: |
| 852 | PythonConfigQuerySet: The annotated queryset. |
| 853 | """ |
| 854 | # we are excluding the plugins that has failed the health_check |
| 855 | qs = ( |
| 856 | self.exclude(health_check_status=False) |
| 857 | # we save the `configured` attribute in the queryset |
| 858 | .annotate_configured(user) |
| 859 | ) |
| 860 | return ( |
| 861 | # this super call parameters are required |
| 862 | super(PythonConfigQuerySet, qs) |
| 863 | # we set the parent `runnable` attribute |
| 864 | .annotate_runnable(user) |
| 865 | # and we do the logic AND between the two fields |
| 866 | .annotate( |
| 867 | runnable=Exact( |
| 868 | # I have no idea how to do the compare |
| 869 | # of two boolean field in a subquery. |
| 870 | # this is the same as runnable =`configured` AND `runnable` |
| 871 | Cast(F("configured"), IntegerField()) * Cast(F("runnable"), IntegerField()), |
| 872 | 1, |
| 873 | ) |
| 874 | ) |
| 875 | ) |
| 876 | |
| 877 | def get_signatures(self, job) -> Generator[Signature, None, None]: |
| 878 | """ |