Example #1
0
    def test_publication_date(self):
        a = Act()
        assert_is_none(a.publication_date)

        a.publication_date = '2012-01-02'
        assert_equal(datestring(a.publication_date), '2012-01-02')
        assert_is_instance(a.publication_date, date)
Example #2
0
 def expression_uri(self):
     """ The FRBR Expression URI as a :class:`FrbrUri` instance that uniquely identifies this expression universally. """
     if self._expression_uri is None:
         self._expression_uri = self.work_uri.clone()
         self._expression_uri.language = self.language.code
         if self.expression_date:
             self._expression_uri.expression_date = '@' + datestring(self.expression_date)
     return self._expression_uri
Example #3
0
 def describe(doc):
     info = {
         'id': d.id,
         'expression_date': datestring(d.expression_date),
     }
     if not d.draft:
         info['published_url'] = self.get_published_url(d, with_date=True)
     return info
Example #4
0
 def repeal(self, value):
     self._repeal = None
     if value:
         self.repeal_event = {
             'date': datestring(value.date),
             'repealing_title': value.repealing_title,
             'repealing_uri': value.repealing_uri,
         }
     else:
         self.repeal_event = None
Example #5
0
    def get_points_in_time(self, doc):
        result = []

        expressions = doc.work.expressions().published()
        for date, group in groupby(expressions, lambda e: e.expression_date):
            result.append({
                'date': datestring(date),
                'expressions': ExpressionSerializer(many=True, context=self.context).to_representation(group),
            })

        return result
Example #6
0
 def amendments(self, value):
     self._amendments = None
     self._amended_versions = None
     if value:
         self.amendment_events = [{
             'date': datestring(a.date) if a.date else None,
             'amending_title': a.amending_title,
             'amending_uri': a.amending_uri,
         } for a in value]
     else:
         self.amendment_events = None
Example #7
0
    def test_set_repeal(self):
        a = Act()
        a.body_xml = """
        <body xmlns="http://www.akomantoso.org/2.0"/>
        """

        a.repeal = RepealEvent(date='2012-02-01', repealing_uri='/za/act/1980/10', repealing_title='Foo')

        assert_equal(a.to_xml(), """<akomaNtoso xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.akomantoso.org/2.0" xsi:schemaLocation="http://www.akomantoso.org/2.0 akomantoso20.xsd">
  <act contains="originalVersion">
    <meta>
      <identification source="#cobalt">
        <FRBRWork>
          <FRBRthis value="/za/act/1900/1/main"/>
          <FRBRuri value="/za/act/1900/1"/>
          <FRBRalias value="Untitled"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
        </FRBRManifestation>
      </identification>
      <lifecycle source="#cobalt">
        <eventRef id="repeal-2012-02-01" date="2012-02-01" type="repeal" source="#repeal-source"/>
      </lifecycle>
      <references>
        <TLCOrganization id="cobalt" href="https://github.com/Code4SA/cobalt" showAs="cobalt"/>
        <passiveRef id="repeal-source" href="/za/act/1980/10" showAs="Foo"/>
      </references>
    </meta>
    <body/>
  </act>
</akomaNtoso>
""")

        assert_equal(a.repeal.repealing_uri, '/za/act/1980/10')
        assert_equal(a.repeal.repealing_title, 'Foo')
        assert_equal(datestring(a.repeal.date), '2012-02-01')

        # check that clearing it works
        a.repeal = None
        assert_is_none(a.repeal)
Example #8
0
def set_repeal_details(apps, schema_editor):
    Document = apps.get_model("indigo_api", "Document")
    db_alias = schema_editor.connection.alias
    for doc in Document.objects.using(db_alias).all():
        a = Act(doc.document_xml)
        repeal = a.repeal
        if repeal:
            doc.repeal_event = {
                'date': datestring(repeal.date),
                'repealing_title': repeal.repealing_title,
                'repealing_uri': repeal.repealing_uri,
            }
            doc.save()
Example #9
0
def set_amendment_details(apps, schema_editor):
    Document = apps.get_model("indigo_api", "Document")
    db_alias = schema_editor.connection.alias
    for doc in Document.objects.using(db_alias).all():
        a = Act(doc.document_xml)
        amendments = a.amendments
        if amendments:
            doc.amendment_events = [{
                'date': datestring(e.date),
                'amending_title': e.amending_title,
                'amending_uri': e.amending_uri,
            } for e in amendments]
            doc.save()
Example #10
0
def uncreate_repeals(apps, schema_editor):
    Work = apps.get_model("indigo_api", "Work")
    db_alias = schema_editor.connection.alias

    # copy repeal info back into documents
    works = Work.objects.using(db_alias).filter(repealed_by__isnull=False).all()

    for work in works:
        for doc in work.document_set.all():
            doc.repeal_event = {
                'repealing_uri': work.frbr_uri,
                'repealing_title': work.title,
                'date': datestring(work.repealed_date),
            }
            doc.save(update_fields=['repeal_event'])
Example #11
0
    def get_published_url(self, doc, with_date=False):
        if doc.draft:
            return None

        uri = doc.work_uri
        if with_date and doc.expression_date:
            uri.expression_date = '@' + datestring(doc.expression_date)
        else:
            uri.expression_date = None

        uri = uri.expression_uri()[1:]

        uri = reverse('published-document-detail', request=self.context['request'],
                      kwargs={'frbr_uri': uri})
        return uri.replace('%40', '@')
Example #12
0
 def test_manifestation_date(self):
     a = Act()
     a.manifestation_date = '2012-01-02'
     assert_equal(datestring(a.manifestation_date), '2012-01-02')
     assert_is_instance(a.manifestation_date, date)
Example #13
0
 def test_expression_date(self):
     a = Act()
     a.expression_date = '2012-01-02'
     assert_equal(datestring(a.expression_date), '2012-01-02')
     assert_is_instance(a.expression_date, date)
Example #14
0
 def test_work_date(self):
     a = Act()
     a.work_date = '2012-01-02'
     assert_equal(datestring(a.work_date), '2012-01-02')
     assert_is_instance(a.work_date, date)
Example #15
0
    def test_set_amendments(self):
        a = Act()
        a.body_xml = """
        <body xmlns="http://www.akomantoso.org/2.0"/>
        """

        a.amendments = [AmendmentEvent(date='2012-02-01', amending_uri='/za/act/1980/10', amending_title="Foo")]

        assert_equal(a.to_xml(), """<akomaNtoso xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.akomantoso.org/2.0" xsi:schemaLocation="http://www.akomantoso.org/2.0 akomantoso20.xsd">
  <act contains="singleVersion">
    <meta>
      <identification source="#cobalt">
        <FRBRWork>
          <FRBRthis value="/za/act/1900/1/main"/>
          <FRBRuri value="/za/act/1900/1"/>
          <FRBRalias value="Untitled"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
        </FRBRManifestation>
      </identification>
      <lifecycle source="#cobalt">
        <eventRef id="amendment-2012-02-01" date="2012-02-01" type="amendment" source="#amendment-0-source"/>
      </lifecycle>
      <references>
        <TLCOrganization id="cobalt" href="https://github.com/Code4SA/cobalt" showAs="cobalt"/>
        <passiveRef id="amendment-0-source" href="/za/act/1980/10" showAs="Foo"/>
      </references>
    </meta>
    <body/>
  </act>
</akomaNtoso>
""")

        a.amendments = [
            AmendmentEvent(date='2012-02-01', amending_uri='/za/act/1980/22', amending_title="Corrected"),
            AmendmentEvent(date='2013-03-03', amending_uri='/za/act/1990/5', amending_title="Bar"),
        ]
        assert_equals(a.to_xml(), """<akomaNtoso xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.akomantoso.org/2.0" xsi:schemaLocation="http://www.akomantoso.org/2.0 akomantoso20.xsd">
  <act contains="singleVersion">
    <meta>
      <identification source="#cobalt">
        <FRBRWork>
          <FRBRthis value="/za/act/1900/1/main"/>
          <FRBRuri value="/za/act/1900/1"/>
          <FRBRalias value="Untitled"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
        </FRBRManifestation>
      </identification>
      <lifecycle source="#cobalt">
        <eventRef id="amendment-2012-02-01" date="2012-02-01" type="amendment" source="#amendment-0-source"/>
        <eventRef id="amendment-2013-03-03" date="2013-03-03" type="amendment" source="#amendment-1-source"/>
      </lifecycle>
      <references>
        <TLCOrganization id="cobalt" href="https://github.com/Code4SA/cobalt" showAs="cobalt"/>
        <passiveRef id="amendment-0-source" href="/za/act/1980/22" showAs="Corrected"/>
        <passiveRef id="amendment-1-source" href="/za/act/1990/5" showAs="Bar"/>
      </references>
    </meta>
    <body/>
  </act>
</akomaNtoso>
""")

        amendment = a.amendments[0]
        assert_equal(datestring(amendment.date), '2012-02-01')
        assert_equal(amendment.amending_uri, '/za/act/1980/22')
        assert_equal(amendment.amending_title, 'Corrected')

        amendment = a.amendments[1]
        assert_equal(datestring(amendment.date), '2013-03-03')
        assert_equal(amendment.amending_uri, '/za/act/1990/5')
        assert_equal(amendment.amending_title, 'Bar')