def form_valid(self, form):
        """Custom form_valid method."""

        obj = form.save(commit=False)

        gleif_data = GLEIF(obj.lei)

        # If the person setting up is a commercial, take that person
        # else, do nothing
        group_list = self.request.user.groups.all().values('name')
        user_groups = []
        for group in group_list:
            user_groups.append(group['name'])

        if 'Commercial' in user_groups:
            obj.relationship_manager = self.request.user
        else:
            pass

        obj.legal_name = gleif_data.entity.legal_name
        obj.short_name = gleif_data.entity.legal_name

        # We need the object instance to save the event, hence saving here
        obj.save()

        # Log the event
        Event.objects.create(issuer=obj,
                             event_type_id=1,
                             triggered_by_user=self.request.user)

        return super(IssuerCreateView, self).form_valid(form)
    def clean(self):
        """Custom method to clean and validate data."""

        cleaned_data = super(AddIssuerForm, self).clean()

        # Add a way to insert issuers manually
        if not cleaned_data['lei'][0:4] == 'LEI_':
            try:
                GLEIF(cleaned_data['lei']).entity.legal_name

            except:  # noqa E722
                raise forms.ValidationError(
                    "There is no issuer with that lei-code."
                )
Exemple #3
0
    def populate_legal_name(self):
        """
        Using the GLEIF library we can easily retrieve the legal name, though
        the pypi package is outdated the repo is current at the time of writing

        * NOTE The exceptions GLEIF raises are not so standard
        """
        try:
            self.legal_name = GLEIF(self.lei).entity.legal_name
        except IndexError:
            # GLEIF will return this when the LEI is not found
            raise ValidationError("Not existent LEI")
        except HTTPError:
            raise ValidationError("Invalid LEI or GLEIF Lookup API not available")
Exemple #4
0
def issuer_setup_address(sender, instance, created, **kwargs):
    """Makes sure there is an instance whenever someone
    saves the corporate model."""

    p, _ = Address.objects.get_or_create(issuer=instance)

    try:
        gleif_data = GLEIF(instance.lei)

        country_obj = CountryRegion.objects.get(
            iso_31661_alpha_2=gleif_data.entity.legal_address.country)

        p.country = country_obj
        p.save()

    except Exception:
        pass
Exemple #5
0
 def setUp(self):
     self.data = GLEIF('549300MLUDYVRQOOXS22')
Exemple #6
0
    def test_break_gleif_entity(self):
        data = GLEIF('549300MWQEN1427O5L53')
        self.assertEqual(data.entity.legal_form, "Aktiebolag")

        data = GLEIF('MAES062Z21O4RZ2U7M96')
        self.assertEqual(data.entity.legal_form, "ELF code: ZRPO")
 def api_data(self):
     """Query the GLEIF API
     :return: An object"""
     return GLEIF(self.lei_code)
    is_aa_plus = row['is_aa_plus']
    is_ccc = row['is_ccc']
    is_cc = row['is_cc']
    is_c = row['is_c']

    # Insert issuer if it does not exist
    try:

        i = Issuer.objects.get(lei=lei, )

    except Issuer.DoesNotExist:

        try:

            try:
                gleif_data = GLEIF(lei)

                legal_name = gleif_data.entity.legal_name

            except Exception:

                legal_name = lei

            i = Issuer.objects.create(
                lei=lei,
                issuer_type_id=issuer_type_id,
                legal_name=legal_name,
                short_name=legal_name,
                gics_sub_industry_id=None,
            )