# HG changeset patch # User Sverre Rabbelier # Date 1223826739 0 # Node ID 972d28056d9d2901b7098d7c1efefd33e393171e # Parent 812abb9a7e3b99bf205afd3fd9253412ddde06d4 Minor style and import fixes Incorperated changes as suggested by Todd and Pawel. Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed diff -r 812abb9a7e3b -r 972d28056d9d app/soc/logic/model.py --- a/app/soc/logic/model.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/logic/model.py Sun Oct 12 15:52:19 2008 +0000 @@ -32,6 +32,7 @@ def getFullClassName(cls): """Returns fully-qualified module.class name string.""" + return '%s.%s' % (cls.__module__, cls.__name__) @@ -46,6 +47,7 @@ default is None, in which case the inheritance_line property is *not* tested by the returned query string """ + query_str_parts = ['SELECT * FROM ', base_class.__name__] if derived_class: @@ -64,6 +66,7 @@ default is None, in which case no ORDER BY clause is placed in the query string """ + query_str_parts = [ buildTypedQueryString(base_class, derived_class=derived_class)] @@ -82,6 +85,7 @@ offset: optional offset in entities list which defines first entity to return; default is zero (first entity) """ + query_string = buildOrderedQueryString( base_class, derived_class=derived_class, order_by=order_by) @@ -109,6 +113,7 @@ possibly None if query had no results for the supplied field that was used. """ + # SELECT * FROM base_class WHERE inheritance_line = 'derived_class' typed_query_str = buildTypedQueryString( base_class, derived_class=derived_class) @@ -146,6 +151,7 @@ None if there are no nearest entities or the offset of the beginning of the range cannot be found for some reason """ + # find entity "nearest" to supplied fields nearest_entities, field = getNearestEntities( base_class, fields_to_try, derived_class=derived_class) @@ -203,15 +209,16 @@ - Args: - key_name: key name of entity """ + return self._model.get_by_key_name(key_name) def getFromFields(self, **kwargs): """Returns the entity for a given link name, or None if not found. Args: - link_name: a link name of the entity that uniquely identifies it + **kwargs: the fields of the entity that uniquely identifies it """ - # lookup by Sponsor key name + key_name = self.getKeyNameForFields(**kwargs) if key_name: @@ -222,19 +229,20 @@ return entity def getIfFields(self, **kwargs): - """Returns Sponsor entity for supplied link name if one exists. + """Returns entity for supplied link name if one exists. Args: - link_name: a link name of the Sponsor that uniquely identifies it + **kwargs: the fields of the entity that uniquely identifies it Returns: - * None if link name is false. - * Sponsor entity for supplied link_name + * None if a field is false. + * Eentity for supplied fields Raises: out_of_band.ErrorResponse if link name is not false, but no Sponsor entity with the supplied link name exists in the Datastore """ + if not all(kwargs.values()): # exit without error, to let view know that link_name was not supplied return None @@ -248,18 +256,19 @@ fields = [] for key, value in kwargs.iteritems(): - fields.extend('"%s" is "%s"' % (key, value)) + fields.extend('"%s" is "%s" ' % (key, value)) # else: fields were supplied, but there is no Entity that has it raise out_of_band.ErrorResponse( 'There is no %s with %s.' % (self._name, ''.join(fields)), status=404) def getKeyNameForFields(self, **kwargs): - """Return a Datastore key_name for a Sponsor from the link name. + """Return a Datastore key_name for a Entity from the specified fields. Args: - link_name: a link name of the entity that uniquely identifies it + **kwargs: the fields of the entity that uniquely identifies it """ + if not all(kwargs.values()): return None @@ -273,6 +282,7 @@ offset: optional offset in entities list which defines first entity to return; default is zero (first entity) """ + query = self._model.all() return query.fetch(limit, offset) @@ -287,6 +297,7 @@ Returns: the original model entity with any supplied properties changed """ + def update(): return self._unsafeUpdateModelProperties(model, **model_properties) @@ -297,6 +308,7 @@ Like updateModelProperties(), but not run within a transaction. """ + properties = model.properties() for prop in properties.values(): @@ -315,9 +327,8 @@ """Update existing entity, or create new one with supplied properties. Args: - link_name: a link_name of the entity that uniquely identifies it - **properties: keyword arguments that correspond to entity - properties and their values + properties: dictionairy with entity properties and their values + key_name: the key_name of the entity that uniquely identifies it Returns: the entity corresponding to the key_name, with any supplied @@ -351,5 +362,6 @@ Args: entity: an existing entity in datastore """ + entity.delete() - + diff -r 812abb9a7e3b -r 972d28056d9d app/soc/logic/site/id_user.py --- a/app/soc/logic/site/id_user.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/logic/site/id_user.py Sun Oct 12 15:52:19 2008 +0000 @@ -81,12 +81,11 @@ # User is definitely *not* a Developer return False - if (not id or id == current_id) and users.is_current_user_admin(): + if ((not id) or (id == current_id)) and users.is_current_user_admin(): # no id supplied, or current logged-in user, and that user is in the # Administration->Developers list in the App Engine console return True - # If no id is specified, default to logged in user if not id: id = current_id diff -r 812abb9a7e3b -r 972d28056d9d app/soc/logic/site/map.py --- a/app/soc/logic/site/map.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/logic/site/map.py Sun Oct 12 15:52:19 2008 +0000 @@ -30,9 +30,7 @@ from django.conf.urls import defaults from django.utils import datastructures -import soc.logic -import soc.logic.path_link_name - +from soc.logic import path_link_name from soc.logic.site import page @@ -84,7 +82,7 @@ user_edit = page.Page( page.Url( - r'^user/profile/%s$' % soc.logic.path_link_name.LINKNAME_ARG_PATTERN, + r'^user/profile/%s$' % path_link_name.LINKNAME_ARG_PATTERN, 'soc.views.user.profile.edit'), 'User: Modify Existing User Profile', parent=user_signout) @@ -125,7 +123,7 @@ site_user_edit = page.Page( page.Url( - r'^site/user/profile/%s$' % soc.logic.path_link_name.LINKNAME_ARG_PATTERN, + r'^site/user/profile/%s$' % path_link_name.LINKNAME_ARG_PATTERN, 'soc.views.site.user.profile.edit'), 'Site: Modify Existing User Profile', short_name='Modify Site User', @@ -142,7 +140,7 @@ # Document views docs_show = page.Page( page.Url( - r'^docs/show/%s$' % soc.logic.path_link_name.PATH_LINKNAME_ARGS_PATTERN, + r'^docs/show/%s$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, 'soc.views.docs.show.public'), 'Show Document', parent=home) @@ -158,7 +156,7 @@ site_docs_edit = page.Page( page.Url( - r'^site/docs/edit/%s$' % soc.logic.path_link_name.PATH_LINKNAME_ARGS_PATTERN, + r'^site/docs/edit/%s$' % path_link_name.PATH_LINKNAME_ARGS_PATTERN, 'soc.views.site.docs.edit.edit'), 'Site: Modify Existing Document', short_name='Modify Site Document', @@ -175,7 +173,7 @@ # Sponsor Group public view sponsor_profile = page.Page( page.Url( - r'^sponsor/profile/%s' % soc.logic.path_link_name.LINKNAME_ARG_PATTERN, + r'^sponsor/profile/%s' % path_link_name.LINKNAME_ARG_PATTERN, 'soc.views.sponsor.profile.public'), 'Public Profile', parent=home) @@ -191,7 +189,7 @@ site_sponsor_delete = page.Page( page.Url( - r'^site/sponsor/profile/%s/delete$' % soc.logic.path_link_name.LINKNAME_ARG_PATTERN, + r'^site/sponsor/profile/%s/delete$' % path_link_name.LINKNAME_ARG_PATTERN, 'soc.views.site.sponsor.profile.delete'), 'Site: Delete Existing Sponsor', short_name='Delete Site Sponsor', @@ -199,7 +197,7 @@ site_sponsor_edit = page.Page( page.Url( - r'^site/sponsor/profile/%s' % soc.logic.path_link_name.LINKNAME_ARG_PATTERN, + r'^site/sponsor/profile/%s' % path_link_name.LINKNAME_ARG_PATTERN, 'soc.views.site.sponsor.profile.edit'), 'Site: Modify Existing Sponsor', short_name='Modify Site Sponsor', diff -r 812abb9a7e3b -r 972d28056d9d app/soc/views/site/docs/edit.py --- a/app/soc/views/site/docs/edit.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/views/site/docs/edit.py Sun Oct 12 15:52:19 2008 +0000 @@ -76,6 +76,7 @@ ugettext_lazy('Document saved.'), ) + def getDocForForm(form): """Extracts doc fields from a form and creates a new doc from it """ @@ -103,6 +104,7 @@ return doc + def edit(request, partial_path=None, link_name=None, template=DEF_SITE_DOCS_EDIT_TMPL): """View for a Developer to modify the properties of a Document Model entity. diff -r 812abb9a7e3b -r 972d28056d9d app/soc/views/site/home.py --- a/app/soc/views/site/home.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/views/site/home.py Sun Oct 12 15:52:19 2008 +0000 @@ -154,18 +154,16 @@ logged_in_id = users.get_current_user() user = soc.logic.user_logic.getFromFields(email=logged_in_id) - properties = {} - properties['title'] = document_form.cleaned_data.get('title') - properties['short_name'] = document_form.cleaned_data.get('short_name') - properties['abstract'] = document_form.cleaned_data.get('abstract') - properties['content'] = document_form.cleaned_data.get('content') - properties['link_name'] = link_name - properties['partial_path'] = partial_path - properties['id'] = logged_in_id - properties['user'] = user - - #bla = dir(logged_in_id) - #raise self + properties = { + title : document_form.cleaned_data.get('title'), + short_name : document_form.cleaned_data.get('short_name'), + abstract : document_form.cleaned_data.get('abstract'), + content : document_form.cleaned_data.get('content'), + link_name : link_name, + partial_path : partial_path, + id : logged_in_id, + user : user, + } site_doc = soc.logic.document_logic.updateOrCreateFromFields( properties, partial_path=partial_path, link_name=link_name) diff -r 812abb9a7e3b -r 972d28056d9d app/soc/views/site/sponsor/list.py --- a/app/soc/views/site/sponsor/list.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/views/site/sponsor/list.py Sun Oct 12 15:52:19 2008 +0000 @@ -22,6 +22,7 @@ ] +import soc.logic from soc.views import simple from soc.views import helper from soc.views.helper import access diff -r 812abb9a7e3b -r 972d28056d9d app/soc/views/site/user/profile.py --- a/app/soc/views/site/user/profile.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/views/site/user/profile.py Sun Oct 12 15:52:19 2008 +0000 @@ -220,7 +220,8 @@ if not validate.isLinkNameFormatValid(link_name): raise forms.ValidationError("This link name is in wrong format.") - user = soc.logic.user_logic.getFromKeyName(link_name) + key_name = self.data.get('key_name') + user = soc.logic.user_logic.getFromKeyName(key_name) if user and user.link_name != link_name: raise forms.ValidationError("This link name is already in use.") @@ -411,11 +412,12 @@ form_id = form.cleaned_data.get('id') link_name = form.cleaned_data.get('link_name') - properties = {} - properties['id'] = form_id - properties['link_name'] = link_name - properties['nick_name'] = form.cleaned_data.get('nick_name') - properties['is_developer'] = form.cleaned_data.get('is_developer') + properties = { + id : form_id, + link_name : link_name, + nick_name : form.cleaned_data.get('nick_name'), + is_developer : form.cleaned_data.get('is_developer'), + } user = soc.logic.user_logic.updateOrCreateFromFields(properties, email=form_id) diff -r 812abb9a7e3b -r 972d28056d9d app/soc/views/user/profile.py --- a/app/soc/views/user/profile.py Sun Oct 12 15:05:50 2008 +0000 +++ b/app/soc/views/user/profile.py Sun Oct 12 15:52:19 2008 +0000 @@ -131,10 +131,11 @@ if form.is_valid(): new_link_name = form.cleaned_data.get('link_name') - properties = {} - properties['link_name'] = new_link_name - properties['nick_name'] = form.cleaned_data.get("nick_name") - properties['id'] = id + properties = { + link_name : new_link_name, + nick_name : form.cleaned_data.get("nick_name"), + id : id, + } user = soc.logic.user_logic.updateOrCreateFromFields(properties, email=id)