Exemplo n.º 1
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")
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def sponsors(context):
    self = context.get('self')
    if hasattr(self, 'show_sponsors') and self.show_sponsors:
        sponsors = Sponsor.for_event(self)
    else:
        sponsors = []
    return {
        'sponsors': sponsors,
        'request': context['request'],
    }
Exemplo n.º 6
0
def sponsors(context):
    self = context.get('self')
    if hasattr(self, 'show_sponsors') and self.show_sponsors:
        sponsors = Sponsor.for_event(self)
    else:
        sponsors = []
    return {
        'sponsors': sponsors,
        'request': context['request'],
    }
Exemplo n.º 7
0
def sponsors(context):
    self = context.get("self")
    if hasattr(self, "show_sponsors") and self.show_sponsors:
        sponsors = Sponsor.for_event(self)
    else:
        sponsors = []
    return {
        "sponsors": sponsors,
        "request": context["request"],
    }
Exemplo n.º 8
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.")
Exemplo n.º 9
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)
Exemplo n.º 10
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())
Exemplo n.º 11
0
    def test_simple_sponsor(self):
        s = Sponsor(name='Test Sponsor')
        im = Image.new('1', (1, 1))
        b = BytesIO()
        im.save(b, 'PNG')
        s.logo.save('test.png', ContentFile(b.getvalue()), save=True)

        page = SponsorPage(name='Sponsor',
                           sponsors=[
                               {
                                   "name": "empty-column",
                                   "sponsors": []
                               },
                               {
                                   "name": "test-column",
                                   "sponsors": [s.id]
                               },
                           ])
        page.save()
        self.assertNotIn('empty-column', page._html)
        self.assertIn('test-column', page._html)
        self.assertIn('Test Sponsor', page._html)
Exemplo n.º 12
0
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})
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})
Exemplo n.º 14
0
 def test_object_must_have_name(self):
     sponsor = Sponsor(url="http://google.com", logo=self.image.name)
     with self.assertRaises(ValidationError):
         sponsor.full_clean()
Exemplo n.º 15
0
 def test_object_must_have_valid_url(self):
     sponsor = Sponsor(name="foo", logo=self.image.name, url="goo.baz")
     with self.assertRaises(ValidationError):
         sponsor.full_clean()
Exemplo n.º 16
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())
Exemplo n.º 17
0
 def test_must_have_image(self):
     sponsor = Sponsor(url="http://google.com", name="foo")
     with self.assertRaises(ValidationError):
         sponsor.full_clean()