Skip to content

Commit 0f47fa6

Browse files
committed
temp working commit
1 parent 5b9f6e6 commit 0f47fa6

File tree

11 files changed

+95
-12
lines changed

11 files changed

+95
-12
lines changed

djity/project/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def update_context(self,context):
204204
# if no module name is declared we are in the project's context
205205
# for example the request might be for project.css
206206
# in this case permissions are asked for a current status of public
207-
if context['module_name'] is None:
207+
if not 'module' in context:
208208
context['perm'] = granted_perms(context['role'],settings.PUBLIC)
209209

210210
# get hierarchy of parent projects

djity/project/urls.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from djity.simplepage.urls import urlpatterns as simplepage_urls
55
from djity.style.urls import urlpatterns as css_urls
6+
from djity.search.urls import urlpatterns as search_urls
67
from djity.utils import djity_modules
78

89
from django.utils.importlib import import_module
@@ -16,14 +17,15 @@
1617
url(r'^forbidden/*$','djity.project.views.forbidden',name='forbidden'),
1718
)
1819

19-
2020
urlpatterns = patterns('',
2121
# project page redirect to the first tab
2222
url(r'^(?P<project_name>[-\w]+)/*$','djity.project.views.first_tab',name='first_tab'),
23-
# login view as a pseudo application
23+
# login and navigation views as a pseudo applications
2424
(r'^(?P<project_name>[-\w]+)/',include(portal_urls)),
25-
# all other urls are handled by djity.modules.simple_page
25+
# css as a pseudo application too
2626
(r'^(?P<project_name>[-\w]+)/css/',include(css_urls)),
27+
# and search also
28+
(r'^(?P<project_name>[-\w]+)/search/',include(search_urls)),
2729
)
2830

2931
#import urls from djity applications

djity/project_skeleton/urls.py_tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ urlpatterns = patterns('',
1414

1515
(r'^localeurl/', include('localeurl.urls')),
1616

17-
1817
(r'^%s/' % settings.DAJAXICE_MEDIA_PREFIX, include('dajaxice.urls')),
1918

2019
(r'^jsi18n/', 'django.views.i18n.javascript_catalog',{{ 'packages': ('djity')}}),

djity/search/__init__.py

Whitespace-only changes.

djity/search/forms.py

Whitespace-only changes.

djity/search/urls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.conf.urls.defaults import *
2+
from djity.search.views import project_search
3+
4+
urlpatterns = patterns('djity.search.views',
5+
url(r'^$', project_search, name='project_search'),
6+
)

djity/search/views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from haystack.views import basic_search
2+
from haystack.forms import ModelSearchForm
3+
from haystack.query import SearchQuerySet
4+
from djity.utils.decorators import djity_view
5+
from djity.utils.context import DjityContext
6+
7+
@djity_view(perm='view')
8+
def project_search(request,context=None):
9+
"""
10+
Override haystack basic_view for customization
11+
"""
12+
#sqs = SearchQuerySet().filter(project=context['project'])
13+
return basic_search(request, template='djity/search/search.html', extra_context=context, context_class=DjityContext)

djity/simplepage/search_indexes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from haystack.indexes import *
2+
from haystack import site
3+
4+
from djity.simplepage.models import SimplePage
5+
6+
class SimplePageIndex(SearchIndex):
7+
text = CharField(document=True, model_attr='content')
8+
project = CharField(model_attr='project')
9+
10+
site.register(SimplePage, SimplePageIndex)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% extends "djity/base.html" %}
2+
3+
{% block body %}
4+
<h2>Search</h2>
5+
6+
<form method="get" action=".">
7+
<table>
8+
{{ form.as_table }}
9+
<tr>
10+
<td>&nbsp;</td>
11+
<td>
12+
<input type="submit" value="Search">
13+
</td>
14+
</tr>
15+
</table>
16+
17+
{% if query %}
18+
<h3>Results</h3>
19+
20+
{% for result in page.object_list %}
21+
<p>
22+
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
23+
</p>
24+
{% empty %}
25+
<p>No results found.</p>
26+
{% endfor %}
27+
28+
{% if page.has_previous or page.has_next %}
29+
<div>
30+
{% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
31+
|
32+
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
33+
</div>
34+
{% endif %}
35+
{% else %}
36+
{# Show some example queries to run, maybe query syntax, something else? #}
37+
{% endif %}
38+
</form>
39+
{% endblock %}

djity/utils/context.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class JSONContext():
1111
def __init__(self,context):
1212
self.context = context
1313
def __repr__(self):
14-
return json.dumps(dict([(k,self.context[k]) for k in self.context._marked_as_json if k != 'json_context']),cls=DjityJSONEncoder)
14+
return json.dumps(dict([(k,self.context[k]) for k in self.context._marked_as_json if (k != 'json_context' and k in self.context)]),cls=DjityJSONEncoder)
1515

1616
class DjityContext(RequestContext):
1717

@@ -28,6 +28,14 @@ def __setitem__(self,key,value):
2828
RequestContext.__setitem__(self,key,value)
2929
self._marked_as_json.add(key)
3030

31+
def __delitem__(self,key):
32+
RequestContext.__delitem__(key)
33+
del self._marked_as_json[key]
34+
35+
def __iter__(self):
36+
for k in self._marked_as_json:
37+
yield (k,self[k])
38+
3139
def mark_as_json(self,attr_name):
3240
self._marked_as_json.add(attr_name)
3341

djity/utils/decorators.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import logging
44

55
from django.http import HttpResponse,HttpResponseNotFound,HttpResponseForbidden,HttpResponseRedirect, Http404
6+
from django.shortcuts import render, render_to_response
67
from django.conf import settings
78
from django.utils.translation import ugettext_lazy as _
89
from django.contrib.auth import REDIRECT_FIELD_NAME
910
from django.utils.http import urlquote
1011
from django.contrib import messages
1112
from django.core.urlresolvers import reverse
1213

13-
from django.template import RequestContext
14+
from django.template import RequestContext, loader
1415
from djity.utils.context import DjityContext, JSTarget
1516

1617
from djity.project.models import Project
@@ -91,10 +92,6 @@ def _new_func(*args,**kwargs):
9192
# actually permissions are resolved here
9293
project.update_context(context)
9394

94-
# if module was not found by projet.update_context() raise 404
95-
if module_name and not 'module' in context:
96-
return HttpResponseRedirect(djreverse('page_not_found',context))
97-
9895
# if the user is not allowed to use this view, redirect or ask for
9996
# authentication of return error
10097
if not perm in context['perm']:
@@ -117,7 +114,16 @@ def _new_func(*args,**kwargs):
117114
context['info_message'] = request.GET['info_message']
118115

119116
kwargs['context'] = context
120-
117+
118+
# if module was not found by projet.update_context() raise 404
119+
if module_name and not 'module' in context:
120+
context.message(_("This page does not exist on this project !"))
121+
context["module"] = {'label':_('Page not found')}
122+
return render_to_response('djity/base.html',context)
123+
#t = loader.get_template('djity/base.html')
124+
#r = t.render(context)
125+
#return HttpResponseNotFound(r)
126+
121127
if 'js_target' in context:
122128
func(*args,**kwargs)
123129
return context['js_target'].json()

0 commit comments

Comments
 (0)