Hi Mary,
Attached is a patch to get stuff.search and stuff testing framework
(not unlike the new django one) working. I've been using this in a
production django site for around a year.
On 3/20/07, Mary <[EMAIL PROTECTED]> wrote:
>
> I want anybody to help me and tell me where to find
> https://simon.bofh.ms/cgi-bin/trac-django-projects.cgi/wiki/AbstractSearching
> that can work with Django stable version 0.95.1
> cause i want to use Abstarct search module
>
> May be this is not the right place for this question but i really
> don't know where i can ask this question
>
> Thank you in advance
> Mary Adel
>
> On Mar 19, 9:41 pm, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> wrote:
> > DjangoStuff:https://simon.bofh.ms/cgi-bin/trac-django-projects.cgi/wiki/DjangoStuff
> >
> > Is not part of the core Django system and is third party.
> > It is developed by D. Joseph Creighton, and all questions on his code
> > should be directed to him:https://simon.bofh.ms/
> >
> > In direct answer to your question: no. Not all of the djangostuff code
> > works with 0.95.1, some of it has been migrated, some of it has not,
> > and the testing framework has been deprecated in favor of the testing
> > framework in django. You will need to read up on the documentation on
> > each individual project or app.
> >
> > You just need to put the code somewhere on your PYTHONPATH. There are
> > complete instructions on the DjangoStuff track wiki, and in the code
> > its self. You may need to modify some of the code in order to get it
> > to work with your site.
> >
> > -Doug
>
>
> >
>
--
matthew
http://wadofstuff.blogspot.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: utils.py
===================================================================
--- utils.py (revision 1016)
+++ utils.py (working copy)
@@ -2,7 +2,7 @@
Simple and handy utility functions.
"""
-from django.models.core import sites
+from django.contrib.sites.models import Site
from django.core.template.defaultfilters import slugify
from stuff.latin1 import latin1_to_ascii
@@ -30,7 +30,7 @@
slug = _slug(slugify(latin1_to_ascii(title)))
if sitesfield is not None:
- current = sites.get_current()
+ current = Site.objects.get_current()
i = 1
pslug = slug
while True:
@@ -38,7 +38,7 @@
kw.update(extra_kwargs)
if sitesfield is not None:
kw.update({'%s__id__exact' % sitesfield: current.id})
- t = table.get_list(**kw)
+ t = table.objects.filter(**kw)
if not t:
return pslug
i += 1
@@ -53,6 +53,6 @@
global current_site
if current_site is not None:
return current_site
- current_site = sites.get_current()
+ current_site = Site.objects.get_current()
return current_site
Index: json.py
===================================================================
--- json.py (revision 1016)
+++ json.py (working copy)
@@ -2,7 +2,7 @@
import types
import re
-from django.conf.settings import DEFAULT_CHARSET
+from django.conf import settings
## json.py implements a JSON (http://json.org) reader and writer.
## Copyright (C) 2005 Patrick D. Logan
@@ -301,7 +301,7 @@
obj = obj.replace('\r', r'\r')
obj = obj.replace('\t', r'\t')
if ty is types.StringType:
- obj = obj.decode(DEFAULT_CHARSET)
+ obj = obj.decode(settings.DEFAULT_CHARSET)
obj = str(ustring_quote(obj))
self._append(obj)
self._append('"')
Index: testing.py
===================================================================
--- testing.py (revision 1016)
+++ testing.py (working copy)
@@ -110,19 +110,15 @@
if hasattr(fixture_mod, '_fixtures'):
return fixture_mod._fixtures
- app_label = getattr(fixture_mod, 'app_label', None)
- module_name = getattr(fixture_mod, 'module_name', None)
+ model_name = getattr(fixture_mod, 'model_name', None)
fixtures = []
for name, obj in fixture_mod.__dict__.items():
if type(obj) == type and hasattr(obj, 'DATA'):
- my_app_label = getattr(obj, 'app_label', app_label)
- my_module_name = getattr(obj, 'module_name', module_name)
- if not my_app_label or not my_module_name:
+ my_model_name = getattr(obj, 'model_name', model_name)
+ if not my_model_name:
raise FixtureFileBroken, module
- model_mod = __import__('django.models.%s' % my_app_label, {}, {}, [my_module_name])
- model_mod = getattr(model_mod, my_module_name)
- fixtures.append((obj(name, model_mod), inspect.findsource(obj)[1]))
+ fixtures.append((obj(name, my_model_name), inspect.findsource(obj)[1]))
fixtures.sort(lambda a,b: cmp(a[1], b[1]))
fixture_mod._fixtures = [obj for obj, line in fixtures]
return fixture_mod._fixtures
@@ -136,7 +132,7 @@
for fixture in fixtures:
kw = dict([(k,v) for (k,v) in fixture.DATA.__dict__.items() if not k.startswith('_')])
- obj = fixture.model_module.Klass(**kw)
+ obj = fixture.model_module(**kw)
objects.append((fixture, obj))
# as a last action store all fixtures in the database
Index: search/utils.py
===================================================================
--- search/utils.py (revision 1016)
+++ search/utils.py (working copy)
@@ -3,12 +3,12 @@
deconstructing search queries and mapping them to models.
"""
try:
- from django.conf.settings import SEARCH_DEFINITIONS
+ from django.conf import settings
except ImportError:
- SEARCH_DEFINITIONS = ()
+ settings.SEARCH_DEFINITIONS = ()
-from django.models import get_module
-from django.core.meta import Q
+from django.db.models.loading import get_model
+from django.db.models import Q
import datetime
from helpers import SearchDefinitionMeta, SearchDefinition
@@ -31,7 +31,7 @@
def __init__(self, search_definition):
self.search_definition = search_definition
(app_label, module_name) = search_definition.model_module.split('.')
- self.model_module = get_module(app_label, module_name)
+ self.model_module = get_model(app_label, module_name)
self.search_fields = search_definition.search_fields
self.lookup_filters = {}
self.result_filters = {}
@@ -78,7 +78,6 @@
extra_args = self.lookup_filters[t](v)
if extra_args in (False, None):
return []
- lookup_kwargs.update(extra_args)
if q is None: q = Q(**extra_args)
else: q = q & Q(**extra_args)
else:
@@ -100,7 +99,7 @@
if q is None: q = subclause
else: q = q & subclause
- objectids = dict([(el, True) for el in self.get_id_list(complex=q, **lookup_kwargs)])
+ objectids = dict([(el, True) for el in self.get_id_list(q, **lookup_kwargs)])
if not objectids: return []
if notwords:
@@ -115,12 +114,12 @@
else: q = q & subclause
kw = {}
kw.update(lookup_kwargs)
- for id in self.get_id_list(complex=q, id__in=objectids.keys(), **kw):
+ for id in self.get_id_list(q, id__in=objectids.keys(), **kw):
if objectids.has_key(id): del objectids[id]
if not objectids: return []
- res = self.model_module.get_in_bulk(objectids.keys(), select_related=True).values()
+ res = self.model_module.objects.in_bulk(objectids.keys()).values()
f = ''
if getattr(self.search_definition, 'time_order_by', None):
f = self.search_definition.time_order_by
@@ -142,11 +141,11 @@
This function loads the search definitions and returns
a structure describing all searches. If the list of
module names isn't passed as a parameter, it uses the
- setting SEARCH_DEFINITIONS.
+ setting settings.SEARCH_DEFINITIONS.
"""
if module_list is None:
- module_list = SEARCH_DEFINITIONS
+ module_list = settings.SEARCH_DEFINITIONS
classes = []
@@ -248,12 +247,14 @@
oldpos = pos
pos, w = word(pos)
p = w.find(':')
- if p >= 0 and w.startswith('-'):
- pos, v = word(oldpos+p+1)
- notags.append([w.split(':',1)[0], v])
- elif p >= 0:
- pos, v = word(oldpos+p+1)
- tags.append([w.split(':',1)[0], v])
+ # check if keyword and keyword has a value
+ if p >= 0 and len(w) > p+1:
+ if w.startswith('-'):
+ pos, v = word(oldpos+p+1)
+ notags.append([w.split(':',1)[0], v])
+ else:
+ pos, v = word(oldpos+p+1)
+ tags.append([w.split(':',1)[0], v])
elif w.startswith('-'):
nowords.append(w[1:])
else:
Index: search/helpers.py
===================================================================
--- search/helpers.py (revision 1016)
+++ search/helpers.py (working copy)
@@ -28,7 +28,7 @@
This function is actually copied over to the controller, so that's why it
takes a controller as first parameter, not a search definition.
"""
- for row in controller.model_module.get_values_iterator(fields=('id',), *args, **kw):
+ for row in controller.model_module.objects.values('id').filter(*args, **kw).iterator():
yield row['id']
def make_date_lookup(fieldname):
Index: search/templatetags/searching.py
===================================================================
--- search/templatetags/searching.py (revision 1016)
+++ search/templatetags/searching.py (working copy)
@@ -3,7 +3,7 @@
within templates.
"""
-from django.core import template
+from django import template
from stuff.search.utils import parse, search, merge
Index: search/views/generic.py
===================================================================
--- search/views/generic.py (revision 1016)
+++ search/views/generic.py (working copy)
@@ -2,8 +2,8 @@
These are generic views for searching objects.
"""
-from django.core.extensions import DjangoContext
-from django.core.extensions import render_to_response
+from django.template import RequestContext
+from django.shortcuts import render_to_response
from stuff.search.utils import parse, search, merge
@@ -45,7 +45,7 @@
"""
if template_name is None:
- template_name = 'search/result'
+ template_name = 'search/result.html'
query = request.GET.get('q', '').strip()
more = request.GET.get('more', '').strip()
@@ -72,5 +72,5 @@
'number_results': number_results,
'number_shown': number_shown,
}
- return render_to_response(template_name, c, context_instance=DjangoContext(request))
+ return render_to_response(template_name, c, context_instance=RequestContext(request))
Index: bin/django-test.py
===================================================================
--- bin/django-test.py (revision 1016)
+++ bin/django-test.py (working copy)
@@ -4,33 +4,23 @@
import getopt
import unittest
-from django.models.core import sites
-from django.conf.settings import INSTALLED_APPS
+from django.conf import settings
from django.core.management import get_sql_delete, get_sql_all
-from django.core import db
+from django import db
from stuff.testing import gather_testcases, reversed
from stuff import coverage
try:
- from django.conf.settings import TESTING
-except ImportError:
+ TESTING = settings.TESTING
+except AttributeError:
TESTING = False
if not TESTING:
print "settings file %r is not a testing settings file" % os.environ['DJANGO_SETTINGS_MODULE']
sys.exit(1)
-def find_module(modname):
- p = modname.rfind('.')
- if p >= 0:
- mod = __import__(modname[:p], {}, {}, [modname[p+1:]])
- mod = getattr(mod, modname[p+1:])
- else:
- mod = __import__(modname, {}, {}, [])
- return mod
-
(opts, args) = getopt.getopt(sys.argv[1:], 'a:pc:Cr:')
app_label = None
@@ -40,13 +30,12 @@
reset = []
try:
- from django.conf.settings import REINSTALL_APPS
-except ImportError:
+ REINSTALL_APPS = settings.REINSTALL_APPS
+except AttributeError:
REINSTALL_APPS = ()
for app_label in REINSTALL_APPS:
- mod = find_module('dmango.models.'+app_label)
- reset.append(mod)
+ reset.append(__import__(app_label, {}, {}, [app_label]))
for (o, v) in opts:
if o == '-a':
@@ -56,11 +45,9 @@
elif o == '-C':
cover_context = True
elif o == '-c':
- mod = find_module(v)
- cover.append(mod)
+ cover.append(__import__(v, {}, {}, [v]))
elif o == '-r':
- mod = find_module('django.models.'+v)
- reset.append(mod)
+ reset.append(__import__(v, {}, {}, [v]))
if (app_label is None and project is False) or len(args) == 0:
print
@@ -90,26 +77,12 @@
path = None
mod = None
-apps = {}
if app_label:
- mod = __import__('django.models', {}, {}, [app_label])
- mod = getattr(mod, app_label)
+ mod = __import__(app_label, {}, {}, [app_label])
+ if app_label in settings.INSTALLED_APPS:
+ path = os.path.dirname(mod.__file__)
-for a in INSTALLED_APPS:
- p = a.rfind('.')
- if p >= 0:
- app = __import__(a[:p], {}, {}, [a[p+1:]])
- app = getattr(app, a[p+1:])
- apps[a[p+1:]] = True
- else:
- app = __import__(a, {}, {}, [])
- apps[a] = True
- p = os.path.dirname(app.__file__)
- if app_label and mod.__file__.startswith(p):
- path = p
- break
-
if project:
mod = __import__(os.environ['DJANGO_SETTINGS_MODULE'], {}, {}, [])
path = os.path.dirname(mod.__file__)
@@ -119,8 +92,7 @@
sys.exit(8)
if cover_context:
- if project: base = mod.__name__
- else: base = app.__name__
+ base = mod.__name__
for dp, dn, fn in os.walk(path):
todel = []
for idx, d in enumerate(dn):
@@ -155,13 +127,13 @@
sql_all_list = []
for mod in reset:
sql_all_list.append(get_sql_all(mod))
- cursor = db.db.cursor()
+ cursor = db.connection.cursor()
for sql in sql_del_list:
cursor.execute(sql)
for sql_list in reversed(sql_all_list):
for sql in sql_list:
cursor.execute(sql)
- db.db.commit()
+ db.connection.commit()
if cover:
coverage.erase()
coverage.start()