[FIX] various website modules, re-enable crawler tests

* fix crawler to discard URL fragments before deduplicating and crawling
* fix website_forum links which should not be links (either because their urls
  are JSON-RPC methods or because their urls are side-effecting
* remove stray print statements
* side-improvements (simplifications) to some methods
This commit is contained in:
Xavier Morel
2014-05-13 11:42:05 +02:00
8 changed files with 83 additions and 59 deletions
+14 -2
View File
@@ -41,6 +41,9 @@ class CrawlSuite(unittest2.TestSuite):
starting the crawl
"""
at_install = False
post_install = True
def __init__(self, user=None, password=None):
super(CrawlSuite, self).__init__()
@@ -108,14 +111,23 @@ class CrawlSuite(unittest2.TestSuite):
for link in doc.xpath('//a[@href]'):
href = link.get('href')
parts = urlparse.urlsplit(href)
# href with any fragment removed
href = urlparse.urlunsplit((
parts.scheme,
parts.netloc,
parts.path,
parts.query,
''
))
# avoid repeats, even for links we won't crawl no need to
# bother splitting them if we've already ignored them
# previously
if href in seen: continue
seen.add(href)
parts = urlparse.urlsplit(href)
# FIXME: handle relative link (not parts.path.startswith /)
if parts.netloc or \
not parts.path.startswith('/') or \
parts.path == '/web' or\
+13 -22
View File
@@ -23,38 +23,29 @@ class contactus(http.Controller):
if kwargs.get(field):
values[field] = kwargs.pop(field)
values.update(kwargs=kwargs.items())
print values
return request.website.render("website.contactus", values)
@http.route(['/crm/contactus'], type='http', auth="public", website=True, multilang=True)
def contactus(self, description=None, partner_name=None, phone=None, contact_name=None, email_from=None, name=None, **kwargs):
post = {}
post['description'] = description
post['partner_name'] = partner_name
post['phone'] = phone
post['contact_name'] = contact_name
post['email_from'] = email_from
post['name'] = name
required_fields = ['contact_name', 'email_from', 'description']
error = set()
values = dict((key, post.get(key)) for key in post)
values['error'] = error
post = {
'description': description,
'partner_name': partner_name,
'phone': phone,
'contact_name': contact_name,
'email_from': email_from,
'name': name or contact_name,
'user_id': False,
}
# fields validation
for field in required_fields:
if not post.get(field):
error.add(field)
error = set(field for field in ['contact_name', 'email_from', 'description']
if not post.get(field))
values = dict(post, error=error)
if error:
values.update(kwargs=kwargs.items())
return request.website.render("website.contactus", values)
# if not given: subject is contact name
if not post.get('name'):
post['name'] = post.get('contact_name')
post['user_id'] = False
try:
post['channel_id'] = request.registry['ir.model.data'].get_object_reference(request.cr, SUPERUSER_ID, 'crm', 'crm_case_channel_website')[1]
except ValueError:
@@ -83,7 +83,6 @@ class website_event(website_event):
def _add_event(self, event_name="New Event", context={}, **kwargs):
try:
print kwargs
dummy, res_id = request.registry.get('ir.model.data').get_object_reference(request.cr, request.uid, 'event_sale', 'product_product_event')
context['default_event_ticket_ids'] = [[0,0,{
'name': _('Subscription'),
+16 -21
View File
@@ -18,19 +18,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import collections
import datetime
import re
import pytz
import werkzeug.utils
import openerp
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.controllers.main import Website as controllers
import datetime
import re
import werkzeug.utils
controllers = controllers()
import pytz
from pytz import timezone
class website_event(http.Controller):
@http.route(['/event/<model("event.event"):event>/track/<model("event.track"):track>'], type='http', auth="public", website=True, multilang=True)
@@ -79,24 +77,21 @@ class website_event(http.Controller):
# TODO: not implemented
@http.route(['/event/<model("event.event"):event>/agenda'], type='http', auth="public", website=True, multilang=True)
def event_agenda(self, event, tag=None, **post):
comp = lambda x: (x.date, bool(x.location_id))
event.track_ids.sort(lambda x,y: cmp(comp(x), comp(y)))
days_tracks = collections.defaultdict(lambda: [])
for track in sorted(event.track_ids, key=lambda x: (x.date, bool(x.location_id))):
if not track.date: continue
days_tracks[track.date[:10]].append(track)
days = {}
days_nbr = {}
for track in event.track_ids:
if not track.date: continue
days.setdefault(track.date[:10], [])
days[track.date[:10]].append(track)
for d in days:
days_nbr[d] = len(days[d])
days[d] = self._prepare_calendar(event, days[d])
days_tracks_count = {}
for day, tracks in days_tracks.iteritems():
days_tracks_count[day] = len(tracks)
days[day] = self._prepare_calendar(event, tracks)
return request.website.render("website_event_track.agenda", {
'event': event,
'days': days,
'days_nbr': days_nbr,
'days_nbr': days_tracks_count,
'tag': tag
})
@@ -94,3 +94,7 @@ a.no-decoration {
font: 1.2em "Helvetica Neue", Helvetica, Arial, sans-serif !important;
height: 1.2em !important;
}
button.btn-link.text-muted {
color: #999999;
}
@@ -74,3 +74,6 @@ a.no-decoration
.text-tags .text-tag .text-button
font: 1.2em "Helvetica Neue", Helvetica, Arial, sans-serif !important
height: 1.2em !important
button.btn-link.text-muted
color: #999
@@ -3,7 +3,7 @@ $(document).ready(function () {
$('.vote_up ,.vote_down').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc($link.attr('href'), 'call', {})
openerp.jsonRpc($link.data('href'), 'call', {})
.then(function (data) {
if (data['error']){
if (data['error'] == 'own_post'){
@@ -47,7 +47,7 @@ $(document).ready(function () {
$('.accept_answer').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) {
openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
if (data['error']) {
if (data['error'] == 'anonymous_user'){
var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
@@ -83,7 +83,7 @@ $(document).ready(function () {
$('.favourite_question').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) {
openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
if (data) {
$link.addClass("forum_favourite_question")
} else {
@@ -96,7 +96,7 @@ $(document).ready(function () {
$('.comment_delete').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) {
openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) {
$link.parents('.comment').first().remove();
});
return true;
+29 -9
View File
@@ -20,6 +20,14 @@
</xpath>
</template>
<!-- helper -->
<template id="muted_button">
<form method="POST" t-att-action="url">
<button t-attf-class="text-muted fa btn-link #{classes}">
<t t-esc="label"/></button>
</form>
</template>
<!-- Page Index -->
<template id="header" name="Forum Index">
<t t-call="website.layout">
@@ -387,10 +395,10 @@
<template id="vote">
<div t-attf-class="box oe_grey">
<a t-attf-class="vote_up fa fa-thumbs-up no-decoration #{post.user_vote == 1 and 'text-success' or ''}"
t-attf-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/upvote"/>
t-attf-data-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/upvote"/>
<span id="vote_count" t-esc="post.vote_count"/>
<a t-attf-class="vote_down fa fa-thumbs-down no-decoration #{post.user_vote == -1 and 'text-warning' or ''}"
t-attf-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/downvote"/>
t-attf-data-href="/forum/#{slug(post.forum_id)}/post/#{slug(post)}/downvote"/>
<div t-if="vote_count &gt; 1" class="subtitle">
votes
</div>
@@ -412,7 +420,7 @@
<span t-field="question.views"/> Views
</div>
<div class="mt4">
<a t-attf-href="/forum/#{slug(question.forum_id)}/question/#{slug(question)}/toggle_favourite"
<a t-attf-data-href="/forum/#{slug(question.forum_id)}/question/#{slug(question)}/toggle_favourite"
t-attf-class="favourite_question no-decoration fa fa-2x fa-star #{question.user_favourite and 'forum_favourite_question' or ''}"/>
</div>
</div>
@@ -495,7 +503,7 @@
</t>
<div class="text-muted mt8">
<a t-attf-class="accept_answer fa fa-2x fa-check-circle no-decoration #{answer.is_correct and 'oe_answer_true' or 'oe_answer_false'}"
t-attf-href="/forum/#{slug(question.forum_id)}/post/#{slug(answer)}/toggle_correct"/>
t-attf-data-href="/forum/#{slug(question.forum_id)}/post/#{slug(answer)}/toggle_correct"/>
</div>
</div>
<div style="margin-left: 95px;" class="clearfix">
@@ -511,10 +519,18 @@
<a class="text-muted fa fa-edit" t-attf-href="/forum/#{slug(forum)}/post/#{slug(answer)}/edit"> Edit</a>
</li>
<li t-if="(user.id == answer.create_uid.id and can_unlink_own) or can_unlink_all">
<a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{slug(forum)}/post/#{slug(answer)}/delete"> Delete</a>
<t t-call="website_forum.muted_button">
<t t-set="url"><t t-escf="/forum/#{slug(forum)}/post/#{slug(answer)}/delete"/></t>
<t t-set="label"> Delete</t>
<t t-set="classes">fa-trash-o</t>
</t>
</li>
<li t-if="user.id == answer.create_uid.id">
<a class="text-muted fa fa-magic" t-attf-href="/forum/#{slug(forum)}/post/#{slug(answer)}/convert_to_comment"> Convert as a comment</a>
<t t-call="website_forum.muted_button">
<t t-set="url"><t t-escf="/forum/#{slug(forum)}/post/#{slug(answer)}/convert_to_comment"/></t>
<t t-set="label">Convert as a comment</t>
<t t-set="classes">fa-magic</t>
</t>
</li>
</ul>
<span t-field="answer.create_uid.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/>
@@ -550,15 +566,19 @@
<div t-foreach="reversed(object.website_message_ids)" t-as="message" class="comment oe_comment_grey">
<small class="text-muted">
<button type="button" t-if="user.partner_id.id == message.author_id.id and user.karma&gt;=750"
t-attf-href="/forum/#{slug(forum)}/post/#{slug(object)}/comment/#{slug(message)}/delete"
t-attf-data-href="/forum/#{slug(forum)}/post/#{slug(object)}/comment/#{slug(message)}/delete"
class="close comment_delete">&amp;times;</button>
<span t-field="message.body"/>
<a t-attf-href="/forum/#{slug(forum)}/partner/#{message.author_id.id}"
t-field="message.author_id" t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}'
style="display: inline-block;"/>
on <span t-field="message.date" t-field-options='{"format":"short"}'/>
<a class="fa fa-magic text-muted pull-right"
t-attf-href="/forum/#{slug(forum)}/post/#{slug(object)}/comment/#{slug(message)}/convert_to_answer">Convert as an answer</a>
<t t-call="website_forum.muted_button">
<t t-set="url"><t t-escf="/forum/#{slug(forum)}/post/#{slug(object)}/comment/#{slug(message)}/convert_to_answer"/></t>
<t t-set="label"> Convert as an answer</t>
<t t-set="classes">fa-magic pull-right</t>
</t>
</small>
</div>
<div class="css_editable_mode_hidden">