combo-plugin-gnm/combo_plugin_gnm/views.py

46 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# combo-plugin-gnm - Combo GNM plugin
# Copyright (C) 2017 Entr'ouvert
#
# 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.conf import settings
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.template import RequestContext
from combo.utils import requests, get_templated_url
def plusone(request, *args, **kwargs):
# add reference to a jsondatastore with slug "plus1"
reference = request.GET.get('ref')
if reference:
context = RequestContext(request, {'request': request})
passerelle_url = '[passerelle_url]jsondatastore/plus1/data/create'
if request.user and request.user.is_authenticated():
passerelle_url += '?name_id=[user_nameid]'
passerelle_url = get_templated_url(passerelle_url, context)
headers = {'content-type': 'application/json'}
requests.post(passerelle_url, remote_service='auto',
without_user=True,
headers={'Accept': 'application/json'},
json={'reference': reference},
timeout=2)
messages.info(request, u'Merci, votre confirmation nous est utile.')
if request.user and request.user.is_authenticated():
return HttpResponseRedirect('/')
else:
return HttpResponseRedirect('/services/')