Ejemplo n.º 1
0
    def get_queryset(self):
        try:
            country = Country.for_code(self.kwargs['country'])
        except Country.DoesNotExist:
            raise Http404

        queryset = super(PublishedDocumentSearchView, self).get_queryset()
        return queryset.published().filter(work__country=country)
Ejemplo n.º 2
0
    def determine_place(self):
        # TODO: this view should support localities, too
        try:
            self.country = Country.for_code(self.kwargs['country'])
        except Country.DoesNotExist:
            raise Http404

        super(PublishedDocumentSearchView, self).determine_place()
Ejemplo n.º 3
0
    def test_inherit_from_work(self):
        w = Work.objects.create(frbr_uri='/za/act/2009/test',
                                title='Test document',
                                country=Country.for_code('za'))
        d = Document(work=w, expression_date='2011-02-01', language=self.eng)
        d.save()

        d = Document.objects.get(pk=d.id)
        assert_equal(w.frbr_uri, d.frbr_uri)
        assert_equal(w.title, d.title)
Ejemplo n.º 4
0
    def test_as_at_date_max_expression_date(self):
        """ The as-at date for an individual work with points in time after the as-at date,
        is the latest point in time date.
        """
        za = Country.for_code('za')
        za.settings.as_at_date = date(2009, 1, 1)
        za.settings.save()

        response = self.client.get(self.api_path + '/za/act/2010/1.json')
        assert_equal(response.data['as_at_date'], "2012-02-02")
Ejemplo n.º 5
0
    def determine_place(self):
        parts = self.kwargs['place'].split('-', 1)
        country = parts[0]
        locality = parts[1] if len(parts) > 1 else None

        try:
            self.country = Country.for_code(country)
        except Country.DoesNotExist:
            raise Http404

        if locality:
            self.locality = self.country.localities.filter(code=locality).first()
            if not self.locality:
                raise Http404

        self.place = self.locality or self.country
Ejemplo n.º 6
0
    def determine_place(self):
        parts = self.kwargs['frbr_uri'].split('/', 2)[1].split('-', 2)

        # country
        try:
            self.country = Country.for_code(parts[0])
        except Country.DoesNotExist:
            raise Http404

        # locality
        if len(parts) > 1:
            self.locality = self.country.localities.filter(code=parts[1]).first()
            if not self.locality:
                raise Http404

        super(PublishedDocumentDetailView, self).determine_place()
Ejemplo n.º 7
0
    def get(self, request, frbr_uri, authorities, *args, **kwargs):
        # strip /akn from v2 api
        if frbr_uri.startswith('/akn'):
            frbr_uri = frbr_uri[4:]

        try:
            FrbrUri.default_language = None
            self.frbr_uri = FrbrUri.parse(frbr_uri)
        except ValueError:
            return HttpResponseBadRequest("Invalid FRBR URI")

        if not self.frbr_uri.language:
            try:
                country = Country.for_code(self.frbr_uri.country)
                self.frbr_uri.language = country.primary_language.code
            except Country.DoesNotExist:
                self.frbr_uri.language = 'eng'

        self.authorities = self.get_authorities(authorities)
        self.references = self.get_references()

        # redirect if there's only one match,
        # or if the user provided an explicit list of authorities
        # to try
        if self.references and (len(self.references) == 1 or authorities):
            return redirect(self.references[0].url)

        # custom 404?
        if not self.references and authorities:
            try:
                not_found_url = next(a.not_found_url for a in self.authorities
                                     if a.not_found_url)
                return redirect(not_found_url)
            except StopIteration:
                pass

        return super(ResolveView, self).get(self,
                                            frbr_uri=frbr_uri,
                                            authorities=authorities,
                                            *args,
                                            **kwargs)
Ejemplo n.º 8
0
    def get(self, request, frbr_uri, authorities, *args, **kwargs):
        try:
            FrbrUri.default_language = None
            self.frbr_uri = FrbrUri.parse(frbr_uri)
        except ValueError:
            return HttpResponseBadRequest("Invalid FRBR URI")

        if not self.frbr_uri.language:
            try:
                country = Country.for_code(self.frbr_uri.country)
                self.frbr_uri.language = country.primary_language.code
            except Country.DoesNotExist:
                self.frbr_uri.language = 'eng'

        self.authorities = self.get_authorities(authorities)
        self.references = self.get_references()

        # redirect if there's only one match,
        # or if the user provided an explicit list of authorities
        # to try
        if self.references and (len(self.references) == 1 or authorities):
            return redirect(self.references[0].url)

        return super(ResolveView, self).get(self, frbr_uri=frbr_uri, authorities=authorities, *args, **kwargs)
Ejemplo n.º 9
0
 def validate_country(self, value):
     try:
         return Country.for_code(value)
     except Country.DoesNotExist:
         raise ValidationError("Invalid country: %s" % value)