general: add contacts app

This commit is contained in:
Frédéric Péters 2015-07-18 20:33:48 +02:00
parent 115e810db1
commit 699e4ac86e
8 changed files with 64 additions and 11 deletions

View File

@ -8,6 +8,7 @@ recursive-include welco/sources/mail/static *.css *.js *.ico *.gif *.png *.jpg
# templates
recursive-include welco/templates *.html
recursive-include welco/kb/templates *.html
recursive-include welco/contacts/templates *.html
recursive-include welco/sources/mail/templates *.html
include COPYING README

View File

View File

@ -0,0 +1,9 @@
{% load i18n %}
<div data-page-fragment-url="{% url 'contacts-zone' %}/">
<div class="search">
<input type="text" autocomplete="off" placeholder="{% trans 'Name, phone, etc.' %}" data-autocomplete-json="{% url 'contacts-search-json' %}" name="q"/>
<ul class="result">
</ul>
</div>
<button>{% trans 'Create new contact' %}</button>
</div>

47
welco/contacts/views.py Normal file
View File

@ -0,0 +1,47 @@
# welco - multichannel request processing
# Copyright (C) 2015 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 import template
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
class HomeZone(object):
def __init__(self, request):
self.request = request
def render(self):
context = RequestContext(self.request)
tmpl = template.loader.get_template('contacts/zone.html')
return tmpl.render(context)
class ContactsZone(TemplateView):
template_name = 'contacts/zone.html'
def get_context_data(self, **kwargs):
context = super(ContactsZone, self).get_context_data(**kwargs)
return context
zone = csrf_exempt(ContactsZone.as_view())
def search_json(request):
query = request.GET.get('q')
result = []
response = HttpResponse(content_type='application/json')
json.dump({'data': result}, response, indent=2)
return response

View File

@ -44,6 +44,7 @@ INSTALLED_APPS = (
'welco.sources.mail',
'welco.qualif',
'welco.kb',
'welco.contacts',
'gadjo',
)

View File

@ -14,17 +14,7 @@
</div>
<div class="cell contacts">
<h2>{% trans 'Contacts' %}</h2>
<form>
<div>
<label>{% trans 'Search:' %}</label>
<input type="text" placeholder="{% trans 'Name, phone, etc.' %}"/>
</div>
<div>
<button>{% trans 'Create new contact' %}</button>
</div>
</form>
{{ contacts.render }}
</div>
<div class="cell qualif" data-zone-url="{% url 'qualif-zone' %}">
<h2>{% trans 'Qualification' %}</h2>

View File

@ -35,6 +35,9 @@ urlpatterns = patterns('',
url(r'^kb/(?P<slug>[\w-]+)/edit$', 'welco.kb.views.page_edit', name='kb-page-edit'),
url(r'^kb/(?P<slug>[\w-]+)/delete$', 'welco.kb.views.page_delete', name='kb-page-delete'),
url(r'^ajax/contacts$', 'welco.contacts.views.zone', name='contacts-zone'),
url(r'^contacts/search/json/$', 'welco.contacts.views.search_json', name='contacts-search-json'),
url(r'^admin/', include(admin.site.urls)),
url(r'^logout/$', 'welco.views.logout', name='auth_logout'),
url(r'^login/$', 'welco.views.login', name='auth_login'),

View File

@ -35,6 +35,7 @@ except ImportError:
from sources.mail.views import Home as MailHome
from .qualif.models import Association, FormdefReference
from .kb.views import HomeZone as KbHomeZone
from .contacts.views import HomeZone as ContactsHomeZone
from .forms import QualificationForm
@ -95,6 +96,7 @@ class Home(TemplateView):
context = super(Home, self).get_context_data(**kwargs)
context['source'] = MailHome(self.request)
context['kb'] = KbHomeZone(self.request)
context['contacts'] = ContactsHomeZone(self.request)
return context
home = Home.as_view()