Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:50:51+00:00 2026-05-30T18:50:51+00:00

I’ve been reading on the ways to implement authorization (and authentication) to my newly

  • 0

I’ve been reading on the ways to implement authorization (and authentication) to my newly created Pyramid application. I keep bumping into the concept called “Resource”. I am using python-couchdb in my application and not using RDBMS at all, hence no SQLAlchemy. If I create a Product object like so:

class Product(mapping.Document):
  item = mapping.TextField()
  name = mapping.TextField()
  sizes = mapping.ListField()

Can someone please tell me if this is also called the resource? I’ve been reading the entire documentation of Pyramids, but no where does it explain the term resource in plain simple english (maybe I’m just stupid). If this is the resource, does this mean I just stick my ACL stuff in here like so:

class Product(mapping.Document):
  __acl__ = [(Allow, AUTHENTICATED, 'view')]
  item = mapping.TextField()
  name = mapping.TextField()
  sizes = mapping.ListField()

  def __getitem__(self, key):
      return <something>

If I were to also use Traversal, does this mean I add the getitem function in my python-couchdb Product class/resource?

Sorry, it’s just really confusing with all the new terms (I came from Pylons 0.9.7).

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:50:52+00:00Added an answer on May 30, 2026 at 6:50 pm

    I think the piece you are missing is the traversal part. Is Product
    the resource? Well it depends on what your traversal produces, it
    could produce products…..

    Perhaps it might be best to walk this through from the view back to
    how it gets configured when the application is created…

    Here’s a typical view.

      @view_config(context=Product, permission="view")
      def view_product(context, request):
          pass # would do stuff  
    

    So this view gets called when context is an instance of Product. AND
    if the acl attribute of that instance has the “view”
    permission. So how would an instance of Product become context?

    This is where the magic of traversal comes in. The very logic of
    traversal is simply a dictionary of dictionaries. So one way that this
    could work for you is if you had a url like

    /product/1
    

    Somehow, some resource needs to be traversed by the segments of the
    url to determine a context so that a view can be determined. What if
    we had something like…

      class ProductContainer(object):
          """
          container = ProductContainer()
          container[1]
          >>> <Product(1)>
          """
          def __init__(self, request, name="product", parent=None):
              self.__name__ = name
              self.__parent__ = parent
              self._request = request
    
          def __getitem__(self, key):
              p = db.get_product(id=key)
    
              if not p:
                  raise KeyError(key)
              else:
                  p.__acl__ = [(Allow, Everyone,"view")]
                  p.__name__ = key
                  p.__parent__ = self
                  return p
    

    Now this is covered in the documentation and I’m attempting to boil it
    down to the basics you need to know. The ProductContainer is an object
    that behaves like a dictionary. The “name” and “parent”
    attributes are required by pyramid in order for the url generation
    methods to work right.

    So now we have a resource that can be traversed. How do we tell
    pyramid to traverse ProductContainer? We do that through the
    Configurator object.

      config = Configurator()
      config.add_route(name="product",
                       path="/product/*traverse",
                       factory=ProductContainer)
      config.scan()
      application = config.make_wsgi_app()
    

    The factory parameter expects a callable and it hands it the current
    request. It just so happens that ProductContainer.init will do
    that just fine.

    This might seem a little much for such a simple example, but hopefully
    you can imagine the possibilities. This pattern allows for very
    granular permission models.

    If you don’t want/need a very granular permission model such as row
    level acl’s you probably don’t need traversal, instead you can use
    routes with a single root factory.

      class RootFactory(object):
          def __init__(self, request):
              self._request = request
              self.__acl__ = [(Allow, Everyone, "view")]  # todo: add more acls
    
    
      @view_config(permission="view", route_name="orders")
      def view_product(context, request):
          order_id, product_id = request.matchdict["order_id"], request.matchdict["product_id"]
          pass # do what you need to with the input, the security check already happened
    
      config = Configurator(root_factory=RootFactory)
    
      config.add_route(name="orders",
                       path="/order/{order_id}/products/{product_id}")
    
      config.scan()
      application = config.make_wsgi_app()
    

    note: I did the code example from memory, obviously you need all the necessary imports etc. in other words this isn’t going to work as a copy/paste

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.