Beispiel #1
0
    def handle(self, *args, **options):
        client = Client()
        acc = client.account(settings.CURATION_BOT_ACCOUNT)
        for index, transaction in acc.history(
                filter=["delegate_vesting_shares"],
                order="asc",
                only_operation_data=False,
        ):
            op = transaction["op"][1]
            if op.get("delegator") == settings.CURATION_BOT_ACCOUNT:
                continue

            if op.get("delegator") in BLACKLIST:
                continue

            try:
                sponsor = Sponsor.objects.get(username=op.get("delegator"))
                sponsor.delegation_modified_at = add_tz_info(
                    parse(transaction["timestamp"]))
            except Sponsor.DoesNotExist:
                sponsor = Sponsor(
                    username=op.get("delegator"),
                )
                sponsor.delegation_created_at = add_tz_info(
                    parse(transaction["timestamp"]))
            sponsor.delegation_amount = Amount(op.get("vesting_shares")).amount
            sponsor.save()

            print(f"Delegation of {op['delegator']}:"
                  f" {op['vesting_shares']} is saved.")
Beispiel #2
0
 def test_str(self):
     sponsor = Sponsor(url="http://google.com",
                       logo=self.image.name,
                       is_active=True,
                       name="Bar")
     sponsor.save()
     self.assertEqual(str(sponsor), "Bar")
def data_transfer(request):
    URL = "https://ecell.nitrr.ac.in/sponsors/list/"
    r = requests.get(URL)
    data = r.json()
    image_url = 'https://ecell.nitrr.ac.in/static/uploads/sponsors/'
    sponsors = data['spons']
    for sponsor in sponsors:
        # image_name = sponsor['profile_pic'].replace(image_url,'')
        name = sponsor['name']
        details = sponsor['details']
        year = sponsor['year']
        website = sponsor['website']
        contact = sponsor['contact']
        spons_type = sponsor['spons_type']
        year = 2018
        social_media = sponsor['social_media']

        image_name = name + '.jpeg'
        image_location = 'static/uploads/sponsors/' + image_name
        req = requests.get(sponsor['pic'], stream=True)
        with open(image_location, 'wb') as out_file:
            shutil.copyfileobj(req.raw, out_file)
        del req
        pic = image_location
        new_sponsor = Sponsor()
        new_sponsor.name = name
        new_sponsor.details = details
        new_sponsor.spons_type = spons_type
        new_sponsor.year = year
        new_sponsor.website = website
        new_sponsor.contact = contact
        new_sponsor.year = year
        new_sponsor.pic = pic
        new_sponsor.save()
    return JsonResponse({'success': True})
Beispiel #4
0
 def test_sposor_toggle_active(self):
     self.client.login(username='******', password='******')
     sponsor = Sponsor(name='foo', url='http://google.com', logo=self.image)
     sponsor.save()
     response = self.client.post(reverse('sponsors_toggle_active'),
                                 {'key': sponsor.id},
                                 follow=True)
     self.assertEqual(response.status_code, 200)
Beispiel #5
0
 def test_toggle_active(self):
     sponsor = Sponsor(url="http://google.com",
                       logo=self.image.name,
                       is_active=True,
                       name="Bar")
     sponsor.save()
     self.assertTrue(sponsor.is_active)
     sponsor.toggle_active()
     self.assertFalse(sponsor.is_active)
     sponsor.toggle_active()
     self.assertTrue(sponsor.is_active)
Beispiel #6
0
 def test_create_object(self):
     count = Sponsor.objects.count()
     sponsor = Sponsor(name="Foo",
                       url="http://google.com",
                       logo=self.image.name)
     try:
         sponsor.full_clean()
     except ValidationError:
         self.fail("Full clean failed")
     sponsor.save()
     self.assertEqual(count + 1, Sponsor.objects.count())
Beispiel #7
0
 def test_edit_get_staff_user(self):
     self.client.login(username='******', password='******')
     sponsor = Sponsor(name='foo', url='http://google.com', logo=self.image)
     sponsor.save()
     response = self.client.get(reverse('sponsors_edit',
                                        kwargs={'sponsor_id': sponsor.id}),
                                follow=True)
     self.assertEqual(response.status_code, 200)
     context = response.context[-1]
     self.assertEqual(context['form'].__class__, SponsorForm)
     self.assertEqual(context['object'], sponsor)
Beispiel #8
0
 def test_sposor_toggle_active(self):
     self.client.login(email='*****@*****.**', password='******')
     sponsor = Sponsor(name='foo', url='http://google.com', logo=self.image)
     sponsor.save()
     self.assertFalse(sponsor.is_active)
     response = self.client.post(reverse('sponsors_toggle_active'),
                                 {'key': sponsor.id},
                                 follow=True)
     sponsor.refresh_from_db()
     self.assertEqual(response.status_code, 200)
     self.assertTrue(sponsor.is_active)
def data_transfer(request):
    URL = "http://206.189.143.11:9000/sponsors/list/"
    r = requests.get(URL)
    data = r.json()
    image_url = 'http://206.189.143.11:9000/static/uploads/sponsors/'
    # print(data)
    sponsors = data['spons']
    for sponsor_data in sponsors:
        # print(sponsor)
        # print()
        sponsor_s = sponsor_data['sponsors']
        for sponsor in sponsor_s:
            # image_name = sponsor['profile_pic'].replace(image_url,'')
            print(sponsor)
            if sponsor['flag'] is True:
                name = sponsor['name']
                details = sponsor['details']
                year = sponsor['year']
                website = sponsor['website']
                contact = sponsor['contact']
                spons_type = SPONS_TYPE[sponsor['spons_type']]
                year = sponsor['year']
                social_media = '-'

                image_name = name + '.jpeg'
                image_location = 'static/uploads/sponsors/' + image_name
                print(sponsor['pic'])
                req = requests.get(sponsor['pic'], stream=True)
                with open(image_location, 'wb') as out_file:
                    shutil.copyfileobj(req.raw, out_file)
                del req
                pic = image_location
                new_sponsor = Sponsor()
                new_sponsor.name = name
                new_sponsor.details = details
                new_sponsor.spons_type = spons_type
                new_sponsor.year = year
                new_sponsor.website = website
                new_sponsor.contact = contact
                new_sponsor.year = year
                new_sponsor.pic = pic
                new_sponsor.save()
    return JsonResponse({'success': True})
Beispiel #10
0
 def test_do_not_need_url(self):
     count = Sponsor.objects.count()
     sponsor = Sponsor(name='foo', logo=self.image.name)
     sponsor.full_clean()
     sponsor.save()
     self.assertEqual(count + 1, Sponsor.objects.count())