[mezzanine-users] UnicodeDecodeError in Mezzanine ThreadedComments

2015-12-18 Thread christian . kuper1
I am working on a project which uses ThreadedComments in a couple of apps 
(Mezzanine Blog and a discussion forum). All was working fine in the 
development and production environment but from one day to the next posting 
a comment raised an Internal Server Error (500).

My setup: Mezzanine 4.01, Django 1.8.5, Python 2.7.6. The production 
environment is a Ubuntu 14.04 server, Apache webserver. Mezzanine is 
deployed using mod_wsgi-express. Mezzanine is set up using "German" as 
language.

The error log created by the server gives me the following:

Traceback (most recent call last):
[Thu Dec 17 21:08:23.317452 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357]   File 
"/home/chris/IT/Portal/veportal/local/lib/python2.7/site-packages/mod_wsgi-4.4.15-py2.7-linux-x86_64.egg/mod_wsgi/server/__init__.py"
, line 1346, in handle_request
[Thu Dec 17 21:08:23.317902 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357] return self.application(
environ, start_response)
[Thu Dec 17 21:08:23.317919 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357]   File 
"/home/chris/IT/Portal/veportal/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py"
, line 195, in __call__
[Thu Dec 17 21:08:23.317982 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357] response_headers.append((str
('Set-Cookie'), str(c.output(header=''
[Thu Dec 17 21:08:23.317993 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357]   File 
"/usr/lib/python2.7/Cookie.py", line 466, in output
[Thu Dec 17 21:08:23.318106 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357] return "%s %s" % ( header, 
self.OutputString(attrs) )
[Thu Dec 17 21:08:23.318116 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357]   File 
"/usr/lib/python2.7/Cookie.py", line 514, in OutputString
[Thu Dec 17 21:08:23.318128 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357] return _semispacejoin(result
)
[Thu Dec 17 21:08:23.318143 2015] [wsgi:error] [pid 30806:tid 
140269963933440] [remote 95.90.251.8:24357] UnicodeDecodeError: 'ascii' 
codec can't decode byte 0xc3 in position 16: ordinal not in range(128)

After some digging I found that this error was caused by the "set_cookie" 
method in mezzanine.utils.views. When creating the "expires" date the 
locale de_DE, utf-8 is used by strftime and the month of March in German 
contains a non ASCII character (i.e. "Umlaut"). Therefore the error only 
pops up if a cookie with expiry "March" is set.

For testing purposes I tried running my project using the Django 
development server in the production environment - strangely enough I did 
NOT get the error there.

As a quick fix I temporarily set the locale back to en_US, utf-8 before 
setting the cookie using this 

 
approach; i.e. mezzanine.utils.views like so:

# This is a hack to avoid unicode decode errors caused on the production 
server
# by a german expiry date

import locale
import threading

from contextlib import contextmanager


LOCALE_LOCK = threading.Lock()

@contextmanager
def setlocale(name):
with LOCALE_LOCK:
saved = locale.setlocale(locale.LC_ALL)
try:
yield locale.setlocale(locale.LC_ALL, name)
finally:
locale.setlocale(locale.LC_ALL, saved)


# End of hack


def set_cookie(response, name, value, expiry_seconds=None, secure=False):
"""
Set cookie wrapper that allows number of seconds to be given as the
expiry time, and ensures values are correctly encoded.
"""
if expiry_seconds is None:
expiry_seconds = 90 * 24 * 60 * 60  # Default to 90 days.
# Set back locale to avoid UnicodeDecodeError
with setlocale(('en', 'utf-8')):
expires = datetime.strftime(datetime.utcnow() +
timedelta(seconds=expiry_seconds),
"%a, %d-%b-%Y %H:%M:%S GMT")
# Django doesn't seem to support unicode cookie keys correctly on
# Python 2. Work around by encoding it. See
# https://code.djangoproject.com/ticket/19802
try:
response.set_cookie(name, value, expires=expires, secure=secure)
except (KeyError, TypeError):
response.set_cookie(name.encode('utf-8'), value, expires=expires,
secure=secure)

Although things seem to be working now I do not think fiddling with core 
code  is a good idea. I am not even sure whether this is really a Mezzanine 
issue or whether it has something todo with Apache, mod_wsgi or an issue 
with the setup of the production server as such.

Any thoughts welcome.

Regards

Chris




-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop rece

[mezzanine-users] Re: Wiki for Mezzaine

2015-12-18 Thread christian . kuper1
Hi Sathishkumar,

could you elaborate a little on features you are looking for and missing in 
MezzanineWiki? I normally use the plugins as a basis for my own 
customization and rescently installed mezzanine-wiki without much problems.

IMHO even Mezzanine as it is provides many "Wiki like" features.

Regards

Chris

Am Dienstag, 15. Dezember 2015 17:36:18 UTC+1 schrieb Sathishkumar 
Duraisamy:
>
> Hi All,
>
> The https://github.com/dfalk/mezzanine-wiki is not active. What is good 
> wiki for mezzaine? 
>
> -- 
> Regards,
> Sathishkumar D
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Using Form builder form in custom Page

2015-12-18 Thread Tomas Chmelevskij
I would like to hear some opinions from more experienced mezzaniners.
I'm building a store for a friend and trying to make it sort of single page.
So for my homepage I want to include contact form. Instead of hardcoding it
I want to be able to edit it from admin interface.

So this is what I came up with:

models.py

class HomePage(Page, RichText):
"""
Landing page
"""
featured_shop = models.ForeignKey("shop.Category",
  blank=True,
  null=True,
  )
contact_form = models.OneToOneField("forms.Form",
default=None,
blank=True,
null=True,
)


page_processors.py

def create_contact_form(page, request):
"""
Create contact form if it is added to the homepage
"""
# get contact form created in the admin interface
form = FormForForm(page.homepage.contact_form, RequestContext(request),
   request.POST or None)
if form.is_valid():
url = page.get_absolute_url() + "?sent=1"
if is_spam(request, form, url):
return redirect(url)
attachments = []
for f in form.files.values():
f.seek(0)
attachments.append(f.name, f.read())
entry = form.save()
subject = page.homepage.contact_form.email_subject
if not subject:
subject = "%s - %s" % (page.homepage.contact_form.title, 
entry.entry_time)
fields = [(v.label, format_value(form.cleaned_data[k]))
  for (k, v) in form.fields.items()]
context = {
"fields": fields,
"message": page.homepage.contact_form.email_message,
"request": request,
}
email_from = page.homepage.contact_form.email_from or 
settings.DEFAULT_FROM_EMAIL
email_to = form.email_to()
if email_to and page.homepage.contact_form.send_email:
send_mail_template(subject, "email/form_response", email_from,
   email_to, context)

headers = None
if email_to:
# Add the email entered as a Reply-To header
headers = {'Reply-To': email_to}
email_copies = split_addresses(page.homepage.contact_form.email_copies)
if email_copies:
send_mail_template(subject, "email/form_response_copies",
   email_from, email_copies, context,
   attachments=attachments, headers=headers)
form_valid.send(sender=request, form=form, entry=entry)
return redirect(url)
form_invalid.send(sender=request, form=form)
return form


@processor_for(HomePage)
def homepage_processor(request, page):
"""
Add products from store to the homepage and pass contact
form created in admin interface
"""
# create contact form
if page.homepage.contact_form:
form = create_contact_form(page, request)
else:
form = None

return {"products": products, "form": form}


pages/index.html

{% extends "pages/form.html" %}

...

{% if page.homepage.contact_form %}
{# Contact Section #}




Contact
{% block main %}
{{ block.super }}
{% endblock %}




{% endif %}


My page_processor.py is exact copy of the 
forms.page_processors.form_processor with
few extra tweeks. Thing is it's not really DRY because it's repeating the 
same logic.
So is there a better way to do it? For example one of the ideas I had was 
try to use solution from Python Cookbook 

.
But problem is it's only possible to use it if decorator is implemented 
with @wraps decorator.
So maybe it could be an idea for future improvements. Or I'm just missing 
something and there
is already and easy way to use those forms?

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: Wiki for Mezzaine

2015-12-18 Thread Derek Adair
They are asking about a wiki dedicated towards mezzanine not a plugin.  The 
docs are here .

On Friday, December 18, 2015 at 4:26:17 AM UTC-6, 
christia...@googlemail.com wrote:
>
> Hi Sathishkumar,
>
> could you elaborate a little on features you are looking for and missing 
> in MezzanineWiki? I normally use the plugins as a basis for my own 
> customization and rescently installed mezzanine-wiki without much problems.
>
> IMHO even Mezzanine as it is provides many "Wiki like" features.
>
> Regards
>
> Chris
>
> Am Dienstag, 15. Dezember 2015 17:36:18 UTC+1 schrieb Sathishkumar 
> Duraisamy:
>>
>> Hi All,
>>
>> The https://github.com/dfalk/mezzanine-wiki is not active. What is good 
>> wiki for mezzaine? 
>>
>> -- 
>> Regards,
>> Sathishkumar D
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Any interest in sorl_thumbmail?

2015-12-18 Thread Derek Adair
After running into some limitations / shortfalls of the thumbnail 
generating template-tag in mezzanine I came across this blog post 
.  I'm wondering if 
anyone else would desire this as a replacement.  Has anyone tried taking it 
further than this post and replacing the thumbnail code from mezzanine.core?

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[mezzanine-users] Re: Is it possible to integrate django-allauth in mezzanine/cartridge ?

2015-12-18 Thread Derek Adair
specifically this answer 
 
is a detailed explanation of what needs to be done.

On Sunday, December 13, 2015 at 1:20:15 PM UTC-6, Sathish Anton wrote:
>
> Hi,
> I have not personaly tried. But here is a post i read before.
>
> https://groups.google.com/forum/#!searchin/mezzanine-users/allauth%7Csort:relevance/mezzanine-users/VvWj7G06uo8/IcCkXTE5lwwJ
> Thanks
>
> On Sunday, December 13, 2015 at 12:24:32 PM UTC+5:30, RAUSHAN RAJ wrote:
>>
>> I want to integrate google/facebook login in my ecommerce site.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Any interest in sorl_thumbmail?

2015-12-18 Thread Matt Mansour
I am having good success with django-image-cropper in a mezzanine project.
I am curious about it as a potential replacement or option as well.
On Dec 18, 2015 2:02 PM, "Derek Adair"  wrote:

> After running into some limitations / shortfalls of the thumbnail
> generating template-tag in mezzanine I came across this blog post
> .  I'm wondering if
> anyone else would desire this as a replacement.  Has anyone tried taking it
> further than this post and replacing the thumbnail code from mezzanine.core?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mezzanine-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [mezzanine-users] Any interest in sorl_thumbmail?

2015-12-18 Thread Stephen McDonald
Worth noting this is mentioned in the FAQs:

http://mezzanine.jupo.org/docs/frequently-asked-questions.html#why-does-mezzanine-contain-its-own-feature-instead-of-using-package


On Sat, Dec 19, 2015 at 4:14 AM, Derek Adair  wrote:

> After running into some limitations / shortfalls of the thumbnail
> generating template-tag in mezzanine I came across this blog post
> .  I'm wondering if
> anyone else would desire this as a replacement.  Has anyone tried taking it
> further than this post and replacing the thumbnail code from mezzanine.core?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mezzanine-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Stephen McDonald
http://jupo.org

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.