summaryrefslogtreecommitdiff
path: root/objectapp/views
diff options
context:
space:
mode:
authorgnowgi <nagarjun@gnowledge.org>2012-03-15 16:19:20 +0530
committergnowgi <nagarjun@gnowledge.org>2012-03-15 16:19:20 +0530
commit7a4f561e851fdc7246d804c3abb6748b8a4199a6 (patch)
treed2afc3463fd49625a9be482012f5c3bfcf7c42b9 /objectapp/views
downloadgnowsys-7a4f561e851fdc7246d804c3abb6748b8a4199a6.tar.gz
master trunk of gnowsys-studio
Diffstat (limited to 'objectapp/views')
-rw-r--r--objectapp/views/__init__.py1
-rw-r--r--objectapp/views/add.py126
-rw-r--r--objectapp/views/authors.py92
-rw-r--r--objectapp/views/channels.py58
-rw-r--r--objectapp/views/decorators.py151
-rw-r--r--objectapp/views/gbobjects.py99
-rw-r--r--objectapp/views/objecttypes.py94
-rw-r--r--objectapp/views/quick_gbobject.py118
-rw-r--r--objectapp/views/search.py91
-rw-r--r--objectapp/views/sitemap.py77
-rw-r--r--objectapp/views/tags.py97
-rw-r--r--objectapp/views/trackback.py109
12 files changed, 1113 insertions, 0 deletions
diff --git a/objectapp/views/__init__.py b/objectapp/views/__init__.py
new file mode 100644
index 00000000..a16657d9
--- /dev/null
+++ b/objectapp/views/__init__.py
@@ -0,0 +1 @@
+"""Views for Objectapp"""
diff --git a/objectapp/views/add.py b/objectapp/views/add.py
new file mode 100644
index 00000000..362c3d30
--- /dev/null
+++ b/objectapp/views/add.py
@@ -0,0 +1,126 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+from django.http import HttpResponse
+from django.http import HttpResponseRedirect
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+from datetime import datetime
+from objectapp.forms import *
+
+
+def addgbobject(request):
+ if request.method == 'POST':
+ formset = GbobjectForm(request.POST)
+ if formset.is_valid():
+ formset.save()
+ return HttpResponseRedirect("/objects/")
+
+
+
+ else:
+
+ formset = GbobjectForm()
+
+
+ variables = RequestContext(request,{'formset':formset})
+ template = "objectappforms/gbobjectform.html"
+ return render_to_response(template, variables)
+
+
+def addprocess(request):
+ if request.method == 'POST':
+ formset = ProcessForm(request.POST)
+ if formset.is_valid():
+ formset.save()
+ return HttpResponseRedirect("/objects/")
+
+
+
+ else:
+
+ formset = ProcessForm()
+
+
+ variables = RequestContext(request,{'formset':formset})
+ template = "objectappforms/processform.html"
+ return render_to_response(template, variables)
+
+def addsystem(request):
+ if request.method == 'POST':
+ formset = ProcessForm(request.POST)
+ if formset.is_valid():
+ formset.save()
+ return HttpResponseRedirect("/objects/")
+
+
+
+ else:
+
+ formset = SystemForm()
+
+
+ variables = RequestContext(request,{'formset':formset})
+ template = "objectappforms/systemform.html"
+ return render_to_response(template, variables)
diff --git a/objectapp/views/authors.py b/objectapp/views/authors.py
new file mode 100644
index 00000000..a6b77451
--- /dev/null
+++ b/objectapp/views/authors.py
@@ -0,0 +1,92 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp authors"""
+from django.shortcuts import get_object_or_404
+from django.views.generic.list_detail import object_list
+
+from objectapp.models import Author
+from objectapp.settings import PAGINATION
+from objectapp.views.decorators import update_queryset
+from objectapp.views.decorators import template_name_for_gbobject_queryset_filtered
+
+
+author_list = update_queryset(object_list, Author.published.all)
+
+
+def author_detail(request, username, page=None, **kwargs):
+ """Display the gbobjects of an author"""
+ extra_context = kwargs.pop('extra_context', {})
+
+ author = get_object_or_404(Author, username=username)
+ if not kwargs.get('template_name'):
+ kwargs['template_name'] = template_name_for_gbobject_queryset_filtered(
+ 'author', author.username)
+
+ extra_context.update({'author': author})
+ kwargs['extra_context'] = extra_context
+
+ return object_list(request, queryset=author.gbobjects_published(),
+ paginate_by=PAGINATION, page=page,
+ **kwargs)
diff --git a/objectapp/views/channels.py b/objectapp/views/channels.py
new file mode 100644
index 00000000..bc842a09
--- /dev/null
+++ b/objectapp/views/channels.py
@@ -0,0 +1,58 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+"""Views for Objectapp channels"""
+from django.views.generic.list_detail import object_list
+
+from objectapp.models import Gbobject
+
+
+def gbobject_channel(request, query, *ka, **kw):
+ """Display a custom selection of gbobjects"""
+ queryset = Gbobject.published.search(query)
+ return object_list(request, queryset=queryset,
+ *ka, **kw)
diff --git a/objectapp/views/decorators.py b/objectapp/views/decorators.py
new file mode 100644
index 00000000..cdc72033
--- /dev/null
+++ b/objectapp/views/decorators.py
@@ -0,0 +1,151 @@
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Decorators for objectapp.views"""
+from functools import wraps
+
+from django.template import RequestContext
+from django.contrib.auth.views import login
+from django.shortcuts import redirect
+from django.shortcuts import get_object_or_404
+from django.shortcuts import render_to_response
+from django.template.loader import get_template
+from django.template import TemplateDoesNotExist
+from django.views.decorators.csrf import csrf_protect
+from django.views.decorators.cache import never_cache
+
+
+def update_queryset(view, queryset,
+ queryset_parameter='queryset'):
+ """Decorator around views based on a queryset
+ passed in parameter, who will force the update
+ of the queryset before executing the view.
+ Related to issue http://code.djangoproject.com/ticket/8378"""
+
+ @wraps(view)
+ def wrapper(*args, **kwargs):
+ """Regenerate the queryset before passing it to the view."""
+ kwargs[queryset_parameter] = queryset()
+ return view(*args, **kwargs)
+
+ return wrapper
+
+
+@csrf_protect
+@never_cache
+def password(request, gbobject):
+ """Displays the password form and handle validation
+ by setting the valid password in a cookie."""
+ error = False
+ if request.method == 'POST':
+ if request.POST.get('password') == gbobject.password:
+ request.session[
+ 'objectapp_gbobject_%s_password' % gbobject.pk] = gbobject.password
+ return redirect(gbobject)
+ error = True
+ return render_to_response('objectapp/password.html', {'error': error},
+ context_instance=RequestContext(request))
+
+
+def protect_gbobject(view):
+ """Decorator performing a security check if needed
+ around the generic.date_based.gbobject_detail view
+ and specify the template used to render the gbobject"""
+
+ @wraps(view)
+ def wrapper(*ka, **kw):
+ """Do security check and retrieve the template"""
+ request = ka[0]
+ gbobject = get_object_or_404(kw['queryset'], slug=kw['slug'],
+ creation_date__year=kw['year'],
+ creation_date__month=kw['month'],
+ creation_date__day=kw['day'])
+
+ if gbobject.login_required and not request.user.is_authenticated():
+ return login(request, 'objectapp/login.html')
+ if gbobject.password and gbobject.password != \
+ request.session.get('objectapp_gbobject_%s_password' % gbobject.pk):
+ return password(request, gbobject)
+ kw['template_name'] = gbobject.template
+ return view(*ka, **kw)
+
+ return wrapper
+
+
+def template_name_for_gbobject_queryset_filtered(model_type, model_name):
+ """Return a custom template name for views
+ returning a queryset of Gbobject filtered by another model."""
+ template_name_list = (
+ 'objectapp/%s/%s/gbobject_list.html' % (model_type, model_name),
+ 'objectapp/%s/%s_gbobject_list.html' % (model_type, model_name),
+ 'objectapp/%s/gbobject_list.html' % model_type,
+ 'objectapp/gbobject_list.html')
+
+ for template_name in template_name_list:
+ try:
+ get_template(template_name)
+ return template_name
+ except TemplateDoesNotExist:
+ continue
diff --git a/objectapp/views/gbobjects.py b/objectapp/views/gbobjects.py
new file mode 100644
index 00000000..9662c97e
--- /dev/null
+++ b/objectapp/views/gbobjects.py
@@ -0,0 +1,99 @@
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+#
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp gbobjects"""
+from django.shortcuts import redirect
+from django.shortcuts import get_object_or_404
+from django.views.generic.list_detail import object_list
+from django.views.generic.date_based import archive_year
+from django.views.generic.date_based import archive_month
+from django.views.generic.date_based import archive_day
+from django.views.generic.date_based import object_detail
+
+from objectapp.models import Gbobject
+from objectapp.views.decorators import protect_gbobject
+from objectapp.views.decorators import update_queryset
+
+
+gbobject_index = update_queryset(object_list, Gbobject.published.all)
+
+gbobject_year = update_queryset(archive_year, Gbobject.published.all)
+
+gbobject_month = update_queryset(archive_month, Gbobject.published.all)
+
+gbobject_day = update_queryset(archive_day, Gbobject.published.all)
+
+gbobject_detail = protect_gbobject(object_detail)
+
+
+def gbobject_shortlink(request, object_id):
+ """
+ Redirect to the 'get_absolute_url' of an Gbobject,
+ accordingly to 'object_id' argument
+ """
+ gbobject = get_object_or_404(Gbobject, pk=object_id)
+ return redirect(gbobject, permanent=True)
diff --git a/objectapp/views/objecttypes.py b/objectapp/views/objecttypes.py
new file mode 100644
index 00000000..f64704fd
--- /dev/null
+++ b/objectapp/views/objecttypes.py
@@ -0,0 +1,94 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp objecttypes"""
+from django.shortcuts import get_object_or_404
+from django.views.generic.list_detail import object_list
+
+from objectapp.models import Objecttype
+from objectapp.settings import PAGINATION
+from objectapp.views.decorators import template_name_for_gbobject_queryset_filtered
+
+
+def get_Objecttype_or_404(path):
+ """Retrieve a Objecttype by a path"""
+ path_bits = [p for p in path.split('/') if p]
+ return get_object_or_404(Objecttype, slug=path_bits[-1])
+
+
+def Objecttype_detail(request, path, page=None, **kwargs):
+ """Display the gbobjects of a Objecttype"""
+ extra_context = kwargs.pop('extra_context', {})
+
+ Objecttype = get_Objecttype_or_404(path)
+ if not kwargs.get('template_name'):
+ kwargs['template_name'] = template_name_for_gbobject_queryset_filtered(
+ 'Objecttype', Objecttype.slug)
+
+ extra_context.update({'Objecttype': Objecttype})
+ kwargs['extra_context'] = extra_context
+
+ return object_list(request, queryset=Objecttype.gbobjects_published(),
+ paginate_by=PAGINATION, page=page,
+ **kwargs)
diff --git a/objectapp/views/quick_gbobject.py b/objectapp/views/quick_gbobject.py
new file mode 100644
index 00000000..0fca2ee9
--- /dev/null
+++ b/objectapp/views/quick_gbobject.py
@@ -0,0 +1,118 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp quick gbobject"""
+from urllib import urlencode
+
+from django import forms
+from django.utils.html import linebreaks
+from django.shortcuts import redirect
+from django.core.urlresolvers import reverse
+from django.contrib.sites.models import Site
+from django.template.defaultfilters import slugify
+from django.utils.encoding import smart_str
+from django.contrib.auth.decorators import permission_required
+
+from objectapp.models import Gbobject
+from objectapp.managers import DRAFT
+from objectapp.managers import PUBLISHED
+
+
+class QuickGbobjectForm(forms.Form):
+ """Form for posting an gbobject quickly"""
+
+ title = forms.CharField(required=True, max_length=255)
+ content = forms.CharField(required=True)
+ tags = forms.CharField(required=False, max_length=255)
+
+
+@permission_required('objectapp.add_gbobject')
+def view_quick_gbobject(request):
+ """View for quickly post an Gbobject"""
+ if request.POST:
+ form = QuickGbobjectForm(request.POST)
+ if form.is_valid():
+ gbobject_dict = form.cleaned_data
+ status = PUBLISHED
+ if 'save_draft' in request.POST:
+ status = DRAFT
+ gbobject_dict['content'] = linebreaks(gbobject_dict['content'])
+ gbobject_dict['slug'] = slugify(gbobject_dict['title'])
+ gbobject_dict['status'] = status
+ gbobject = Gbobject.objects.create(**gbobject_dict)
+ gbobject.sites.add(Site.objects.get_current())
+ gbobject.authors.add(request.user)
+ return redirect(gbobject)
+
+ data = {'title': smart_str(request.POST.get('title', '')),
+ 'content': smart_str(linebreaks(request.POST.get(
+ 'content', ''))),
+ 'tags': smart_str(request.POST.get('tags', '')),
+ 'slug': slugify(request.POST.get('title', '')),
+ 'authors': request.user.pk,
+ 'sites': Site.objects.get_current().pk}
+ return redirect('%s?%s' % (reverse('admin:objectapp_gbobject_add'),
+ urlencode(data)))
+
+ return redirect('admin:objectapp_gbobject_add')
diff --git a/objectapp/views/search.py b/objectapp/views/search.py
new file mode 100644
index 00000000..bb9fe9df
--- /dev/null
+++ b/objectapp/views/search.py
@@ -0,0 +1,91 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp gbobjects search"""
+from django.utils.translation import ugettext as _
+from django.views.generic.list_detail import object_list
+
+from objectapp.models import Gbobject
+from objectapp.settings import PAGINATION
+
+
+def gbobject_search(request):
+ """Search gbobjects matching with a pattern"""
+ error = None
+ pattern = None
+ gbobjects = Gbobject.published.none()
+
+ if request.GET:
+ pattern = request.GET.get('pattern', '')
+ if len(pattern) < 3:
+ error = _('The pattern is too short')
+ else:
+ gbobjects = Gbobject.published.search(pattern)
+ else:
+ error = _('No pattern to search found')
+
+ return object_list(request, queryset=gbobjects,
+ paginate_by=PAGINATION,
+ template_name='objectapp/gbobject_search.html',
+ extra_context={'error': error,
+ 'pattern': pattern})
diff --git a/objectapp/views/sitemap.py b/objectapp/views/sitemap.py
new file mode 100644
index 00000000..2c9ebbc2
--- /dev/null
+++ b/objectapp/views/sitemap.py
@@ -0,0 +1,77 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp sitemap"""
+from django.views.generic.simple import direct_to_template
+
+from objectapp.models import Gbobject
+from objectapp.models import Objecttype
+
+
+def sitemap(*ka, **kw):
+ """Wrapper around the direct to template generic view to
+ force the update of the extra context"""
+ kw['extra_context'] = {'gbobjects': Gbobject.published.all(),
+ 'objecttypes': Objecttype.tree.all()}
+ return direct_to_template(*ka, **kw)
diff --git a/objectapp/views/tags.py b/objectapp/views/tags.py
new file mode 100644
index 00000000..33ada35b
--- /dev/null
+++ b/objectapp/views/tags.py
@@ -0,0 +1,97 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp tags"""
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+from django.template.defaultfilters import slugify
+
+from tagging.models import Tag
+from tagging.views import tagged_object_list
+
+from objectapp.models import Gbobject
+from objectapp.settings import PAGINATION
+
+from objectapp.views.decorators import template_name_for_gbobject_queryset_filtered
+
+
+def tag_list(request, template_name='objectapp/tag_list.html'):
+ """Return the list of published tags with counts,
+ try to simulate an object_list view"""
+ tag_list = Tag.objects.usage_for_queryset(
+ Gbobject.published.all(), counts=True)
+ return render_to_response(template_name, {'object_list': tag_list},
+ context_instance=RequestContext(request))
+
+
+def tag_detail(request, tag, page=None, **kwargs):
+ """Display the gbobjects of a tag"""
+ if not kwargs.get('template_name'):
+ kwargs['template_name'] = template_name_for_gbobject_queryset_filtered(
+ 'tag', slugify(tag))
+
+ return tagged_object_list(request, tag=tag,
+ queryset_or_model=Gbobject.published.all(),
+ paginate_by=PAGINATION, page=page,
+ **kwargs)
diff --git a/objectapp/views/trackback.py b/objectapp/views/trackback.py
new file mode 100644
index 00000000..932f575c
--- /dev/null
+++ b/objectapp/views/trackback.py
@@ -0,0 +1,109 @@
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This project incorporates work covered by the following copyright and permission notice:
+
+# Copyright (c) 2009, Julien Fache
+# All rights reserved.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the author nor the names of other
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Copyright (c) 2011, 2012 Free Software Foundation
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+"""Views for Objectapp trackback"""
+from django.shortcuts import redirect
+from django.shortcuts import get_object_or_404
+from django.contrib.sites.models import Site
+from django.contrib import comments
+from django.views.decorators.csrf import csrf_exempt
+from django.contrib.contenttypes.models import ContentType
+from django.views.generic.simple import direct_to_template
+
+from objectapp.models import Gbobject
+
+
+@csrf_exempt
+def gbobject_trackback(request, object_id):
+ """Set a TrackBack for an Gbobject"""
+ gbobject = get_object_or_404(Gbobject.published, pk=object_id)
+
+ if request.POST.get('url'):
+ error = ''
+ url = request.POST['url']
+ site = Site.objects.get_current()
+
+ if not gbobject.pingback_enabled:
+ error = u'Trackback is not enabled for %s' % gbobject.title
+
+ title = request.POST.get('title') or url
+ excerpt = request.POST.get('excerpt') or title
+ blog_name = request.POST.get('blog_name') or title
+
+ if not error:
+ comment, created = comments.get_model().objects.get_or_create(
+ content_type=ContentType.objects.get_for_model(Gbobject),
+ object_pk=gbobject.pk, site=site, user_url=url,
+ user_name=blog_name, defaults={'comment': excerpt})
+ if created:
+ user = gbobject.authors.all()[0]
+ comment.flags.create(user=user, flag='trackback')
+ else:
+ error = u'Trackback is already registered'
+
+ return direct_to_template(request, 'objectapp/gbobject_trackback.xml',
+ mimetype='text/xml',
+ extra_context={'error': error})
+
+ return redirect(gbobject, permanent=True)