Skip to content

Commit

Permalink
More documentation per #83
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Feb 7, 2016
1 parent 7ec6ff0 commit ec8ef82
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions mongonaut/forms/form_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


def get_document_unicode(document):
"""Safely converts MongoDB document strings to unicode."""
try:
return document.__unicode__()
except AttributeError:
Expand Down
10 changes: 8 additions & 2 deletions mongonaut/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, form_post_data=None, *args, **kwargs):
super(MongoModelForm, self).__init__(*args, **kwargs)

def set_fields(self):
"""Sets existing data to form fields."""

# Get dictionary map of current model
if self.is_initialized:
Expand All @@ -44,8 +45,10 @@ def set_fields(self):
self.set_form_fields(form_field_dict)

def set_post_data(self):
# Need to set form data so that validation on all post data occurs and
# places newly entered form data on the form object.
"""
Need to set form data so that validation on all post data occurs and
places newly entered form data on the form object.
"""
self.form.data = self.post_data_dict

# Specifically adding list field keys to the form so they are included
Expand All @@ -62,6 +65,9 @@ def set_post_data(self):
self.form.fields.update({key: field})

def get_form(self):
"""
Generate the form for view.
"""
self.set_fields()
if self.post_data_dict is not None:
self.set_post_data()
Expand Down
2 changes: 2 additions & 0 deletions mongonaut/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


def get_widget(model_field, disabled=False):
"""Choose which widget to display for a field."""

attrs = get_attrs(model_field, disabled)

Expand All @@ -42,6 +43,7 @@ def get_widget(model_field, disabled=False):


def get_attrs(model_field, disabled=False):
"""Set attributes on the display widget."""
attrs = {}
attrs['class'] = 'span6 xlarge'
if disabled or isinstance(model_field, ObjectIdField):
Expand Down
1 change: 1 addition & 0 deletions mongonaut/templatetags/mongonaut_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@register.simple_tag()
def get_document_value(document, key):
"""Returns the display value of a field for a particular MongoDB document."""
value = getattr(document, key)
if isinstance(value, ObjectId):
return value
Expand Down
2 changes: 1 addition & 1 deletion mongonaut/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get_context_data(self, **kwargs):
return context

def post(self, request, *args, **kwargs):
"""Creates new mongoengine records/"""
"""Creates new mongoengine records."""
# TODO - make sure to check the rights of the poster
#self.get_queryset() # TODO - write something that grabs the document class better
form_class = self.get_form_class()
Expand Down

0 comments on commit ec8ef82

Please sign in to comment.