Search Results

Search found 5 results on 1 pages for 'codingjoe'.

Page 1/1 | 1 

  • 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

  • Difficulty adding widgets to django form.

    - by codingJoe
    I have a django app that tracks activities that can benefit a classroom. Using the django examples, I was able to build a form to enter this data. But when I try to add widgets to that form, things get tricky. What I want is a calendar widget that lets the user enter the 'activity_date' field using a widget. If I use Admin interface. The AdminDateWidget works fine. however. This particular user isn't allowed access to the admin interface so I need a different way to present this widget. Also I couldn't figure out how to make the bring the admin widget over into non-admin pages. So I tried a custom widget. This is the first custom widget I've built, so I'm not quite sure what is supposed to be going on here. Any Expert Advice? How do I get my date widget to work? # The Model class Activity(models.Model): activity_date = models.DateField() activity_type = models.CharField(max_length=50, choices=ACTIVITY_TYPES) activity_description = models.CharField(max_length=200) activity_duration= models.DecimalField(decimal_places=2, max_digits=4) est_attendance = models.IntegerField("Estimated attendance") # The Form class ActivityForm(forms.ModelForm): # The following line causes lockup if enabled. # With the DateTimeWidget removed, the form functions correctly except that there is no widget. #activity_date = forms.DateField(label=_('Date'), widget=DateTimeWidget) ##!!! Point of Error !!! class Meta: model = Activity fields = ('activity_date', 'activity_type', 'activity_description', 'activity_duration', 'est_attendance') def __init__(self, *args, **kwargs): super(ActivityForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) edit_aid = kwargs.get('edit_aid', False) # On a different approach, the following also didn't work. #self.fields['activity_date'].widget = widgets.AdminDateWidget() # The Widget # Example referenced: http://djangosnippets.org/snippets/391/ calbtn = u""" <button id="calendar-trigger">...</button> <img src="%s/site_media/images/icon_calendar.gif" alt="calendar" id="%s_btn" style="cursor: pointer; border: 1px solid #8888aa;" title="Select date and time" onmouseover="this.style.background='#444444';" onmouseout="this.style.background=''" /> <script type="text/javascript"> Calendar.setup({ trigger : "calendar-trigger", inputField : "%s" }); </script>""" class DateTimeWidget(forms.widgets.TextInput): dformat = '%Y-%m-%d %H:%M' def render(self, name, value, attrs=None): print "DTWgt render name=%s, value=%s" % name, value if value is None: value = '' final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) if value != '': try: final_attrs['value'] = \ force_unicode(value.strftime(self.dformat)) except: final_attrs['value'] = \ force_unicode(value) if not final_attrs.has_key('id'): final_attrs['id'] = u'%s_id' % (name) id = final_attrs['id'] jsdformat = self.dformat #.replace('%', '%%') cal = calbtn % (settings.MEDIA_URL, id, id, jsdformat, id) a = u'<input%s />%s' % (forms.util.flatatt(final_attrs), cal) print "render return %s " % a return mark_safe(a) def value_from_datadict(self, data, files, name): print "DTWgt value_from_datadict" dtf = forms.fields.DEFAULT_DATETIME_INPUT_FORMATS empty_values = forms.fields.EMPTY_VALUES value = data.get(name, None) if value in empty_values: return None if isinstance(value, datetime.datetime): return value if isinstance(value, datetime.date): return datetime.datetime(value.year, value.month, value.day) for format in dtf: try: return datetime.datetime(*time.strptime(value, format)[:6]) except ValueError: continue return None

    Read the article

  • Using Page anchors on Google AppEngine?

    - by codingJoe
    I would like to have AppEngine render an html page that auto scrolls to an html anchor point. I'm not how and where to put the that type of instruction. template_values = { 'foo' : 'foo', 'bar': 'bar', 'anchor' : '#MyPageAnchor' # ?? Something like this... } path = os.path.join(os.path.dirname(__file__), fileName) self.response.out.write(template.render(path, template_values)) Is this possible? How do I accomplish this?

    Read the article

  • Django json serialization problem

    - by codingJoe
    I am having difficulty serializing a django object. The problem is that there are foreign keys. I want the serialization to have data from the referenced object, not just the index. For example, I would like the sponsor data field to say "sponsor.last_name, sponsor.first_name" rather than "13". How can I fix my serialization? json data: {"totalCount":"2","activities":[{"pk": 1, "model": "app.activity", "fields": {"activity_date": "2010-12-20", "description": "my activity", "sponsor": 13, "location": 1, .... model code: class Activity(models.Model): activity_date = models.DateField() description = models.CharField(max_length=200) sponsor = models.ForeignKey(Sponsor) location = models.ForeignKey(Location) class Sponsor(models.Model): last_name = models.CharField(max_length=20) first_name= models.CharField(max_length=20) specialty = models.CharField(max_length=100) class Location(models.Model): location_num = models.IntegerField(primary_key=True) location_name = models.CharField(max_length=100) def activityJSON(request): activities = Activity.objects.all() total = activities.count() activities_json = serializers.serialize("json", activities) data = "{\"totalCount\":\"%s\",\"activities\":%s}" % (total, activities_json) return HttpResponse(data, mimetype="application/json")

    Read the article

  • How to display and change an icon inside a python Tk Frame

    - by codingJoe
    I have a python Tkinter Frame that displays several fields. I want to also add an red/yellow/green icon that will display the status of an external device. The icon is loaded from a file called ICON_LED_RED.ico. How do I display the icon in my frame? How do I change the icon at runtime? for example replace BitmapImage('RED.ico') with BitmapImage('GREEN.ico') class Application(Frame): def init(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): # ...other frame code.. works just fine. self.OKBTN = Button(self) self.OKBTN["text"] = "OK" self.OKBTN["fg"] = "red" self.OKBTN["command"] = self.ok_btn_func self.OKBTN.pack({"side": "left"}) # when I add the following the frame window is not visible # The process is locked up such that I have to do a kill -9 self.statusFrame = Frame(self, bd=2, relief=RIDGE) Label(self.statusFrame, text='Status:').pack(side=LEFT, padx=5) self.statIcon = BitmapImage('data/ICON_LED_RED.ico') Label (self.statusFrame, image=self.statIcon ).grid() self.statusFrame.pack(expand=1, fill=X, pady=10, padx=5)

    Read the article

1