示例#1
0
    def _do_update(self, extra):
        "Perform the update for update_count_total and update_count_unread"
        # Get IDs for current queries
        ids = self.values_list('id', flat=True)
        
        # If no IDs, no sense trying to do anything
        if not ids:
            return self
        
        # Prepare query options
        # IDs and states should only ever be ints, but force them to
        # ints to be sure we don't introduce injection vulns
        opts = {
            'feed':     get_model('yarr', 'Feed')._meta.db_table,
            'entry':    get_model('yarr', 'Entry')._meta.db_table,
            'ids':      ','.join([str(int(id)) for id in ids]),
            
            # Fields which should be set in extra
            'field':    '',
            'where':    '',
        }
        opts.update(extra)

        if transaction.atomic:
            # See https://github.com/mocco/django-fabric/pull/17/commits/3956d44a9527b2c1f4d051e2c94128741a512bd6
            with transaction.atomic():
                self.execute_update_query(opts)
        else:
            self.execute_update_query(opts)

            # Ensure changes are committed in Django 1.5 or earlier
            transaction.commit_unless_managed()
        
        return self
示例#2
0
    def _do_update(self, extra):
        "Perform the update for update_count_total and update_count_unread"
        # Get IDs for current queries
        ids = self.values_list('id', flat=True)

        # If no IDs, no sense trying to do anything
        if not ids:
            return self

        # Prepare query options
        # IDs and states should only ever be ints, but force them to
        # ints to be sure we don't introduce injection vulns
        opts = {
            'feed': get_model('yarr', 'Feed')._meta.db_table,
            'entry': get_model('yarr', 'Entry')._meta.db_table,
            'ids': ','.join([str(int(id)) for id in ids]),

            # Fields which should be set in extra
            'field': '',
            'where': '',
        }
        opts.update(extra)

        if transaction.atomic:
            # See https://github.com/mocco/django-fabric/pull/17/commits/3956d44a9527b2c1f4d051e2c94128741a512bd6
            with transaction.atomic():
                self.execute_update_query(opts)
        else:
            self.execute_update_query(opts)

            # Ensure changes are committed in Django 1.5 or earlier
            transaction.commit_unless_managed()

        return self
示例#3
0
def get_premises_model():
    """
    Support for custom company premises model
    with developer friendly validation.
    """
    try:
        app_label, model_name = PREMISES_MODEL.split('.')
    except ValueError:
        raise ImproperlyConfigured("OPENINGHOURS_PREMISES_MODEL must be of the"
                                   " form 'app_label.model_name'")
    premises_model = get_model(app_label=app_label, model_name=model_name)
    if premises_model is None:
        raise ImproperlyConfigured("OPENINGHOURS_PREMISES_MODEL refers to"
                                   " model '%s' that has not been installed" %
                                   PREMISES_MODEL)
    return premises_model
示例#4
0
def get_premises_model():
    """
    Support for custom company premises model
    with developer friendly validation.
    """
    try:
        app_label, model_name = PREMISES_MODEL.split('.')
    except ValueError:
        raise ImproperlyConfigured("OPENINGHOURS_PREMISES_MODEL must be of the"
                                   " form 'app_label.model_name'")
    premises_model = get_model(app_label=app_label, model_name=model_name)
    if premises_model is None:
        raise ImproperlyConfigured("OPENINGHOURS_PREMISES_MODEL refers to"
                                   " model '%s' that has not been installed"
                                   % PREMISES_MODEL)
    return premises_model
示例#5
0
    def filter_for_cases_related_to_compliance_case(self, compliance_case_id):
        """
        :return a list of cases in a queryset object which are linked to the compliance case id given.
        """

        # We filter cases to look at if an object contains an non-draft licence (if required)
        queryset = self.filter(
            Q(
                baseapplication__licences__status__in=[
                    LicenceStatus.ISSUED,
                    LicenceStatus.REINSTATED,
                    LicenceStatus.REVOKED,
                    LicenceStatus.SUSPENDED,
                    LicenceStatus.SURRENDERED,
                    LicenceStatus.CANCELLED,
                ],
                baseapplication__application_sites__site__site_records_located_at__compliance__id
                =compliance_case_id,
            )
            |
            Q(opengenerallicencecase__site__site_records_located_at__compliance__id
              =compliance_case_id))

        # We filter for OIEL, OICL, OGLs, and specific SIELs (dependant on CLC codes present) as these are the only case
        #   types relevant for compliance cases
        GoodOnLicence = get_model("licences", "GoodOnLicence")
        approved_goods_on_licence = GoodOnLicence.objects.filter(
            good__good__control_list_entries__rating__regex=
            COMPLIANCE_CASE_ACCEPTABLE_GOOD_CONTROL_CODES).values_list(
                "good", flat=True)

        queryset = queryset.filter(case_type__id__in=[
            CaseTypeEnum.OICL.id, CaseTypeEnum.OIEL.id,
            *CaseTypeEnum.OPEN_GENERAL_LICENCE_IDS
        ]) | queryset.filter(
            baseapplication__goods__id__in=approved_goods_on_licence, )

        return queryset.distinct()
示例#6
0
    def search(  # noqa
        self,
        queue_id=None,
        is_work_queue=None,
        user=None,
        status=None,
        case_type=None,
        assigned_user=None,
        case_officer=None,
        include_hidden=None,
        organisation_name=None,
        case_reference=None,  # gov case number
        exporter_application_reference=None,
        exporter_site_name=None,
        exporter_site_address=None,
        control_list_entry=None,
        flags=None,
        country=None,
        team_advice_type=None,
        final_advice_type=None,
        min_sla_days_remaining=None,
        max_sla_days_remaining=None,
        submitted_from=None,
        submitted_to=None,
        finalised_from=None,
        finalised_to=None,
        party_name=None,
        party_address=None,
        goods_related_description=None,
        sla_days_elapsed_sort_order=None,
        sla_days_elapsed=None,
        **kwargs,
    ):
        """
        Search for a user's available cases given a set of search parameters.
        """
        case_qs = (self.submitted().select_related(
            "status", "case_type").prefetch_related(
                "case_assignments",
                "case_assignments__user",
                "case_assignments__queue",
            ))

        if not include_hidden and user:
            EcjuQuery = get_model("cases", "ecjuquery")
            CaseReviewDate = get_model("cases", "casereviewdate")

            case_qs = case_qs.exclude(id__in=EcjuQuery.objects.filter(
                raised_by_user__team_id=user.team.id,
                responded_at__isnull=True).values("case_id").distinct())

            # We hide cases that have a next review date that is set in the future (for your team)
            case_qs = case_qs.exclude(id__in=CaseReviewDate.objects.filter(
                team_id=user.team.id,
                next_review_date__gt=timezone.localtime().date()).values(
                    "case_id"))

        if queue_id and user:
            case_qs = case_qs.filter_based_on_queue(queue_id=queue_id,
                                                    team_id=user.team.id,
                                                    user=user)

        if status:
            case_qs = case_qs.has_status(status=status)

        if case_type:
            case_type = CaseTypeEnum.reference_to_id(case_type)
            case_qs = case_qs.is_type(case_type=case_type)

        if assigned_user:
            if assigned_user == self.NOT_ASSIGNED:
                case_qs = case_qs.not_assigned_to_any_user()
            else:
                case_qs = case_qs.assigned_to_user(user=assigned_user)

        if case_officer:
            if case_officer == self.NOT_ASSIGNED:
                case_officer = None
            case_qs = case_qs.assigned_as_case_officer(user=case_officer)

        if case_reference:
            case_qs = case_qs.with_case_reference_code(case_reference)

        if exporter_application_reference:
            case_qs = case_qs.with_exporter_application_reference(
                exporter_application_reference)

        if organisation_name:
            case_qs = case_qs.with_organisation(organisation_name)

        if exporter_site_name:
            case_qs = case_qs.with_exporter_site_name(exporter_site_name)

        if exporter_site_address:
            case_qs = case_qs.with_exporter_site_address(exporter_site_address)

        if control_list_entry:
            case_qs = case_qs.with_control_list_entry(control_list_entry)

        if flags:
            case_qs = case_qs.with_flags(flags)

        if country:
            case_qs = case_qs.with_country(country)

        if team_advice_type:
            case_qs = case_qs.with_advice(team_advice_type, AdviceLevel.TEAM)

        if final_advice_type:
            case_qs = case_qs.with_advice(final_advice_type, AdviceLevel.FINAL)

        if min_sla_days_remaining or max_sla_days_remaining:
            case_qs = case_qs.with_sla_days_range(
                min_sla=min_sla_days_remaining, max_sla=max_sla_days_remaining)

        if sla_days_elapsed:
            case_qs = case_qs.with_sla_days_elapsed(sla_days_elapsed)

        if submitted_from or submitted_to:
            case_qs = case_qs.with_submitted_range(
                submitted_from=submitted_from, submitted_to=submitted_to)

        if finalised_from or finalised_to:
            case_qs = case_qs.with_finalised_range(
                finalised_from=finalised_from, finalised_to=finalised_to)

        if party_name:
            case_qs = case_qs.with_party_name(party_name)

        if party_address:
            case_qs = case_qs.with_party_address(party_address)

        if goods_related_description:
            case_qs = case_qs.with_goods_related_description(
                goods_related_description)

        if is_work_queue:
            case_qs = case_qs.annotate(case_order=Case(
                When(baseapplication__hmrcquery__have_goods_departed=False,
                     then=0),
                default=1,
                output_field=BinaryField(),
            ))

            case_qs = case_qs.order_by("case_order", "submitted_at")
        else:
            case_qs = case_qs.order_by_date()

        if sla_days_elapsed_sort_order:
            if sla_days_elapsed_sort_order == SortOrder.ASCENDING:
                case_qs = case_qs.order_by("sla_days")
            else:
                case_qs = case_qs.order_by("-sla_days")

        return case_qs.distinct()
示例#7
0
        def test_get_model(self):
            self.assertEqual(get_model('admin', 'LogEntry'), LogEntry)
            with self.assertRaises(LookupError):
                get_model('admin', 'LogExit')

            # App label is case-sensitive, Model name is case-insensitive.
            self.assertEqual(get_model('admin', 'loGentrY'), LogEntry)
            with self.assertRaises(LookupError):
                get_model('Admin', 'LogEntry')

            # A single argument is accepted.
            self.assertEqual(get_model('admin.LogEntry'), LogEntry)
            with self.assertRaises(LookupError):
                get_model('admin.LogExit')
            with self.assertRaises(ValueError):
                get_model('admin_LogEntry')
示例#8
0
 def test_get_model_only_returns_installed_models(self):
     with self.assertRaises(LookupError):
         get_model("not_installed", "NotInstalledModel")