Search Results

Search found 9 results on 1 pages for 'djangoforms'.

Page 1/1 | 1 

  • How much customization can you do with djangoforms.ModelForm?

    - by Randell
    I've just started playing with The Django Form Validation Framework on Google App Engine (from google.appengine.ext.db import djangoforms) and I got stuck googling how to customize forms using it. I was wondering whether the following are possible using the package: Add help texts beside/below input/select fields and textareas (e.g. "This field is required", "Example: qwerty123") Add/modify attributes for the input/select fields and textareas (e.g. adding the following attributes: class, id, name, maxlength, minlength, etc.) Add custom validations like checking whether a particular field should be unique or checking a value against a regular expression Modify the error messages Add another column to the table generated by the form Also note that djangoforms.ModelForm is different from django.forms.Form.

    Read the article

  • How do I use a ListProperty(users.user) in a djangoforms.ModelForm on Google AppEngine?

    - by Gabriel
    I have been looking around a bit for info on how to do this. Essentially I have a Model: class SharableUserAsset(db.Model): name = StringProperty() users = ListProperty(users.User) My questions are: What is the best way to associate users to this value where they are not authenticated, visa vi invite from contacts list etc.? Is there a reasonable way to present a list control easily in a djangoforms.ModelForm? Once a user logs in I want to be able to check if that user is in the list for any number of SharableUserAsset class "records", how do I do that? Does user evaluate as a match to an email address or is there a way to look up a valid user against an email address?

    Read the article

  • GAE formpreview

    - by Niklas R
    I'm trying to enable form preview with Google App Engine. Getting the following error message I suspect being mistaken somewhere: ... handler = handler_class() TypeError: __call__() takes at least 2 arguments (1 given) Can you tell what's wrong with my attempt? Here is some of the code. from django.contrib.formtools.preview import FormPreview class AFormPreview(FormPreview): def done(self, request, cleaned_data): # Do something with the cleaned_data, then redirect # to a "success" page. self.response.out.write('Done!') class AForm(djangoforms.ModelForm): text = forms.CharField(widget=forms.Textarea(attrs={'rows':'11','cols':'70','class':'foo'}),label=_("content").capitalize()) def clean(self): cleaned_data = self.clean_data name = cleaned_data.get("name") if not name: raise forms.ValidationError("No name.") # Always return the full collection of cleaned data. return cleaned_data class Meta: model = A fields = ['category','currency','price','title','phonenumber','postaladress','name','text','email'] #change the order ... ('/aformpreview/([^/]*)', AFormPreview(AForm)), UPDATE: Here's a complete app where the preview is not working. Any ideas are most welcome: import cgi from google.appengine.api import users from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.db import djangoforms class Item(db.Model): name = db.StringProperty() quantity = db.IntegerProperty(default=1) target_price = db.FloatProperty() priority = db.StringProperty(default='Medium',choices=[ 'High', 'Medium', 'Low']) entry_time = db.DateTimeProperty(auto_now_add=True) added_by = db.UserProperty() class ItemForm(djangoforms.ModelForm): class Meta: model = Item exclude = ['added_by'] from django.contrib.formtools.preview import FormPreview class ItemFormPreview(FormPreview): def done(self, request, cleaned_data): # Do something with the cleaned_data, then redirect # to a "success" page. return HttpResponseRedirect('/') class MainPage(webapp.RequestHandler): def get(self): self.response.out.write('<html><body>' '<form method="POST" ' 'action="/">' '<table>') # This generates our shopping list form and writes it in the response self.response.out.write(ItemForm()) self.response.out.write('</table>' '<input type="submit">' '</form></body></html>') def post(self): data = ItemForm(data=self.request.POST) if data.is_valid(): # Save the data, and redirect to the view page entity = data.save(commit=False) entity.added_by = users.get_current_user() entity.put() self.redirect('/items.html') else: # Reprint the form self.response.out.write('<html><body>' '<form method="POST" ' 'action="/">' '<table>') self.response.out.write(data) self.response.out.write('</table>' '<input type="submit">' '</form></body></html>') class ItemPage(webapp.RequestHandler): def get(self): query = db.GqlQuery("SELECT * FROM Item ORDER BY name") for item in query: self.response.out.write('<a href="/edit?id=%d">Edit</a> - ' % item.key().id()) self.response.out.write("%s - Need to buy %d, cost $%0.2f each<br>" % (item.name, item.quantity, item.target_price)) class EditPage(webapp.RequestHandler): def get(self): id = int(self.request.get('id')) item = Item.get(db.Key.from_path('Item', id)) self.response.out.write('<html><body>' '<form method="POST" ' 'action="/edit">' '<table>') self.response.out.write(ItemForm(instance=item)) self.response.out.write('</table>' '<input type="hidden" name="_id" value="%s">' '<input type="submit">' '</form></body></html>' % id) def post(self): id = int(self.request.get('_id')) item = Item.get(db.Key.from_path('Item', id)) data = ItemForm(data=self.request.POST, instance=item) if data.is_valid(): # Save the data, and redirect to the view page entity = data.save(commit=False) entity.added_by = users.get_current_user() entity.put() self.redirect('/items.html') else: # Reprint the form self.response.out.write('<html><body>' '<form method="POST" ' 'action="/edit">' '<table>') self.response.out.write(data) self.response.out.write('</table>' '<input type="hidden" name="_id" value="%s">' '<input type="submit">' '</form></body></html>' % id) def main(): application = webapp.WSGIApplication( [('/', MainPage), ('/edit', EditPage), ('/items.html', ItemPage), ('/itemformpreview', ItemFormPreview(ItemForm)), ], debug=True) run_wsgi_app(application)

    Read the article

  • Google App Engine + Form Validation

    - by Iwona
    Hi, I would like to do google app engine form validation but I dont know how to do it? I tried like this: from google.appengine.ext.db import djangoforms from django import newforms as forms class SurveyForm(forms.Form): occupations_choices = ( ('1', ""), ('2', "Undergraduate student"), ('3', "Postgraduate student (MSc)"), ('4', "Postgraduate student (PhD)"), ('5', "Lab assistant"), ('6', "Technician"), ('7', "Lecturer"), ('8', "Other" ) ) howreach_choices = ( ('1', ""), ('2', "Typed the URL directly"), ('3', "Site is bookmarked"), ('4', "A search engine"), ('5', "A link from another site"), ('6', "From a book"), ('7', "Other") ) boxes_choices = ( ("des", "Website Design"), ("svr", "Web Server Administration"), ("com", "Electronic Commerce"), ("mkt", "Web Marketing/Advertising"), ("edu", "Web-Related Education") ) name = forms.CharField(label='Name', max_length=100, required=True) email = forms.EmailField(label='Your Email Address:') occupations = forms.ChoiceField(choices=occupations_choices, label='What is your occupation?') howreach = forms.ChoiceField(choices=howreach_choices, label='How did you reach this site?') # radio buttons 1-5 rating = forms.ChoiceField(choices=range(1,6), label='What is your occupation?', widget=forms.RadioSelect) boxes = forms.ChoiceField(choices=boxes_choices, label='Are you involved in any of the following? (check all that apply):', widget=forms.CheckboxInput) comment = forms.CharField(widget=forms.Textarea, required=False) And I wanted to display it like this: template_values = { 'url' : url, 'url_linktext' : url_linktext, 'userName' : userName, 'item1' : SurveyForm() } And I have this error message: Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp_init_.py", line 515, in call handler.get(*groups) File "C:\Program Files\Google\google_appengine\demos\b00213576\main.py", line 144, in get self.response.out.write(template.render(path, template_values)) File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 143, in render return t.render(Context(template_dict)) File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 183, in wrap_render return orig_render(context) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 168, in render return self.nodelist.render(context) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 705, in render bits.append(self.render_node(node, context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 718, in render_node return(node.render(context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template\defaulttags.py", line 209, in render return self.nodelist_true.render(context) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 705, in render bits.append(self.render_node(node, context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 718, in render_node return(node.render(context)) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 768, in render return self.encode_output(output) File "C:\Program Files\Google\google_appengine\lib\django\django\template_init_.py", line 757, in encode_output return str(output) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\util.py", line 26, in str return self.unicode().encode(settings.DEFAULT_CHARSET) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 73, in unicode return self.as_table() File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 144, in as_table return self._html_output(u'%(label)s%(errors)s%(field)s%(help_text)s', u'%s', '', u'%s', False) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 129, in _html_output output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text}) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\forms.py", line 232, in unicode value = value.str() File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\util.py", line 26, in str return self.unicode().encode(settings.DEFAULT_CHARSET) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\widgets.py", line 246, in unicode return u'\n%s\n' % u'\n'.join([u'%s' % w for w in self]) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\widgets.py", line 238, in iter yield RadioInput(self.name, self.value, self.attrs.copy(), choice, i) File "C:\Program Files\Google\google_appengine\lib\django\django\newforms\widgets.py", line 212, in init self.choice_value = smart_unicode(choice[0]) TypeError: 'int' object is unsubscriptable Do You have any idea how I can do this validation in different case? I have tried to do it using this kind of: class ItemUserAnswer(djangoforms.ModelForm): class Meta: model = UserAnswer But I dont know how to add extra labels to this form and it is displayed in one line. Do You have any suggestions? Thanks a lot as it making me crazy why it is still not working:/

    Read the article

  • Valid Dates in AppEngine forms (Beginner)

    - by codingJoe
    In AppEngine, I have a form that prompts a user for a date. The problem is that when the clicks enter there is an error: "Enter a Valid Date" How do I make my Form accept (for example) %d-%b-%Y as the date format? Is there a more elegant way to accomplish this? # Model and Forms class Task(db.Model): name=db.StringProperty() due=db.DateProperty() class TaskForm(djangoforms.ModelForm): class Meta: model = Task # my get function has the following. # using "now" for example. Could just as well be next Friday. tmStart = datetime.now() form = TaskForm(initial={'due': tmStart.strftime("%d-%b-%Y")}) template_values = {'form': form }

    Read the article

  • Datastore query outputting for Django form instance

    - by Jelle
    Hello! I'm using google appengine and Django. I'm using de djangoforms module and wanted to specify the form instance with the information that comes from the query below. userquery = db.GqlQuery("SELECT * FROM User WHERE googleaccount = :1", users.get_current_user()) form = forms.AccountForm(data=request.POST or None,instance=?????) I've found a snippet in a sample app that does this trick, but I can't modify it to work with the query I need. gift = User.get(db.Key.from_path(User.kind(), int(gift_id))) if gift is None: return http.HttpResponseNotFound('No gift exists with that key (%r)' % gift_id) form = RegisterForm(data=request.POST or None, instance=gift) Could anyone help me?

    Read the article

  • How to load a database of countries in a web application

    - by lance_klusener
    Hello All, I am new to web application development, so sorry in advance if this question is too basic. The following are the details of the question: A] Platform being used -- google app engine with python, django. B] Tutorial link being used -- http://code.google.com/appengine/articles/djangoforms.html C] Question: In the application i am building, there is a drop down box which allows the user to select their country. Since the list of countries is above 200, i want to construct a database of the countries before the application loads. Once this application is deployed, i dont want the database to get re-loaded again, since the entries are constant for all the users. How does one achieve this ? thanks, Lance.

    Read the article

  • Google App Engine django model form does not pick up BlobProperty

    - by Wes
    I have the following model: class Image(db.Model): auction = db.ReferenceProperty(Auction) image = db.BlobProperty() thumb = db.BlobProperty() caption = db.StringProperty() item_to_tag = db.StringProperty() And the following form: class ImageForm(djangoforms.ModelForm): class Meta: model = Image When I call ImageForm(), only the non-Blob fields are created, like this: <tr><th><label for="id_auction">Auction:</label></th><td><select name="auction" id="id_auction"> <option value="" selected="selected">---------</option> <option value="ahRoYXJ0bWFuYXVjdGlvbmVlcmluZ3INCxIHQXVjdGlvbhgKDA">2010-06-19 11:00:00</option> </select></td></tr> <tr><th><label for="id_caption">Caption:</label></th><td><input type="text" name="caption" id="id_caption" /></td></tr> <tr><th><label for="id_item_to_tag">Item to tag:</label></th><td><input type="text" name="item_to_tag" id="id_item_to_tag" /></td></tr> I want the Blob fields to be included in the form as well (as file inputs). What am I doing wrong?

    Read the article

  • Query distinct list of choices for Django form with App Engine Datastore

    - by Brian
    I've been trying to figure this out for hours across a couple of days, and can not get it to work. I've been everywhere. I'll continue trying to figure it out, but was hoping for a quicker solution. I'm using App Engine datastore + Django. Using a query in a view and custom forms, I was able to get a list to the form but then I was not able to post. I have been trying to figure out how to dynamically add the choices as part of the Django form... I've tried various ways with no success. Help! Below are the two models. I'd like to get a distinct list of address_id to show in the location field in InfoForm. This fields could (and maybe should) be named the same, but I thought it'd be easier if they were named different. class Info(db.Model): user = db.UserProperty() location = db.StringProperty() info = db.StringProperty() created = db.DateTimeProperty(auto_now_add=True) modified = db.DateTimeProperty(auto_now=True) class Locations(db.Model): user = db.UserProperty() address_id = db.StringProperty() address = db.StringProperty() class InfoForm(djangoforms.ModelForm): info = forms.ChoiceField(choices=INFO_CHOICES) location = forms.ChoiceField() class Meta: model = Info exclude = ['user','created','modified']

    Read the article

1