# -*- coding: utf-8 -*-

import openerp
from openerp.addons.web import http
from openerp.addons.web.http import request
import simplejson
import werkzeug.wrappers

from urllib import quote_plus

class contactus(http.Controller):

    @http.route(['/crm/contactus'], type='http', auth="admin")
    def contactus(self, *arg, **post):
        website = request.registry['website']
        post['user_id'] = False
        request.registry['crm.lead'].create(request.cr, request.uid, post)
        values = website.get_rendering_context()
        company = values['res_company']
        values.update({
            'google_map_url': "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=8&size=298x298" % quote_plus('%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''))
        })
        return website.render("website_crm.thanks", values)

    @http.route(['/crm/google_map/'], type='http', auth="admin")
    def google_map(self, *arg, **post):
        website = request.registry['website']
        values = website.get_rendering_context()
        values['partner_ids'] = post.get('partner_ids', "")
        return website.render("website_crm.google_map", values)

    @http.route(['/crm/google_map/partners.json'], type='http', auth="admin")
    def google_map_data(self, *arg, **post):
        website = request.registry['website']
        partner_obj = request.registry['res.partner']

        domain = [("id", "in", [int(p) for p in post.get('partner_ids', "").split(",") if p])]
        partner_ids = partner_obj.search(request.cr, openerp.SUPERUSER_ID, domain + [('website_published', '=', True)])
        if request.uid != website.get_public_user().id:
            partner_ids += partner_obj.search(request.cr, request.uid, domain)

        data = {
            "counter": len(partner_ids),
            "partners": []
            }
        for partner in partner_obj.browse(request.cr, openerp.SUPERUSER_ID, partner_ids, context={'show_address': True}):
            data["partners"].append({
                'id': partner.id,
                'name': partner.name,
                'address': '\n'.join(partner.name_get()[0][1].split('\n')[1:]),
                'type': "Silver Partners"
                })

        mime = 'application/json'
        body = "var data = " + "}, \n{".join(simplejson.dumps(data).split("}, {"))
        return werkzeug.wrappers.Response(body, headers=[('Content-Type', mime), ('Content-Length', len(body))])

# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:

@@ -930,1612 +930,8 @@
 s)%0A%0A
-    @http.route(%5B'/crm/google_map/'%5D, type='http', auth=%22admin%22)%0A    def google_map(self, *arg, **post):%0A        website = request.registry%5B'website'%5D%0A        values = website.get_rendering_context()%0A        values%5B'partner_ids'%5D = post.get('partner_ids', %22%22)%0A        return website.render(%22website_crm.google_map%22, values)%0A%0A    @http.route(%5B'/crm/google_map/partners.json'%5D, type='http', auth=%22admin%22)%0A    def google_map_data(self, *arg, **post):%0A        website = request.registry%5B'website'%5D%0A        partner_obj = request.registry%5B'res.partner'%5D%0A%0A        domain = %5B(%22id%22, %22in%22, %5Bint(p) for p in post.get('partner_ids', %22%22).split(%22,%22) if p%5D)%5D%0A        partner_ids = partner_obj.search(request.cr, openerp.SUPERUSER_ID, domain + %5B('website_published', '=', True)%5D)%0A        if request.uid != website.get_public_user().id:%0A            partner_ids += partner_obj.search(request.cr, request.uid, domain)%0A%0A        data = %7B%0A            %22counter%22: len(partner_ids),%0A            %22partners%22: %5B%5D%0A            %7D%0A        for partner in partner_obj.browse(request.cr, openerp.SUPERUSER_ID, partner_ids, context=%7B'show_address': True%7D):%0A            data%5B%22partners%22%5D.append(%7B%0A                'id': partner.id,%0A                'name': partner.name,%0A                'address': '%5Cn'.join(partner.name_get()%5B0%5D%5B1%5D.split('%5Cn')%5B1:%5D),%0A                'type': %22Silver Partners%22%0A                %7D)%0A%0A        mime = 'application/json'%0A        body = %22var data = %22 + %22%7D, %5Cn%7B%22.join(simplejson.dumps(data).split(%22%7D, %7B%22))%0A        return werkzeug.wrappers.Response(body, headers=%5B('Content-Type', mime), ('Content-Length', len(body))%5D)%0A%0A
 # vi

remove non used code