When playing with Models and Forms…and formsets

Posted in Programming on March 23rd, 2010 by denivorium

This is definitely an off the wall post, especially after such a long silence but more on that in another post.  After beating my head against the wall trying to solve the following django exception I feel the need to post the solution in the vain hope that I will find my own words of wisdom when I run into this again.  First the exception and solution, then backstory if necessary.

MultiValueDictKeyError at [pageUrl]

Key ‘[key]‘ not found in <QueryDict: {[request.POST]}>

The solution is actually right there in the exception if you read it right.  The key is not in the POST.  If the POST is returning a form constructed from an existing model, then there’s really only one way that could happen.  Somewhere in the template system one or more model values got removed from the initial form.  In my case this was a foreign key that I added to the model during development.  Since I was displaying each form element individually in my template, my template didn’t have the new hidden value.  Therefore it wasn’t getting included in the post even though it was in the initial form created in my view.

My somewhat generic solution in this case was to include the following snippet under the custom template layout.

{% for field in form.hidden_fields %}
    {{ field.errors }}
    {{ field }}
{% endfor %}

I include the field.errors mostly because I am still heavily in development and this helps me see at a glance that I broke something, or forgot to setup a new relationship correctly, etc.

On the face of it the exception looks pretty clear, Django can’t find the key in the POST.  The part that confused me is that my form, modelformset actually, is loading correctly and is displaying the correct information.  Furthermore the missing value was a reference to a foreign key that represents my model inheritance.  So I incorrectly assumed that modelformset_factory had problems with inherited models.  It turned out that I just need to make sure I update templates anytime I change model definitions!

Tags: , , , , ,

Stalling…stalling…

Posted in General, HumanAdmin on June 26th, 2009 by denivorium

In the previous post I mentioned doing a quick sanity check on the viability of our idea.  Once we got a chance to talk with a laywer we learned an important lesson.  Legal, and legally defensible are not always the same thing!

Our idea was a good idea for a niche market which isn’t really covered yet.  The idea is a good solid idea, not some crazy scheme to part people with their money.  BUT, I will acknowledge that the market we were targeting isn’t for everyone.  In fact it isn’t for anyone that doesn’t have a large reserve of liquid capital.

We simply can not adequately control who would use our service, and if the wrong person used our service poorly, and got angry, our lawyer told us we would have a very large uphill battle in front of us.

Now that we are all setup and ready to develop, our idea has been put on hold!  This doesn’t appear to be unusual in the crazy world of startups, and we are already building and trimming a list of alternatives.

I’ll update again once things stabilize, or vaporize.

Tags:

Building an Environment

Posted in SysAdmin on June 26th, 2009 by denivorium
  • Step one, have an idea.  Or meet someone who has an idea. Check.
  • Step two, do a quick check on viability of idea. Check.
  • Step three, figure out how multiple developers in different locations can share thoughts, ideas, documentation, and of course code. Let’s take a look at this one.

Now, I *am* aware that there are many solutions available for online collaboration.  Did I mention we are looking for a free solution?  And ideally one that at some level supports the notion of agile development.

Being developers we decided on, ‘the best, most flexible’ solution since we aren’t 100% sure what exactly it is that we need.  Normally this would involve a Linux stack on a dedicated hosted server somewhere.  I suggested this route over a purely hosted solution since we aren’t sure what software we will end up using.  The obvious trade off is that we have to administer the machine(s) ourselves.

No problem, we’re pros.

Since we aren’t spending money, we did the next best thing.  We found an old machine, threw Ubuntu 8.04 server on it and promptly installed VMServer on it.  This should give us the flexibility to spin up test VM’s to our hearts content.  I would like to digress a little on OS choice, but that can wait until another day.  I will merely point out that we ended up on Ubuntu due to available options, not choice.  Now all we need is access.

Hijacking, a small piece, of one of our connections proved to be a feasible shot term solution.  A quick hop over to DynDNS scored us a development domain that is easy to pass around amongst ourselves.  Of course the fun didn’t stop there, initial testing of this new setup yielded lots of “Network Timeout pages” since the forwarding rules did not appear to function as intended.  Accessing the VMServer web page through the LAN address worked like a charm, but any attempt to access VMServer through our public IP, or domain, resulted in Network Timeouts.  A bit of troubleshooting lead back to the ‘client’ side firewalls which were a little too tight.

Next stop, the online collaboration tool.  I have previous experience with Trac and the ticketing system is annoying enough to warrant looking for alternatives.  So we decided to give Retrospectiva a shot since they boast a nice claim:

Open-source project management tool, intended to assist the collaborative aspect of work carried out by agile software development teams.

So far, I really like the look and feel, the polish level is much higher than Trac and there are built in plugins for wiki, blog, ticketing, and source browsing.  It does appear that the agile piece is a pay for plugin, but I haven’t had the chance to actually contact them about this yet.

To round out the system we are using the tried and true Subversion, although we may experiment with a git/svn combo at some point in the future to see what all the fuss is about.

This stack is definately non-trivial to setup; however, we did it all in a VM so we can deploy this over and over again with minimal configuration changes.

Now, it’s time for some development!

Tags: , , ,

VMWare server…you want multiple users?

Posted in VMWare on June 14th, 2009 by denivorium

As we have started building out our own development environment we came to a point where we wanted to allow multiple users to login to the VMWare Server 2.0.0 Administrator console.  No problem right?  Well it shouldn’t have been. We were able to add a single user, which didn’t work right.  So we deleted the user and tried again, only to run into this wonderful error message

RuntimeFault: Database temporarily unavailable or has network problems

It turns out that this problem is rather wide spread.  You can see several common themes if you go check out some of the posts on VMWare’s Community forums.  This post has both the problem and the anwser pretty well written, but I couldn’t find a nice concise solution with a good example.  So I thought I’d give it a shot.

First the underlying error from /var/logs/vmware/hostd.log

[timestamp]Throw vim.fault.DatabaseError
[timestamp]Result:
(vim.fault.DatabaseError) {
dynamicType = <unset>,
msg = “”
}

When installing VMWare Server on a Linux platform, you might think it’s a good idea to use a non-root user for the default Administrator user.  If you do then you should also ‘fix’ your /etc/vmware/hostd/authorization.xml before you get too much further. (Note: I have not confirmed that this step is really unecessary if you DO use a root user.  That is just a common theme on the forums.)

<ConfigRoot>
<ACEData id=”11″>
<ACEDataEntity>ha-folder-root</ACEDataEntity>
<ACEDataId>11</ACEDataId>
<ACEDataIsGroup>false</ACEDataIsGroup>
<ACEDataPropagate>true</ACEDataPropagate>
<ACEDataRoleId>-1</ACEDataRoleId>
<ACEDataUser>UserNameFromScript</ACEDataUser>
</ACEData>
<NextAceId>12</NextAceId>
</ConfigRoot>

Make sure to set the <NextAceId> to a value higher than your current user Id, as shown above.

Now you should be able to add permission to your main server for additional user(s).  This was all that was needed to get my system up and working properly.  There do appear to be other common issues in addition to this based on VMWare Server version, deployment system, etc.  Here’s a link to additional things you might need to try to get this working.

http://communities.vmware.com/thread/171431?start=12&tstart=0

Tags: ,

And so it begins.

Posted in General on June 9th, 2009 by denivorium

Here sits another Software Developer who thinks he can write.  This particular developer also thinks he knows about an idea that is good enough to be profitable.

So, with that in mind I will be tracking my progress through the journey of starting a company.  I plan to talk about problems we encounter, both technical and….more human issues that might arise.

Right now our ‘company’ is little more than a skeleton idea and a few guys thinking out loud.  Expect more in the comming days/weeks/months.