diff options
author | Anuja <anujag@anujag-Latitude-D630.(none)> | 2012-03-21 17:34:34 +0530 |
---|---|---|
committer | Anuja <anujag@anujag-Latitude-D630.(none)> | 2012-03-21 17:34:34 +0530 |
commit | 874fceac6498f2ba733c433b964f9ce5975d6a69 (patch) | |
tree | aee7c168a44287d5b8ec22582d654b970eb6108e /gstudio | |
parent | 9d76c138b63828b549b33fe1b9a8ad4ab3dd8d86 (diff) | |
download | gnowsys-874fceac6498f2ba733c433b964f9ce5975d6a69.tar.gz |
Changes made on model files and search files
Diffstat (limited to 'gstudio')
-rw-r--r-- | gstudio/__init__.pyc | bin | 0 -> 378 bytes | |||
-rw-r--r-- | gstudio/admin/objecttype.py | 1 | ||||
-rw-r--r-- | gstudio/managers.py | 48 | ||||
-rw-r--r-- | gstudio/models.py | 51 | ||||
-rw-r--r-- | gstudio/search.py | 10 | ||||
-rw-r--r-- | gstudio/templates/gstudio/base.html | 4 |
6 files changed, 86 insertions, 28 deletions
diff --git a/gstudio/__init__.pyc b/gstudio/__init__.pyc Binary files differnew file mode 100644 index 00000000..9f1566a8 --- /dev/null +++ b/gstudio/__init__.pyc diff --git a/gstudio/admin/objecttype.py b/gstudio/admin/objecttype.py index 22ef2059..c98a0d78 100644 --- a/gstudio/admin/objecttype.py +++ b/gstudio/admin/objecttype.py @@ -33,6 +33,7 @@ class ObjecttypeAdmin(reversion.VersionAdmin): 'classes': ('collapse', 'collapse-closed')}), (_('Options'), {'fields': ('featured', 'excerpt', 'template', 'authors', + 'rurl', 'creation_date', 'start_publication', 'end_publication'), diff --git a/gstudio/managers.py b/gstudio/managers.py index 5922327f..f05a9255 100644 --- a/gstudio/managers.py +++ b/gstudio/managers.py @@ -79,6 +79,54 @@ class AuthorPublishedManager(models.Manager): nodetypes__sites=Site.objects.get_current() ).distinct() +def nodes_published(queryset): + + """Return only the nodetypes published""" + now = datetime.now() + return queryset.filter(status=PUBLISHED, + start_publication__lte=now, + end_publication__gt=now, + sites=Site.objects.get_current()) + +class NodePublishedManager(models.Manager): + """Manager to retrieve published nodes""" + + def get_query_set(self): + """Return published nodes""" + return nodes_published( + super(NodePublishedManager, self).get_query_set()) + + def on_site(self): + """Return nodes published on current site""" + return super(NodePublishedManager, self).get_query_set( + ).filter(sites=Site.objects.get_current()) + + def search(self, pattern): + """Top level search method on nodes""" + try: + return self.advanced_search(pattern) + except: + return self.basic_search(pattern) + + def advanced_search(self, pattern): + """Advanced search on nodes""" + from gstudio.search import advanced_search + return advanced_search(pattern) + + def basic_search(self, pattern): + """Basic search on nodes""" + lookup = None + for pattern in pattern.split(): + query_part = models.Q(title__icontains=pattern) + ''' models.Q(content__icontains=pattern) | \ + models.Q(excerpt__icontains=pattern) | \ ''' + if lookup is None: + lookup = query_part + else: + lookup |= query_part + + return self.get_query_set().filter(lookup) + def nodetypes_published(queryset): diff --git a/gstudio/models.py b/gstudio/models.py index 885b345e..c145ab0d 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -95,6 +95,7 @@ from gstudio.settings import MARKDOWN_EXTENSIONS from gstudio.settings import AUTO_CLOSE_COMMENTS_AFTER from gstudio.managers import nodetypes_published from gstudio.managers import NodetypePublishedManager +from gstudio.managers import NodePublishedManager from gstudio.managers import AuthorPublishedManager from gstudio.managers import DRAFT, HIDDEN, PUBLISHED from gstudio.moderator import NodetypeCommentModerator @@ -212,15 +213,26 @@ class NID(models.Model): """ return self.__dict__ + @property + def get_app_name(self): + if self.ref.__class__.__name__=='Gbobject' or self.ref.__class__.__name__=='Process' or self.ref.__class__.__name__=='System' : + return 'type' + @models.permalink def get_absolute_url(self): """Return nodetype's URL""" - - return ('gstudio_nodetype_detail', (), { - 'year': self.creation_date.strftime('%Y'), - 'month': self.creation_date.strftime('%m'), - 'day': self.creation_date.strftime('%d'), - 'slug': self.slug}) + if self.get_app_name=='type': + return ('objectapp_gbobject_detail', (), { + 'year': self.creation_date.strftime('%Y'), + 'month': self.creation_date.strftime('%m'), + 'day': self.creation_date.strftime('%d'), + 'slug': self.slug}) + else: + return ('gstudio_nodetype_detail', (), { + 'year': self.creation_date.strftime('%Y'), + 'month': self.creation_date.strftime('%m'), + 'day': self.creation_date.strftime('%d'), + 'slug': self.slug}) @property def ref(self): @@ -273,7 +285,17 @@ class Node(NID): altnames = TagField(_('alternate names'), help_text=_('alternate names if any'), blank=True, null=True) plural = models.CharField(_('plural name'), help_text=_('plural form of the node name if any'), max_length=255, blank=True, null=True) rating = RatingField(range=5, can_change_vote = True, help_text=_('your rating'), blank=True, null=True) + status = models.IntegerField(choices=STATUS_CHOICES, default=PUBLISHED) + start_publication = models.DateTimeField(_('start publication'), + help_text=_('date start publish'), + default=datetime.now) + end_publication = models.DateTimeField(_('end publication'), + help_text=_('date end publish'), + default=datetime(2042, 3, 15)) + sites = models.ManyToManyField(Site, verbose_name=_('sites publication'), + related_name='nodetypes') + published = NodePublishedManager() def __unicode__(self): return self.title @@ -514,24 +536,9 @@ class Nodetype(Node): related_name='nodetypes', blank=True, null=False) - status = models.IntegerField(choices=STATUS_CHOICES, default=PUBLISHED) - featured = models.BooleanField(_('featured'), default=False) comment_enabled = models.BooleanField(_('comment enabled'), default=True) pingback_enabled = models.BooleanField(_('linkback enabled'), default=True) - - - - start_publication = models.DateTimeField(_('start publication'), - help_text=_('date start publish'), - default=datetime.now) - end_publication = models.DateTimeField(_('end publication'), - help_text=_('date end publish'), - default=datetime(2042, 3, 15)) - - sites = models.ManyToManyField(Site, verbose_name=_('sites publication'), - related_name='nodetypes') - login_required = models.BooleanField( _('login required'), default=False, help_text=_('only authenticated users can view the nodetype')) @@ -545,7 +552,7 @@ class Nodetype(Node): choices=[('gstudio/nodetype_detail.html', _('Default template'))] + \ NODETYPE_TEMPLATES, help_text=_('template used to display the nodetype')) - + rurl=models.URLField(_('rurl'),verify_exists=True,null=True, blank=True) objects = models.Manager() published = NodetypePublishedManager() diff --git a/gstudio/search.py b/gstudio/search.py index adbb0370..7312ad66 100644 --- a/gstudio/search.py +++ b/gstudio/search.py @@ -64,7 +64,7 @@ from pyparsing import operatorPrecedence from django.db.models import Q -from gstudio.models import Nodetype +from gstudio.models import Node from gstudio.settings import STOP_WORDS @@ -96,9 +96,9 @@ def createQ(token): return Q() if not meta: - return Q(content__icontains=search) | \ - Q(excerpt__icontains=search) | \ - Q(title__icontains=search) + return Q(title__icontains=search) + ''' Q(content__icontains=search) | \ + Q(excerpt__icontains=search) | \ ''' if meta == 'metatype': if wildcards == 'BOTH': @@ -178,4 +178,4 @@ def advanced_search(pattern): """Parse the grammar of a pattern and build a queryset with it""" query_parsed = QUERY.parseString(pattern) - return Nodetype.published.filter(query_parsed[0]).distinct() + return Node.published.filter(query_parsed[0]).distinct() diff --git a/gstudio/templates/gstudio/base.html b/gstudio/templates/gstudio/base.html index 2c612e19..94a72eb8 100644 --- a/gstudio/templates/gstudio/base.html +++ b/gstudio/templates/gstudio/base.html @@ -25,7 +25,7 @@ <div class="search"> <h3>{% trans "Search" %}</h3> - <form method="get" id="searchform" action="{% url objectapp_gbobject_search %}"> + <form method="get" id="searchform" action="{% url nodes_search %}"> <p> <input type="text" value="{% trans "Keywords..." %}" name="pattern" id="searchbox" onfocus="this.value=''" /> <input type="submit" class="submitbutton" value="OK" /> @@ -35,10 +35,12 @@ </p> </form> </div> +<!-- <div class="objecttypes"> <h3>{% trans "Objecttypes" %}</h3> {% get_objecttypes %} </div> +--> <div class="authors"> <h3>{% trans "Authors" %}</h3> {% get_authors %} |