# HG changeset patch # User Sverre Rabbelier # Date 1227743680 0 # Node ID be98a2f5d8a279aa695572c66f4abe004eda4356 # Parent 530fa94faffec81dd6395d43e8b2cfd21b64b32e Fixed an outstanding TODO for tlarsen A nice side-effect is that accounts now does not depend on out_of_band, sadly that does not fix the cyclic dependency, but it is a nice side-effect nonetheless. diff -r 530fa94faffe -r be98a2f5d8a2 app/soc/logic/accounts.py --- a/app/soc/logic/accounts.py Wed Nov 26 21:34:11 2008 +0000 +++ b/app/soc/logic/accounts.py Wed Nov 26 23:54:40 2008 +0000 @@ -26,7 +26,6 @@ from google.appengine.api import users from soc.logic import models -from soc.views import out_of_band import soc.models.user import soc.logic.models.user @@ -110,20 +109,3 @@ # email does not already belong to this User, but to some other User return False - - -# TODO(tlarsen): make this generic for any Linkable and move elsewhere -def getUserFromLinkIdOr404(link_id): - """Like getUserFromLinkId but expects to find a user. - - Raises: - out_of_band.Error if no User entity is found - """ - user = models.user.logic.getForFields({'link_id': link_id}, - unique=True) - - if user: - return user - - raise out_of_band.Error( - 'There is no user with a "link ID" of "%s".' % link_id, status=404) diff -r 530fa94faffe -r be98a2f5d8a2 app/soc/logic/models/base.py --- a/app/soc/logic/models/base.py Wed Nov 26 21:34:11 2008 +0000 +++ b/app/soc/logic/models/base.py Wed Nov 26 23:54:40 2008 +0000 @@ -207,29 +207,17 @@ return entity - def getIfFields(self, fields): - """Returns entity for supplied link ID if one exists. - Args: - fields: the fields of the entity that uniquely identifies it - - Returns: - * None if a field is false. - * Entity for supplied fields + def getFromFieldsOr404(self, **fields): + """Like getFromFields but expects to find an entity. Raises: - out_of_band.Error if link ID is not false, but no entity - with the supplied link ID exists in the Datastore. + out_of_band.Error if no User entity is found """ - if not all(fields.values()): - # exit without error, to let view know that link_id was not supplied - return None - entity = self.getFromFields(**fields) if entity: - # an entity exist for this link_id, so return that entity return entity format_text = ugettext_lazy('"%(key)s" is "%(value)s"') @@ -243,9 +231,21 @@ 'There is no "%(name)s" where %(pairs)s.') % { 'name': self._name, 'pairs': joined_pairs} + raise out_of_band.Error(msg, status=404) - # else: fields were supplied, but there is no Entity that has it - raise out_of_band.Error(msg, status=404) + + def getIfFields(self, fields): + """Like getFromFieldsOr404 but returns none if not all fields are set + + Raises: + out_of_band.Error if no User entity is found and all fields were set + """ + + if not all(fields.values()): + return None + + return self.getFromFieldsOr404(**fields) + def getKeyNameForFields(self, fields): """Return a Datastore key_name for a Entity from the specified fields.