Skip to content

Commit

Permalink
ver 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Aug 5, 2011
1 parent 964b207 commit 78b9704
Show file tree
Hide file tree
Showing 31 changed files with 524 additions and 388 deletions.
7 changes: 4 additions & 3 deletions backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def makeQuery(request):
reports=RentReport.objects.filter(city=i_city,street=i_street,address=i_address)
logging.info(reports)
if len(reports)==0:
logging.info("########TTTTTTTT")
logging.info("###NOT FOUND")
return HttpResponse("");
else:
uc=False
Expand All @@ -91,6 +91,7 @@ def makeQuery(request):
else:
uc=True
if uc:
resp=resp+"@"
resp=resp+" -1"
logging.info("########"+resp)
return HttpResponse(resp)
return HttpResponse(resp)

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="breadcrumbs">
<a href="../../">{% trans "Home" %}</a> &rsaquo;
<a href="../">{{ app_label|capfirst }}</a> &rsaquo;
<a href="./">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
<a href="">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% trans 'Delete multiple objects' %}
</div>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2>Model groups</h2>
<ul>
{% regroup models by app_label as grouped_models %}
{% for group in grouped_models %}
<li><a href="#app-{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
<li><a href="model_index.html#app-{{ group.grouper }}">{{ group.grouper|capfirst }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h3 id="{{ library.grouper|default_if_none:"built_in" }}-{{ filter.name }}">{{ f
<h2>{% firstof library.grouper "Built-in filters" %}</h2>
<ul>
{% for filter in library.list|dictsort:"name" %}
<li><a href="#{{ library.grouper|default_if_none:"built_in" }}-{{ filter.name }}">{{ filter.name }}</a></li>
<li><a href="template_filter_index.html#{{ library.grouper|default_if_none:"built_in" }}-{{ filter.name }}">{{ filter.name }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h4>{{ tag.title|striptags }}</h4>
<h2>{% firstof library.grouper "Built-in tags" %}</h2>
<ul>
{% for tag in library.list|dictsort:"name" %}
<li><a href="#{{ library.grouper|default_if_none:"built_in" }}-{{ tag.name }}">{{ tag.name }}</a></li>
<li><a href="template_tag_index.html#{{ library.grouper|default_if_none:"built_in" }}-{{ tag.name }}">{{ tag.name }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>View documentation</h1>
<h2>Jump to site</h2>
<ul>
{% for site_views in views_by_site %}
<li><a href="#site{{ site_views.grouper.id }}">{{ site_views.grouper.name }}</a></li>
<li><a href="view_index.html#site{{ site_views.grouper.id }}">{{ site_views.grouper.name }}</a></li>
{% endfor %}
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/comments/templates/comments/approve.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block content %}
<h1>{% trans "Really make this comment public?" %}</h1>
<blockquote>{{ comment|linebreaks }}</blockquote>
<form action="." method="post">{% csrf_token %}
<form action="" method="post">{% csrf_token %}
{% if next %}<div><input type="hidden" name="next" value="{{ next }}" id="next" /></div>{% endif %}
<p class="submit">
<input type="submit" name="submit" value="{% trans "Approve" %}" /> or <a href="{{ comment.get_absolute_url }}">cancel</a>
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/comments/templates/comments/delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block content %}
<h1>{% trans "Really remove this comment?" %}</h1>
<blockquote>{{ comment|linebreaks }}</blockquote>
<form action="." method="post">{% csrf_token %}
<form action="" method="post">{% csrf_token %}
{% if next %}<div><input type="hidden" name="next" value="{{ next }}" id="next" /></div>{% endif %}
<p class="submit">
<input type="submit" name="submit" value="{% trans "Remove" %}" /> or <a href="{{ comment.get_absolute_url }}">cancel</a>
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/comments/templates/comments/flag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% block content %}
<h1>{% trans "Really flag this comment?" %}</h1>
<blockquote>{{ comment|linebreaks }}</blockquote>
<form action="." method="post">{% csrf_token %}
<form action="" method="post">{% csrf_token %}
{% if next %}<div><input type="hidden" name="next" value="{{ next }}" id="next" /></div>{% endif %}
<p class="submit">
<input type="submit" name="submit" value="{% trans "Flag" %}" /> or <a href="{{ comment.get_absolute_url }}">cancel</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>Step {{ step }} of {{ step_count }}</p>
<form action="." method="post">{% csrf_token %}
<form action="" method="post">{% csrf_token %}
<table>
{{ form }}
</table>
Expand Down
152 changes: 117 additions & 35 deletions djangoappengine/db/base.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
from ..utils import appid, have_appserver, on_production_server
from ..boot import DATA_ROOT
from ..utils import appid, on_production_server
from .creation import DatabaseCreation
from .stubs import stub_manager
from django.db.backends.util import format_number
from djangotoolbox.db.base import NonrelDatabaseFeatures, \
NonrelDatabaseOperations, NonrelDatabaseWrapper, NonrelDatabaseClient, \
NonrelDatabaseValidation, NonrelDatabaseIntrospection
from google.appengine.ext.db.metadata import get_kinds, get_namespaces
from google.appengine.api.datastore import Query, Delete
from google.appengine.api.namespace_manager import set_namespace
from google.appengine.api.datastore import Query
from urllib2 import HTTPError, URLError
import logging
import os
import time

REMOTE_API_SCRIPT = '$PYTHON_LIB/google/appengine/ext/remote_api/handler.py'
DATASTORE_PATHS = {
'datastore_path': os.path.join(DATA_ROOT, 'datastore'),
'blobstore_path': os.path.join(DATA_ROOT, 'blobstore'),
'rdbms_sqlite_path': os.path.join(DATA_ROOT, 'rdbms'),
'prospective_search_path': os.path.join(DATA_ROOT, 'prospective-search'),
}

def auth_func():
import getpass
return raw_input('Login via Google Account (see note above if login fails): '), getpass.getpass('Password: ')

def rpc_server_factory(*args, ** kwargs):
from google.appengine.tools import appengine_rpc
kwargs['save_cookies'] = True
return appengine_rpc.HttpRpcServer(*args, ** kwargs)

def get_datastore_paths(options):
paths = {}
for key, path in DATASTORE_PATHS.items():
paths[key] = options.get(key, path)
return paths

def get_test_datastore_paths(options, inmemory=True):
paths = get_datastore_paths(options)
for key in paths:
paths[key] += '.test'
if inmemory:
for key in ('datastore_path', 'blobstore_path'):
paths[key] = None
return paths

def destroy_datastore(paths):
"""Destroys the appengine datastore at the specified paths."""
for path in paths.values():
Expand All @@ -44,9 +62,8 @@ class DatabaseOperations(NonrelDatabaseOperations):
compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'

DEFAULT_MAX_DIGITS = 16

def value_to_db_decimal(self, value, max_digits, decimal_places):
if value is None:
if value is None:
return None
sign = value < 0 and u'-' or u''
if sign:
Expand Down Expand Up @@ -92,24 +109,96 @@ def __init__(self, *args, **kwds):
self.validation = DatabaseValidation(self)
self.introspection = DatabaseIntrospection(self)
options = self.settings_dict
self.use_test_datastore = False
self.test_datastore_inmemory = True
self.remote = options.get('REMOTE', False)
if on_production_server:
self.remote = False
self.remote_app_id = options.get('REMOTE_APP_ID', appid)
self.high_replication = options.get('HIGH_REPLICATION', False)
self.domain = options.get('DOMAIN', 'appspot.com')
self.remote_api_path = options.get('REMOTE_API_PATH', None)
self.secure_remote_api = options.get('SECURE_REMOTE_API', True)
self._setup_stubs()

remote = options.get('REMOTE', False)
if on_production_server:
remote = False
if remote:
stub_manager.setup_remote_stubs(self)
def _get_paths(self):
if self.use_test_datastore:
return get_test_datastore_paths(self.settings_dict, self.test_datastore_inmemory)
else:
stub_manager.setup_stubs(self)
return get_datastore_paths(self.settings_dict)

def _setup_stubs(self):
# If this code is being run without an appserver (eg. via a django
# commandline flag) then setup a default stub environment.
if not have_appserver:
from google.appengine.tools import dev_appserver_main
args = dev_appserver_main.DEFAULT_ARGS.copy()
args.update(self._get_paths())
log_level = logging.getLogger().getEffectiveLevel()
logging.getLogger().setLevel(logging.WARNING)
from google.appengine.tools import dev_appserver
dev_appserver.SetupStubs(appid, **args)
logging.getLogger().setLevel(log_level)
# If we're supposed to set up the remote_api, do that now.
if self.remote:
self.setup_remote()

def setup_remote(self):
if not self.remote_api_path:
from ..utils import appconfig
for handler in appconfig.handlers:
if handler.script == REMOTE_API_SCRIPT:
self.remote_api_path = handler.url.split('(', 1)[0]
break
self.remote = True
server = '%s.%s' % (self.remote_app_id, self.domain)
remote_url = 'https://%s%s' % (server, self.remote_api_path)
logging.info('Setting up remote_api for "%s" at %s' %
(self.remote_app_id, remote_url))
if not have_appserver:
print('Connecting to remote_api handler.\n\n'
'IMPORTANT: Check your login method settings in the '
'App Engine Dashboard if you have problems logging in. '
'Login is only supported for Google Accounts.\n')
from google.appengine.ext.remote_api import remote_api_stub
remote_app_id = self.remote_app_id
if self.high_replication:
remote_app_id = 's~' + remote_app_id
remote_api_stub.ConfigureRemoteApi(remote_app_id,
self.remote_api_path, auth_func, servername=server,
secure=self.secure_remote_api,
rpc_server_factory=rpc_server_factory)
retry_delay = 1
while retry_delay <= 16:
try:
remote_api_stub.MaybeInvokeAuthentication()
except HTTPError, e:
if not have_appserver:
print 'Retrying in %d seconds...' % retry_delay
time.sleep(retry_delay)
retry_delay *= 2
else:
break
else:
try:
remote_api_stub.MaybeInvokeAuthentication()
except HTTPError, e:
raise URLError("%s\n"
"Couldn't reach remote_api handler at %s.\n"
"Make sure you've deployed your project and "
"installed a remote_api handler in app.yaml. "
"Note that login is only supported for "
"Google Accounts. Make sure you've configured "
"the correct authentication method in the "
"App Engine Dashboard."
% (e, remote_url))
logging.info('Now using the remote datastore for "%s" at %s' %
(self.remote_app_id, remote_url))

def flush(self):
"""Helper function to remove the current datastore and re-open the stubs"""
if stub_manager.active_stubs == 'remote':
import random
import string
if self.remote:
import random, string
code = ''.join([random.choice(string.ascii_letters) for x in range(4)])
print '\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
Expand All @@ -123,28 +212,21 @@ def flush(self):
response = raw_input('Repeat: ')
if code == response:
print 'Deleting...'
delete_all_entities()
from django.db import models
from google.appengine.api import datastore as ds
for model in models.get_models():
print 'Deleting %s...' % model._meta.db_table
while True:
data = ds.Query(model._meta.db_table, keys_only=True).Get(200)
if not data:
break
ds.Delete(data)
print "Datastore flushed! Please check your dashboard's " \
'datastore viewer for any remaining entities and remove ' \
'all unneeded indexes with appcfg.py vacuum_indexes.'
'all unneeded indexes with manage.py vacuum_indexes.'
else:
print 'Aborting'
exit()
elif stub_manager.active_stubs == 'test':
stub_manager.deactivate_test_stubs()
stub_manager.activate_test_stubs()
else:
destroy_datastore(get_datastore_paths(self.settings_dict))
stub_manager.setup_local_stubs(self)

def delete_all_entities():
for namespace in get_namespaces():
set_namespace(namespace)
for kind in get_kinds():
if kind.startswith('__'):
continue
while True:
data = Query(kind=kind, keys_only=True).Get(200)
if not data:
break
Delete(data)
destroy_datastore(self._get_paths())
self._setup_stubs()
61 changes: 5 additions & 56 deletions djangoappengine/db/compiler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .db_settings import get_model_indexes
from .utils import commit_locked
from .expressions import ExpressionEvaluator

import datetime
import sys
Expand Down Expand Up @@ -118,10 +116,7 @@ def fetch(self, low_mark, high_mark):
yield self._make_entity(entity)

if executed and not isinstance(query, MultiQuery):
try:
self.query._gae_cursor = query.GetCompiledCursor()
except:
pass
self.query._gae_cursor = query.GetCompiledCursor()

@safe_call
def count(self, limit=None):
Expand Down Expand Up @@ -189,11 +184,11 @@ def add_filter(self, column, lookup_type, negated, db_type, value):
key_type_error = 'Lookup values on primary keys have to be' \
'a string or an integer.'
if lookup_type == 'range':
if isinstance(value, (list, tuple)) and not (
isinstance(value[0], (basestring, int, long)) and
if isinstance(value,(list, tuple)) and not(isinstance(
value[0], (basestring, int, long)) and \
isinstance(value[1], (basestring, int, long))):
raise DatabaseError(key_type_error)
elif not isinstance(value, (basestring, int, long)):
elif not isinstance(value,(basestring, int, long)):
raise DatabaseError(key_type_error)
# for lookup type range we have to deal with a list
if lookup_type == 'range':
Expand Down Expand Up @@ -473,53 +468,7 @@ def insert(self, data, return_id=False):
return key.id_or_name()

class SQLUpdateCompiler(NonrelUpdateCompiler, SQLCompiler):
def execute_sql(self, result_type=MULTI):
# modify query to fetch pks only and then execute the query
# to get all pks
pk = self.query.model._meta.pk.name
self.query.add_immediate_loading([pk])
pks = [row for row in self.results_iter()]
self.update_entities(pks)
return len(pks)

def update_entities(self, pks):
for pk in pks:
self.update_entity(pk[0])

@commit_locked
def update_entity(self, pk):
gae_query = self.build_query()
key = create_key(self.query.get_meta().db_table, pk)
entity = Get(key)
if not gae_query.matches_filters(entity):
return

qn = self.quote_name_unless_alias
update_dict = {}
for field, o, value in self.query.values:
if hasattr(value, 'prepare_database_save'):
value = value.prepare_database_save(field)
else:
value = field.get_db_prep_save(value, connection=self.connection)

if hasattr(value, "evaluate"):
assert not value.negated
assert not value.subtree_parents
value = ExpressionEvaluator(value, self.query, entity,
allow_joins=False)

if hasattr(value, 'as_sql'):
# evaluate expression and return the new value
val = value.as_sql(qn, self.connection)
update_dict[field] = val
else:
update_dict[field] = value

for field, value in update_dict.iteritems():
db_type = field.db_type(connection=self.connection)
entity[qn(field.column)] = self.convert_value_for_db(db_type, value)

key = Put(entity)
pass

class SQLDeleteCompiler(NonrelDeleteCompiler, SQLCompiler):
pass
Expand Down
Loading

0 comments on commit 78b9704

Please sign in to comment.