Пример #1
0
    def setUpTestData(cls):
        TEST_URL = "http://localhost/"
        TEST_SECRET = "thisisaverystrongsecret"

        webhooks = Webhook.objects.bulk_create(
            [
                Webhook(
                    name="Create Webhook",
                    type_create=True,
                    url=TEST_URL,
                    secret=TEST_SECRET,
                ),
                Webhook(
                    name="Update Webhook",
                    type_update=True,
                    url=TEST_URL,
                    secret=TEST_SECRET,
                ),
                Webhook(
                    name="Delete Webhook",
                    type_delete=True,
                    url=TEST_URL,
                    secret=TEST_SECRET,
                ),
            ]
        )
        Tag.objects.bulk_create(
            (
                Tag(name="Foo", slug="foo"),
                Tag(name="Bar", slug="bar"),
                Tag(name="Baz", slug="baz"),
            )
        )
Пример #2
0
    def setUpTestData(cls):
        tag = Tag(name="Tag 1", slug="tag-1")
        tag.save()

        user = User.objects.create_user(username="******")
        for i in range(1, 4):
            uid = uuid.uuid4()
            change = tag.get_change(ObjectChangeAction.UPDATE)
            change.user = user
            change.request_id = uid
            change.save()
Пример #3
0
def get_tag(name):

    print 'get_tag(%s)' % name
    try:
        tag = Tag.objects.get(name=name)
        print 'got existing tag: %s' % tag
        return tag
    except:
        tag = Tag(name=name)
        tag.save()
        print 'created new tag: %s' % tag
        return tag
Пример #4
0
    def setUpTestData(cls):
        Tag.objects.bulk_create((
            Tag(name="Tag 1", slug="tag-1"),
            Tag(name="Tag 2", slug="tag-2"),
            Tag(name="Tag 3", slug="tag-3"),
        ))

        cls.form_data = {
            "name": "Tag 4",
            "slug": "tag-4",
            "color": "c0c0c0",
            "comments": "Some comments",
        }

        cls.bulk_edit_data = {"color": "00ff00"}
Пример #5
0
    async def create(self,
                     ctx: MyContext,
                     tag_name: TagName,
                     *,
                     tag_content=""):
        """
        Create a new tag. The tag name must not be an existing tag or tag alias.
        """
        _ = await ctx.get_translate_function()
        tag = await get_tag(tag_name, increment_uses=False)

        if len(ctx.message.attachments):
            url = ctx.message.attachments[0].url
            if tag_content:
                tag_content += "\n\n" + url
            else:
                tag_content = url

        if not tag_content:
            await ctx.reply(
                _("❌ You didn't specify what you want your tag to say."))

        if tag:
            await ctx.reply(_("❌ This tag already exists."))
        else:
            db_user = await get_from_db(ctx.author, as_user=True)
            tag = Tag(name=tag_name, content=tag_content, owner=db_user)

            await tag.save()
            await ctx.reply(
                _("👌 Tag created: {tag.name} (`{tag.pk}`)", tag=tag))
Пример #6
0
 def save(self, **kwargs):
     super(Post, self).save(**kwargs)
     # Add UserTags
     for user in UserProfile.auto_tag(self.text_content):
         user_profile = UserProfile.objects.get(user=user)
         UserTag(user_profile=user_profile, post=self).save()
     # Save tags
     for tag in Tag.extract(self.text_content):
         PostTag(post=self, tag=tag).save()
    def setUpTestData(cls):
        tag = Tag(name="Tag 1", slug="tag-1")
        tag.save()

        user = User.objects.create_user(username="******")
        for i in range(1, 4):
            tag.log_change(user, uuid.uuid4(), ObjectChangeAction.UPDATE)
Пример #8
0
    def setUpTestData(cls):
        tag = Tag(name="Tag 1", slug="tag-1")
        tag.save()

        user = User.objects.create_user(username="******")
        for i in range(1, 4):
            tag.log_change(user, uuid.uuid4(), OBJECT_CHANGE_ACTION_UPDATE)
Пример #9
0
 def setUpTestData(cls):
     Tag.objects.bulk_create((
         Tag(name="Tag 1", slug="tag-1"),
         Tag(name="Tag 2", slug="tag-2"),
         Tag(name="Tag 3", slug="tag-3"),
     ))
Пример #10
0
 def setUpTestData(cls):
     cls.tags = [
         Tag(name="Tag 1", slug="tag-1"),
         Tag(name="Tag 2", slug="tag-2"),
         Tag(name="Tag 3", slug="tag-3"),
     ]
     Tag.objects.bulk_create(cls.tags)
     cls.routing_policies = [
         RoutingPolicy(name="Reject All", slug="reject-all", weight=255),
         RoutingPolicy(name="Accept All", slug="accept-all", weight=255),
         RoutingPolicy(name="Import Known Prefixes",
                       slug="import-known-prefixes",
                       weight=128),
         RoutingPolicy(name="Export Supernets",
                       slug="export-supernets",
                       weight=64),
         RoutingPolicy(
             name="Export Deaggregated v4",
             slug="export-deaggregated-v4",
             address_family=IPFamily.IPV4,
         ),
         RoutingPolicy(
             name="Export Deaggregated v6",
             slug="export-deaggregated-v6",
             address_family=IPFamily.IPV6,
         ),
     ]
     RoutingPolicy.objects.bulk_create(cls.routing_policies)
     cls.communities = [
         Community(name="Learnt from IXP",
                   slug="learnt-from-ixp",
                   value="123:1"),
         Community(
             name="Learnt from direct peer",
             slug="learnt-from-direct-peer",
             value="123:2",
         ),
         Community(
             name="Learnt from transit",
             slug="learnt-from-transit",
             value="123:3",
             type=CommunityType.INGRESS,
         ),
     ]
     Community.objects.bulk_create(cls.communities)
     AutonomousSystem.objects.create(asn=64520, name="Useless")
     cls.a_s = AutonomousSystem.objects.create(asn=64510,
                                               name="Test",
                                               ipv6_max_prefixes=100)
     cls.a_s.import_routing_policies.add(
         RoutingPolicy.objects.get(slug="import-known-prefixes"))
     cls.a_s.export_routing_policies.add(
         RoutingPolicy.objects.get(slug="export-supernets"),
         RoutingPolicy.objects.get(slug="export-deaggregated-v4"),
         RoutingPolicy.objects.get(slug="export-deaggregated-v6"),
     )
     cls.a_s.communities.add(
         Community.objects.get(slug="learnt-from-transit"))
     cls.a_s.tags.add(*cls.tags)
     cls.router = Router.objects.create(name="test",
                                        hostname="test.example.com")
     cls.ixp = InternetExchange.objects.create(
         local_autonomous_system=AutonomousSystem.objects.create(
             asn=64500, name="Autonomous System", affiliated=True),
         name="Test IXP",
         slug="test-ixp",
     )
     cls.ixp.import_routing_policies.add(
         RoutingPolicy.objects.get(slug="reject-all"))
     cls.ixp.export_routing_policies.add(
         RoutingPolicy.objects.get(slug="reject-all"))
     cls.ixp.communities.add(Community.objects.get(slug="learnt-from-ixp"))
     cls.ixp_connection = Connection.objects.create(
         vlan=10,
         internet_exchange_point=cls.ixp,
         ipv4_address="192.0.2.10",
         ipv6_address="2001:db8::a",
         router=cls.router,
     )
     cls.session6 = InternetExchangePeeringSession.objects.create(
         autonomous_system=cls.a_s,
         ixp_connection=cls.ixp_connection,
         ip_address="2001:db8::1",
         password="******",
     )
     cls.session4 = InternetExchangePeeringSession.objects.create(
         autonomous_system=cls.a_s,
         ixp_connection=cls.ixp_connection,
         ip_address="192.0.2.1",
         password="******",
     )
     cls.rs_session6 = InternetExchangePeeringSession.objects.create(
         autonomous_system=cls.a_s,
         ixp_connection=cls.ixp_connection,
         ip_address="2001:db8::ffff",
         is_route_server=True,
     )
     cls.rs_session4 = InternetExchangePeeringSession.objects.create(
         autonomous_system=cls.a_s,
         ixp_connection=cls.ixp_connection,
         ip_address="192.0.2.255",
         is_route_server=True,
     )
     cls.session6.import_routing_policies.add(
         RoutingPolicy.objects.get(slug="accept-all"))
     cls.session6.export_routing_policies.add(
         RoutingPolicy.objects.get(slug="accept-all"),
         RoutingPolicy.objects.get(slug="export-supernets"),
     )
Пример #11
0
 def setUpTestData(cls):
     Tag.objects.bulk_create([
         Tag(name="Test 1", slug="test-1", color="333333"),
         Tag(name="Test 2", slug="test-2", color="333333"),
         Tag(name="Test 3", slug="test-3", color="333333"),
     ])
Пример #12
0
def who(request):

    #try grabbing the competition-in-progress from their session
    competition = None
    try:
        competition = Competition.objects.get(id=request.session["new_comp_id"])
    except:
        return HttpResponseRedirect("/new/")

    print '### new: setting up who on comp: %s' % competition.id

    if request.method == "POST":

        reqs = competition.application_requirements()

        #completely overwrite all existing tags
        reqs.remove_all()

        #TODO NEXT: test that these tags get added & removed properly after submit

        for key in request.POST:

            print 'checking key: %s' % key
            value = request.POST.get(key)

            if value is not None:

                value = value.strip()
                if value:

                    toks = key.split("_")
                    if key.startswith("location_"):
                        reqs.locations.add(get_tag(request.POST.get(key)))
                        print 'added to location: %s' %request.POST.get(key)

                    elif key.startswith("other-requirements_"):
                        reqs.other_requirements.add(get_tag(request.POST.get(key)))
                        print 'added to other reqs: %s' %request.POST.get(key)

                    elif key.startswith("other-ideas_"):
                        reqs.business_types.add(get_tag(request.POST.get(key)))
                        print 'added to other ideas: %s' %request.POST.get(key)

                    elif key.startswith("institution_"):
                        reqs.institutions.add(get_tag(request.POST.get(key)))
                        print 'added to institution: %s' %request.POST.get(key)

        #a couple traits are special cased because they're added free-form
        #and this makes them agree with our processing of standard tags
        #if request.POST.get("institutions"):
            #list = request.POST.get("institutions").split(";")
            #custom_tag_data.append( ( list, reqs.institutions) )
        #else:
            #custom_tag_data.append( ( [], reqs.institutions ) )
#
        #if request.POST.get("locations"):
            #location_list = request.POST.get("locations").split(";")
            #custom_tag_data.append( ( location_list, reqs.locations) )
        #else:
            #custom_tag_data.append( ( [], reqs.locations ) )

        #if request.POST.get("other-requirements"):
            #other_requirement_list = request.POST.get("other-requirements").split(";")
            #custom_tag_data.append( ( other_requirement_list, reqs.other-requirements) )
        #else:
            #custom_tag_data.append( ( [], reqs.other-requirements ) )

        #for tag_names, current_tags in custom_tag_data:
            #for tag in current_tags.all():
                #current_tags.remove(tag)
#
            #for tag_name in tag_names:
                #try:
                    #current_tags.add(Tag.objects.get(name=tag_name))
                #except:
                    #tag = Tag(name=tag_name)
                    #tag.save()
                    #reqs.add(tag)

        tag_data = [ ( APPLICANT_TYPES, reqs.applicant_types),
                     ( BUSINESS_TYPES, reqs.business_types) ]

        #add/remove a couple different sets of tags
        for tag_names, current_tags in tag_data:

            print 'tag names: %s' % tag_names

            #checking each tag within each set
            for tag_name in tag_names:
                print 'testing tag name: %s' % tag_name

                #is tag desired?
                if request.POST.get(tag_name):

                    print 'turn on tag: %s' % tag_name
                    try:
                        #if tag exists on another comp, 
                        #we add it to this one also
                        current_tags.add(Tag.objects.get(name=tag_name))
                        print 'added existing tag: %s' % tag
                    except:
                        #otherwise, we'll create it
                        tag = Tag(name=tag_name)
                        tag.save()
                        current_tags.add(tag)
                        print 'added new tag: %s' % tag

        return HttpResponseRedirect("/new/phases/")

    return render_to_response("new_comp/who.html", locals())