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

  • SEARCH
  • Home
  • 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 6759081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:53:23+00:00 2026-05-26T13:53:23+00:00

I’m having problems creating custom forms in pyramid_formalchemy. I suspect there is a bug

  • 0

I’m having problems creating custom forms in pyramid_formalchemy. I suspect there is a bug in the package and wanted to confirm I’m not missing anything. My setup looks like this:

def includeme(config):
    config.include('pyramid_formalchemy')
    # Adding the jquery libraries
    config.include('fa.jquery')
    # Adding the package specific routes
    config.include('myapp.web.formalchemy.faroutes')

    config.formalchemy_admin('admin',
                             models=[User],
                             forms=faforms,
                             session_factory=session,
                             view='fa.jquery.pyramid.ModelView',
                             factory='myapp.model.RootFactory')

    config.formalchemy_model('user',
                             model='myapp.model.user.User',
                             session_factory=session,
                             view='fa.jquery.pyramid.ModelView',
                             factory='myapp.model.RootFactory')

faforms is a module containing my custom forms:

from myapp.model.user import User

from formalchemy import FieldSet
from formalchemy import Grid

class UserFieldSet(FieldSet):
    def __init__(self):
        FieldSet.__init__(self, User)
        self.configure()

class UserGrid(Grid):
    def __init__(self):
        Grid.__init__(self, User)
        self.configure()

If I comment out the two classes above, formalchemy works fine. I can view Users and I can edit them.

When I put the two classes in I run into problems. The problem is pyramid_formalchemy grabs UserGrid and UserFieldSet from the module’s namespace and then tries to use them as if they were instantiated classes. This breaks things. On the other hand if pyramid_formalchemy doesn’t find the classes in will dynamically create the classes AND instantiate them. I believe the offending code is in pyramid_formalchemy/views.py, line 236 starting at the get_grid() function:

def get_grid(self):
    """return a Grid object"""
    request = self.request
    model_name = request.model_name
    form_name = '%sGrid' % model_name
    if hasattr(request.forms, form_name):
        g = getattr(request.forms, form_name)  <-- g is a class type not an
        g.engine = g.engine or self.engine     <-- instance!
        g.readonly = True                      <-- why is it not instantiated?
        g._request = self.request
        self.update_grid(g)
        return g
    model = self.context.get_model()           <-- UserGrid not found in faforms 
    grid = self.grid_class(model)              <-- module.
    grid.engine = self.engine                  <-- so a Grid is instantiated
    if not isinstance(request.forms, list):
        # add default grid to form module eg: caching
        setattr(request.forms, form_name, grid)
    grid = grid.copy()
    grid._request = self.request
    self.update_grid(grid)
    return grid

Here you can see if the matching grid (or fieldset) is not found it will be instantiated, but if it is found the class type will be used directly, but not actually instantiated.

Any thoughts here? Am I setting something up wrong?

Basically I’m using CSRF tokens so I need to customize my forms to grab the tokens from the session.

Thanks.

  • 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-26T13:53:24+00:00Added an answer on May 26, 2026 at 1:53 pm

    pyramid_formalchemy makes certain, mostly undocumented assumptions, about how you setup your forms file. Here are the gotchas I hit and worked around…

    1. If you have a model User for example, then you will need to have a FieldSet called UserFieldSet.

    2. UserFieldSet must be an instance and not a class.

    3. Be careful on your imports or you will break assumptions pyramid_formalchemy is making. If you have a model class User, import User’s package, but not the User class itself. Then reference the class by prefixing the reference with the package name.

    Below is a working example using the 3 points above.

    from myapp.model import user
    
    from formalchemy import Field
    from formalchemy import FieldSet
    from formalchemy import Grid
    
    UserFieldSet = FieldSet(user.User)
    UserFieldSet.configure()
    
    UserGrid = Grid(user.User)
    UserGrid.configure()
    

    You can also post to the formalchemy group for more info.

    • 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
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.