Made the existing code use the new soc.logic.models
Patch by: Sverre Rabbelier
Reviewed by: to-be-reviewed
--- a/app/soc/logic/site/id_user.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/logic/site/id_user.py Sun Oct 12 18:30:37 2008 +0000
@@ -28,9 +28,9 @@
from google.appengine.api import users
from google.appengine.ext import db
-import soc.logic
from soc.logic import key_name
from soc.logic import model
+from soc.logic import models
from soc.logic import out_of_band
import soc.models.user
@@ -89,7 +89,7 @@
if not id:
id = current_id
- user = soc.logic.user_logic.getFromFields(email=id)
+ user = models.user.logic.getFromFields(email=id)
if not user:
# no User entity for this Google Account, and id is not the currently
@@ -111,7 +111,7 @@
when existing_user is not supplied; default is None
"""
if not existing_user:
- existing_user = soc.logic.user_logic.getFromKeyName(existing_key_name)
+ existing_user = models.user.logic.getFromKeyName(existing_key_name)
if existing_user:
old_email = existing_user.id.email()
@@ -123,7 +123,7 @@
return True
# else: "new" email truly is new to the existing User, so keep checking
- if not soc.logic.user_logic.getFromFields(id=new_id):
+ if not models.user.logic.getFromFields(id=new_id):
# new email address also does not belong to any other User,
# so it is available
return True
@@ -169,7 +169,7 @@
# link name cannot belong to an unspecified User
return False
- user = soc.logic.user_logic.getFromFields(email=id.email())
+ user = models.user.logic.getFromFields(email=id.email())
if not user:
# no User corresponding to id Google Account, so no link name at all
--- a/app/soc/views/helper/access.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/helper/access.py Sun Oct 12 18:30:37 2008 +0000
@@ -33,7 +33,7 @@
from google.appengine.api import users
from django.utils.translation import ugettext_lazy
-import soc.logic.host
+from soc.logic import models
from soc.logic.site import id_user
from soc.views.simple import requestLogin
import soc.views.out_of_band
@@ -96,7 +96,7 @@
checkIsLoggedIn(request)
id = users.get_current_user()
- user = soc.logic.user_logic.getFromFields(email=id)
+ user = models.user.logic.getFromFields(email=id)
if user:
return
--- a/app/soc/views/helper/responses.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/helper/responses.py Sun Oct 12 18:30:37 2008 +0000
@@ -30,6 +30,8 @@
from django import http
from django.template import loader
+import soc.logic.models.user
+
# DeadlineExceededError can live in two different places
try:
# When deployed
@@ -116,7 +118,7 @@
if id:
context['id'] = id
- context['user'] = soc.logic.user_logic.getFromFields(email=id.email())
+ context['user'] = soc.logic.models.user.logic.getFromFields(email=id.email())
context['is_admin'] = id_user.isIdDeveloper(id=id)
context['is_debug'] = system.isDebug()
--- a/app/soc/views/site/docs/edit.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/docs/edit.py Sun Oct 12 18:30:37 2008 +0000
@@ -28,7 +28,7 @@
from django import newforms as forms
from django.utils.translation import ugettext_lazy
-import soc.logic
+from soc.logic.models import document
from soc.logic import out_of_band
from soc.logic import path_link_name
from soc.logic.site import id_user
@@ -97,9 +97,9 @@
properties['short_name'] = form.cleaned_data.get('short_name')
properties['abstract'] = form.cleaned_data.get('abstract')
properties['content'] = form.cleaned_data.get('content')
- properties['user'] = soc.logic.user_logic.getFromFields(email=email)
+ properties['user'] = models.user.logic.getFromFields(email=email)
- doc = soc.logic.document_logic.updateOrCreateFromFields(properties,
+ doc = document.logic.updateOrCreateFromFields(properties,
partial_path=partial_path, link_name=link_name)
return doc
@@ -139,7 +139,7 @@
# try to fetch Document entity corresponding to path if one exists
try:
if path:
- doc = soc.logic.document_logic.getFromFields(partial_path=partial_path,
+ doc = document.logic.getFromFields(partial_path=partial_path,
link_name=link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when path doesn't exist in Datastore
--- a/app/soc/views/site/docs/list.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/docs/list.py Sun Oct 12 18:30:37 2008 +0000
@@ -23,6 +23,7 @@
import soc.logic
+from soc.logic import models
import soc.models.document
from soc.views import simple
from soc.views import helper
@@ -60,7 +61,7 @@
offset=request.GET.get('offset'), limit=request.GET.get('limit'))
# Fetch one more to see if there should be a 'next' link
- docs = soc.logic.work_logic.getForLimitAndOffset(limit + 1, offset=offset)
+ docs = models.work.logic.getForLimitAndOffset(limit + 1, offset=offset)
context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
--- a/app/soc/views/site/home.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/home.py Sun Oct 12 18:30:37 2008 +0000
@@ -33,9 +33,12 @@
from django import shortcuts
from django import newforms as forms
-import soc.logic
+
+import soc.logic.models.settings
+from soc.logic import models
from soc.logic import out_of_band
from soc.logic import validate
+from soc.logic.models import document
from soc.logic.site import id_user
from soc.views import simple
from soc.views import helper
@@ -107,7 +110,7 @@
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
- site_settings = soc.logic.settings_logic.getFromFields(path=DEF_SITE_SETTINGS_PATH)
+ site_settings = soc.logic.models.settings.logic.getFromFields(path=DEF_SITE_SETTINGS_PATH)
if site_settings:
context['site_settings'] = site_settings
@@ -152,7 +155,7 @@
link_name = DEF_SITE_HOME_DOC_LINK_NAME
partial_path=DEF_SITE_SETTINGS_PATH
logged_in_id = users.get_current_user()
- user = soc.logic.user_logic.getFromFields(email=logged_in_id)
+ user = models.user.logic.getFromFields(email=logged_in_id)
properties = {
title : document_form.cleaned_data.get('title'),
@@ -165,18 +168,18 @@
user : user,
}
- site_doc = soc.logic.document_logic.updateOrCreateFromFields(
+ site_doc = document.logic.updateOrCreateFromFields(
properties, partial_path=partial_path, link_name=link_name)
feed_url = settings_form.cleaned_data.get('feed_url')
- site_settings = soc.logic.settings_logic.updateOrCreateFromFields(
+ site_settings = models.settings.logic.updateOrCreateFromFields(
{'feed_url' : feed_url, 'home' : site_doc}, path=DEF_SITE_SETTINGS_PATH)
context['notice'] = 'Site Settings saved.'
else: # request.method == 'GET'
# try to fetch SiteSettings entity by unique key_name
- site_settings = soc.logic.settings_logic.getFromFields(
+ site_settings = models.settings.logic.getFromFields(
path=DEF_SITE_SETTINGS_PATH)
if site_settings:
--- a/app/soc/views/site/sponsor/list.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/sponsor/list.py Sun Oct 12 18:30:37 2008 +0000
@@ -23,6 +23,7 @@
import soc.logic
+from soc.logic import models
from soc.views import simple
from soc.views import helper
from soc.views.helper import access
@@ -49,7 +50,7 @@
offset=request.GET.get('offset'), limit=request.GET.get('limit'))
# Fetch one more to see if there should be a 'next' link
- sponsors = soc.logic.sponsor_logic.getForLimitAndOffset(limit + 1, offset=offset)
+ sponsors = models.sponsor.logic.getForLimitAndOffset(limit + 1, offset=offset)
context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
--- a/app/soc/views/site/sponsor/profile.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/sponsor/profile.py Sun Oct 12 18:30:37 2008 +0000
@@ -31,6 +31,7 @@
from soc.logic import validate
from soc.logic import out_of_band
from soc.logic.site import id_user
+from soc.logic import models
import soc.models.sponsor
from soc.views import helper
from soc.views.helper import access
@@ -59,7 +60,7 @@
link_name = self.cleaned_data.get('link_name')
if not validate.isLinkNameFormatValid(link_name):
raise forms.ValidationError("This link name is in wrong format.")
- if soc.logic.sponsor_logic.getFromFields(link_name=link_name):
+ if models.sponsor.logic.getFromFields(link_name=link_name):
raise forms.ValidationError("This link name is already in use.")
return link_name
@@ -105,13 +106,13 @@
context = helper.responses.getUniversalContext(request)
logged_in_id = users.get_current_user()
- user = soc.logic.user_logic.getFromFields(email=logged_in_id)
+ user = models.user.logic.getFromFields(email=logged_in_id)
sponsor_form = None
existing_sponsor = None
# try to fetch Sponsor entity corresponding to link_name if one exists
try:
- existing_sponsor = soc.logic.sponsor_logic.getIfFields(link_name=link_name)
+ existing_sponsor = models.sponsor.logic.getIfFields(link_name=link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG
@@ -143,7 +144,7 @@
fields['founder'] = user
form_ln = fields['link_name']
- form_sponsor = soc.logic.sponsor_logic.updateOrCreateFromFields(fields, link_name=form_ln)
+ form_sponsor = models.sponsor.logic.updateOrCreateFromFields(fields, link_name=form_ln)
if not form_sponsor:
return http.HttpResponseRedirect('/')
@@ -221,7 +222,7 @@
# try to fetch Sponsor entity corresponding to link_name if one exists
try:
- existing_sponsor = soc.logic.sponsor_logic.getIfFields(link_name=link_name)
+ existing_sponsor = models.sponsor.logic.getIfFields(link_name=link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
error.message = error.message + DEF_CREATE_NEW_SPONSOR_MSG
@@ -230,6 +231,6 @@
if existing_sponsor:
# TODO(pawel.solyga): Create specific delete method for Sponsor model
# Check if Sponsor can be deleted (has no Hosts and Programs)
- soc.logic.sponsor_logic.delete(existing_sponsor)
+ models.sponsor.logic.delete(existing_sponsor)
return http.HttpResponseRedirect('/site/sponsor/list')
\ No newline at end of file
--- a/app/soc/views/site/user/list.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/user/list.py Sun Oct 12 18:30:37 2008 +0000
@@ -23,6 +23,7 @@
import soc.logic
+from soc.logic import models
from soc.logic.site import id_user
import soc.models.user
from soc.views import simple
@@ -61,7 +62,7 @@
offset=request.GET.get('offset'), limit=request.GET.get('limit'))
# Fetch one more to see if there should be a 'next' link
- users = soc.logic.user_logic.getForLimitAndOffset(limit + 1, offset=offset)
+ users = models.user.logic.getForLimitAndOffset(limit + 1, offset=offset)
context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
--- a/app/soc/views/site/user/profile.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/site/user/profile.py Sun Oct 12 18:30:37 2008 +0000
@@ -29,6 +29,7 @@
from django.utils.translation import ugettext_lazy
import soc.logic
+from soc.logic import models
from soc.logic import validate
from soc.logic import out_of_band
from soc.logic.site import id_user
@@ -127,7 +128,7 @@
if form_id:
# email provided, so attempt to look up user by email
- user = soc.logic.user_logic.getFromFields(id=form_id)
+ user = models.user.logic.getFromFields(id=form_id)
if user:
lookup_message = ugettext_lazy('User found by email.')
@@ -221,7 +222,7 @@
raise forms.ValidationError("This link name is in wrong format.")
key_name = self.data.get('key_name')
- user = soc.logic.user_logic.getFromKeyName(key_name)
+ user = models.user.logic.getFromKeyName(key_name)
if user and user.link_name != link_name:
raise forms.ValidationError("This link name is already in use.")
@@ -282,7 +283,7 @@
properties['nick_name'] = form.cleaned_data.get('nick_name')
properties['is_developer'] = form.cleaned_data.get('is_developer')
- user = soc.logic.user_logic.updateOrCreateFromKeyName(properties, key_name)
+ user = models.user.logic.updateOrCreateFromKeyName(properties, key_name)
#raise forms.ValidationError("lesseee: " + new_link_name + " " + user.link_name)
@@ -377,7 +378,7 @@
def clean_id(self):
new_email = self.cleaned_data.get('id')
form_id = users.User(email=new_email)
- if soc.logic.user_logic.getFromFields(email=form_id):
+ if models.user.logic.getFromFields(email=form_id):
raise forms.ValidationError("This account is already in use.")
return form_id
@@ -419,7 +420,7 @@
is_developer : form.cleaned_data.get('is_developer'),
}
- user = soc.logic.user_logic.updateOrCreateFromFields(properties, email=form_id)
+ user = models.user.logic.updateOrCreateFromFields(properties, email=form_id)
if not user:
return http.HttpResponseRedirect('/')
--- a/app/soc/views/sponsor/profile.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/sponsor/profile.py Sun Oct 12 18:30:37 2008 +0000
@@ -22,8 +22,8 @@
]
+import soc.logic.models.sponsor
from soc.logic import out_of_band
-from soc.logic import sponsor
from soc.views import simple
from soc.views import helper
import soc.views.helper.responses
@@ -47,7 +47,7 @@
context = helper.responses.getUniversalContext(request)
try:
- link_name_sponsor = sponsor.sponsor_logic.getIfFields(link_name=link_name)
+ link_name_sponsor = soc.logic.models.sponsor.logic.getIfFields(link_name=link_name)
except out_of_band.ErrorResponse, error:
# show custom 404 page when link name doesn't exist in Datastore
return simple.errorResponse(request, error, template, context)
--- a/app/soc/views/user/profile.py Sun Oct 12 18:11:20 2008 +0000
+++ b/app/soc/views/user/profile.py Sun Oct 12 18:30:37 2008 +0000
@@ -29,6 +29,7 @@
from django.utils.translation import ugettext_lazy
import soc.logic
+from soc.logic import models
from soc.logic import validate
from soc.logic import out_of_band
from soc.logic.site import id_user
@@ -137,7 +138,7 @@
id : id,
}
- user = soc.logic.user_logic.updateOrCreateFromFields(properties, email=id)
+ user = models.user.logic.updateOrCreateFromFields(properties, email=id.email())
# redirect to new /user/profile/new_link_name?s=0
# (causes 'Profile saved' message to be displayed)
@@ -145,7 +146,7 @@
request, link_name, new_link_name, params=SUBMIT_PROFILE_SAVED_PARAMS)
else: # request.method == 'GET'
# try to fetch User entity corresponding to Google Account if one exists
- user = soc.logic.user_logic.getFromFields(email=id)
+ user = models.user.logic.getFromFields(email=id)
if user:
# is 'Profile saved' parameter present, but referrer was not ourself?