<s> from django . http import HttpResponse <EOL> from django . http import ( HttpResponseBadRequest , HttpResponseNotFound , <EOL> HttpResponseForbidden ) <EOL> from django . contrib . auth import authenticate , login , logout <EOL> from django . views . decorators . csrf import csrf_exempt <EOL> from django . shortcuts import render <EOL> from django . utils . translation import ugettext as _ <EOL> from django . conf import settings <EOL> import json <EOL> import random <EOL> from django . views . decorators . http import require_POST <EOL> from django . views . decorators . http import require_GET <EOL> from utils . spellcheck_localization import SPELLCHECK_LOCALIZATION <EOL> from forms import ( <EOL> CustomUserCreationForm , <EOL> GetRequestValidationForm , <EOL> PostCommentForm , <EOL> RegularUserLoginForm , <EOL> ) <EOL> from models import Site , Thread , Comment <EOL> from decorators import json_response , cross_domain_post_response , host_check <EOL> try : <EOL> import enchant <EOL> from enchant . checker import SpellChecker <EOL> except ImportError : <EOL> settings . SPELLCHECK_ENABLED = False <EOL> def add_to_session_list ( request , key , value ) : <EOL> session_data = request . session . setdefault ( key , [ ] ) <EOL> session_data . append ( value ) <EOL> request . session [ key ] = session_data <EOL> return request . session [ key ] <EOL> def remove_from_session_list ( request , key , value ) : <EOL> session_data = request . session . setdefault ( key , [ ] ) <EOL> if value in session_data : <EOL> session_data . remove ( value ) <EOL> request . session [ key ] = session_data <EOL> return session_data <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def register_user ( request ) : <EOL> form = CustomUserCreationForm ( request . POST ) <EOL> if not form . is_valid ( ) : <EOL> return HttpResponseBadRequest ( _ ( "<STR_LIT>" ) ) <EOL> cd = form . cleaned_data <EOL> user = form . save ( ) <EOL> user = authenticate ( email = cd [ '<STR_LIT:email>' ] , password = cd [ '<STR_LIT:password>' ] ) <EOL> login ( request , user ) <EOL> return HttpResponse ( unicode ( user ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def logout_user ( request ) : <EOL> if request . user . is_authenticated ( ) : <EOL> logout ( request ) <EOL> return HttpResponse ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def set_avatar_image ( request ) : <EOL> avatar_num = int ( request . POST . get ( '<STR_LIT>' ) ) <EOL> if avatar_num < settings . AVATAR_NUM_MIN or avatar_num > settings . AVATAR_NUM_MAX : <EOL> HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) + str ( avatar_num ) <EOL> ) <EOL> if request . user . is_authenticated ( ) : <EOL> u = request . user <EOL> u . avatar_num = avatar_num <EOL> u . save ( ) <EOL> request . session [ '<STR_LIT>' ] = avatar_num <EOL> return HttpResponse ( '<STR_LIT>' ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def login_user ( request ) : <EOL> form = RegularUserLoginForm ( request . POST ) <EOL> if not form . is_valid ( ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( "<STR_LIT>" ) <EOL> ) <EOL> user = form . get_user ( ) <EOL> login ( request , user ) <EOL> data = user . get_user_domain_data ( ) <EOL> request . session . update ( data ) <EOL> return HttpResponse ( unicode ( user ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def comment ( request ) : <EOL> form = PostCommentForm ( request . POST , request ) <EOL> if not form . is_valid ( ) : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : form . errors } <EOL> return HttpResponseBadRequest ( json . dumps ( data ) ) <EOL> else : <EOL> site = Site . objects . get ( domain = form . cleaned_data [ '<STR_LIT>' ] ) <EOL> if not request . user . is_anonymous ( ) : <EOL> if request . user . hidden . filter ( id = site . id ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( "<STR_LIT>" ) ) <EOL> new_comment = form . save ( ) <EOL> posted = add_to_session_list ( request , '<STR_LIT>' , new_comment . id ) <EOL> comments = form . cleaned_data [ '<STR_LIT>' ] . comments . all ( ) <EOL> if request . user . is_anonymous ( ) : <EOL> site_admin = False <EOL> else : <EOL> site_admin = bool ( request . user . get_comments ( new_comment . id ) ) <EOL> request . session [ '<STR_LIT>' ] = True <EOL> resp = render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : comments , <EOL> '<STR_LIT>' : posted , <EOL> '<STR_LIT>' : posted [ - <NUM_LIT:1> ] if posted else None , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> '<STR_LIT>' : request . session . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : site_admin <EOL> } <EOL> ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : resp . content , <EOL> '<STR_LIT>' : new_comment . id <EOL> } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> @ host_check <EOL> def like_comment ( request , comment_id ) : <EOL> try : <EOL> comment = Comment . objects . get ( id = comment_id ) <EOL> except Comment . DoesNotExist as e : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : str ( e ) } <EOL> return HttpResponseNotFound ( json . dumps ( data ) ) <EOL> if request . user . is_anonymous ( ) : <EOL> site_admin = False <EOL> else : <EOL> site_admin = bool ( request . user . get_comments ( comment_id ) ) <EOL> if site_admin : <EOL> if request . user . hidden . filter ( id = comment . thread . site . id ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % comment . thread . site . id <EOL> ) <EOL> liked_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> disliked_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> if comment . id in disliked_comments : <EOL> comment . undo_dislike ( request . user ) <EOL> remove_from_session_list ( request , '<STR_LIT>' , comment . id ) <EOL> comment . like ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , comment . id ) <EOL> elif comment . id not in liked_comments : <EOL> comment . like ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , comment . id ) <EOL> comments = Comment . objects . filter ( thread = comment . thread ) <EOL> posted_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> site = comment . thread . site <EOL> resp = render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : comments , <EOL> '<STR_LIT>' : posted_comments , <EOL> '<STR_LIT>' : posted_comments [ - <NUM_LIT:1> ] if posted_comments else None , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> '<STR_LIT>' : request . session . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : site_admin , <EOL> } <EOL> ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : resp . content } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> @ host_check <EOL> def dislike_comment ( request , comment_id ) : <EOL> try : <EOL> comment = Comment . objects . get ( id = comment_id ) <EOL> except Comment . DoesNotExist as e : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : str ( e ) } <EOL> return HttpResponseNotFound ( json . dumps ( data ) ) <EOL> if request . user . is_anonymous ( ) : <EOL> site_admin = False <EOL> else : <EOL> site_admin = bool ( request . user . get_comments ( comment_id ) ) <EOL> if site_admin : <EOL> if request . user . hidden . filter ( id = comment . thread . site . id ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % comment . thread . site . id <EOL> ) <EOL> liked_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> disliked_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> if comment . id in liked_comments : <EOL> comment . undo_like ( request . user ) <EOL> remove_from_session_list ( request , '<STR_LIT>' , comment . id ) <EOL> comment . dislike ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , comment . id ) <EOL> elif comment . id not in disliked_comments : <EOL> comment . dislike ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , comment . id ) <EOL> comments = Comment . objects . filter ( thread = comment . thread ) <EOL> posted_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> site = comment . thread . site <EOL> resp = render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : comments , <EOL> '<STR_LIT>' : posted_comments , <EOL> '<STR_LIT>' : posted_comments [ - <NUM_LIT:1> ] if posted_comments else None , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> '<STR_LIT>' : request . session . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : site_admin , <EOL> } <EOL> ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : resp . content } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def hide_comment ( request , comment_id ) : <EOL> try : <EOL> comment = Comment . objects . get ( id = comment_id ) <EOL> except Comment . DoesNotExist as e : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : str ( e ) } <EOL> return HttpResponseNotFound ( json . dumps ( data ) ) <EOL> if request . user . is_anonymous ( ) : <EOL> site_admin = False <EOL> else : <EOL> site_admin = bool ( request . user . get_comments ( comment_id ) ) <EOL> if not site_admin : <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : _ ( "<STR_LIT>" ) <EOL> } <EOL> return HttpResponseForbidden ( json . dumps ( data ) ) <EOL> comment . hide ( ) <EOL> comments = Comment . objects . filter ( thread = comment . thread ) <EOL> posted_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> site = comment . thread . site <EOL> resp = render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : comments , <EOL> '<STR_LIT>' : posted_comments , <EOL> '<STR_LIT>' : posted_comments [ - <NUM_LIT:1> ] if posted_comments else None , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> '<STR_LIT>' : request . session . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : site_admin , <EOL> } <EOL> ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : resp . content } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def unhide_comment ( request , comment_id ) : <EOL> try : <EOL> comment = Comment . objects . get ( id = comment_id ) <EOL> except Comment . DoesNotExist as e : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : str ( e ) } <EOL> return HttpResponseNotFound ( json . dumps ( data ) ) <EOL> if request . user . is_anonymous ( ) : <EOL> site_admin = False <EOL> else : <EOL> site_admin = bool ( request . user . get_comments ( comment_id ) ) <EOL> if not site_admin : <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : _ ( "<STR_LIT>" ) <EOL> } <EOL> return HttpResponseForbidden ( json . dumps ( data ) ) <EOL> comment . unhide ( ) <EOL> comments = Comment . objects . filter ( thread = comment . thread ) <EOL> posted_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> site = comment . thread . site <EOL> resp = render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : comments , <EOL> '<STR_LIT>' : posted_comments , <EOL> '<STR_LIT>' : posted_comments [ - <NUM_LIT:1> ] if posted_comments else None , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> '<STR_LIT>' : request . session . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : site_admin , <EOL> } <EOL> ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : resp . content } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def like_thread ( request , thread_id ) : <EOL> try : <EOL> thread = Thread . objects . get ( id = thread_id ) <EOL> except Thread . DoesNotExist as e : <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : str ( e ) <EOL> } <EOL> return HttpResponseNotFound ( json . dumps ( data ) ) <EOL> if not request . user . is_anonymous ( ) : <EOL> if request . user . hidden . filter ( id = thread . site . id ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % thread . site . id <EOL> ) <EOL> liked_threads = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> disliked_threads = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> if thread . id in disliked_threads : <EOL> thread . undo_dislike ( request . user ) <EOL> remove_from_session_list ( request , '<STR_LIT>' , thread . id ) <EOL> thread . like ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , thread . id ) <EOL> elif thread . id not in liked_threads : <EOL> thread . like ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , thread . id ) <EOL> resp = render ( request , '<STR_LIT>' , { '<STR_LIT>' : thread } ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : resp . content } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def dislike_thread ( request , thread_id ) : <EOL> try : <EOL> thread = Thread . objects . get ( id = thread_id ) <EOL> except Thread . DoesNotExist as e : <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : str ( e ) <EOL> } <EOL> return HttpResponseNotFound ( json . dumps ( data ) ) <EOL> if not request . user . is_anonymous ( ) : <EOL> if request . user . hidden . filter ( id = thread . site . id ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % thread . site . id <EOL> ) <EOL> liked_threads = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> disliked_threads = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> if thread . id in liked_threads : <EOL> thread . undo_like ( request . user ) <EOL> remove_from_session_list ( request , '<STR_LIT>' , thread . id ) <EOL> thread . dislike ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , thread . id ) <EOL> elif thread . id not in disliked_threads : <EOL> thread . dislike ( request . user ) <EOL> add_to_session_list ( request , '<STR_LIT>' , thread . id ) <EOL> resp = render ( request , '<STR_LIT>' , { '<STR_LIT>' : thread } ) <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:content>' : resp . content } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_GET <EOL> @ csrf_exempt <EOL> @ json_response <EOL> def comment_count ( request ) : <EOL> domain = request . GET . get ( '<STR_LIT>' , None ) <EOL> thread_url = request . GET . get ( '<STR_LIT>' , None ) <EOL> try : <EOL> site = Site . objects . get ( domain = domain ) <EOL> except Site . DoesNotExist : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % domain <EOL> ) <EOL> try : <EOL> thread = site . threads . get ( url = thread_url ) <EOL> except Thread . DoesNotExist : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % thread_url <EOL> ) <EOL> comment_count = thread . comments . filter ( hidden = False ) . count ( ) <EOL> return { "<STR_LIT>" : comment_count } <EOL> @ require_GET <EOL> @ csrf_exempt <EOL> @ json_response <EOL> def get_comments ( request ) : <EOL> form = GetRequestValidationForm ( request . GET ) <EOL> if not form . is_valid ( ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % form . errors <EOL> ) <EOL> domain_name = form . cleaned_data [ '<STR_LIT>' ] <EOL> thread_id = form . cleaned_data [ '<STR_LIT>' ] <EOL> try : <EOL> site = Site . objects . get ( domain = domain_name ) <EOL> if not request . user . is_anonymous ( ) : <EOL> if request . user . hidden . filter ( id = site . id ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % site . id <EOL> ) <EOL> except Site . DoesNotExist : <EOL> return HttpResponseBadRequest ( <EOL> '<STR_LIT>' % domain_name <EOL> ) <EOL> if not thread_id : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> thread , created = site . threads . get_or_create ( id = thread_id ) <EOL> posted_comments = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> all_comments = request . GET . get ( '<STR_LIT:all>' , False ) <EOL> if all_comments : <EOL> request . session [ '<STR_LIT>' ] = True <EOL> if request . user . is_anonymous ( ) : <EOL> site_admin = False <EOL> else : <EOL> site_admin = request . user . is_site_admin ( domain_name ) <EOL> comments = thread . comments . exclude ( user__hidden__in = [ site ] ) . distinct ( ) <EOL> resp = render ( <EOL> request , <EOL> "<STR_LIT>" , <EOL> { <EOL> '<STR_LIT>' : comments , <EOL> '<STR_LIT>' : posted_comments , <EOL> '<STR_LIT>' : posted_comments [ - <NUM_LIT:1> ] if posted_comments else None , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> '<STR_LIT>' : all_comments , <EOL> '<STR_LIT>' : site_admin <EOL> } <EOL> ) <EOL> return { "<STR_LIT:html>" : resp . content , "<STR_LIT>" : "<STR_LIT>" } <EOL> @ require_GET <EOL> @ json_response <EOL> def thread_info ( request ) : <EOL> domain = request . GET . get ( '<STR_LIT>' , None ) <EOL> thread_url = request . GET . get ( '<STR_LIT>' , None ) <EOL> titles = { <EOL> '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> } <EOL> try : <EOL> site = Site . objects . get ( domain = domain ) <EOL> except Site . DoesNotExist : <EOL> return HttpResponseBadRequest ( <EOL> '<STR_LIT>' % domain <EOL> ) <EOL> thread , created = site . threads . get_or_create ( url = thread_url ) <EOL> thread . titles = titles <EOL> thread . save ( ) <EOL> if request . session . get ( '<STR_LIT>' ) : <EOL> del request . session [ '<STR_LIT>' ] <EOL> avatar_num = request . session . get ( "<STR_LIT>" , None ) <EOL> if not avatar_num and request . user . is_anonymous ( ) : <EOL> avatar_num = random . randint ( <EOL> settings . AVATAR_NUM_MIN , <EOL> settings . AVATAR_NUM_MAX <EOL> ) <EOL> request . session [ '<STR_LIT>' ] = avatar_num <EOL> return { <EOL> "<STR_LIT>" : thread . id , <EOL> "<STR_LIT>" : thread . allow_comments , <EOL> "<STR_LIT>" : settings . SPELLCHECK_ENABLED , <EOL> "<STR_LIT>" : SPELLCHECK_LOCALIZATION <EOL> } <EOL> @ require_GET <EOL> @ json_response <EOL> def get_header ( request ) : <EOL> form = GetRequestValidationForm ( request . GET ) <EOL> if not form . is_valid ( ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % form . errors <EOL> ) <EOL> domain_name = form . cleaned_data [ '<STR_LIT>' ] <EOL> thread_id = form . cleaned_data [ '<STR_LIT>' ] <EOL> try : <EOL> site = Site . objects . get ( domain = domain_name ) <EOL> except Site . DoesNotExist : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % domain_name <EOL> ) <EOL> thread , created = site . threads . get_or_create ( id = thread_id ) <EOL> resp = render ( request , "<STR_LIT>" , { '<STR_LIT>' : thread } ) <EOL> return { "<STR_LIT:html>" : resp . content , "<STR_LIT>" : "<STR_LIT>" } <EOL> @ require_GET <EOL> @ json_response <EOL> def get_footer ( request ) : <EOL> form = GetRequestValidationForm ( request . GET ) <EOL> if not form . is_valid ( ) : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % form . errors <EOL> ) <EOL> domain_name = form . cleaned_data [ '<STR_LIT>' ] <EOL> thread_id = form . cleaned_data [ '<STR_LIT>' ] <EOL> try : <EOL> site = Site . objects . get ( domain = domain_name ) <EOL> except Site . DoesNotExist : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) % domain_name <EOL> ) <EOL> thread , created = site . threads . get_or_create ( id = thread_id ) <EOL> resp = render ( <EOL> request , <EOL> "<STR_LIT>" , { <EOL> '<STR_LIT:user>' : request . user , <EOL> '<STR_LIT>' : site , <EOL> '<STR_LIT>' : range ( <NUM_LIT:1> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : request . session . get ( '<STR_LIT>' , <NUM_LIT:6> ) , <EOL> '<STR_LIT>' : site . rs_customer_id , <EOL> } <EOL> ) <EOL> return { "<STR_LIT:html>" : resp . content , "<STR_LIT>" : "<STR_LIT>" } <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def incorrect_words ( request ) : <EOL> """<STR_LIT>""" <EOL> if not settings . SPELLCHECK_ENABLED : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> text = request . POST . get ( '<STR_LIT:text>' ) <EOL> if not text : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> chkr = SpellChecker ( settings . LANGUAGE_CODE ) <EOL> chkr . set_text ( text ) <EOL> errors = [ err . word for err in chkr ] <EOL> data = { '<STR_LIT:data>' : [ errors ] } <EOL> return HttpResponse ( json . dumps ( data ) ) <EOL> @ require_POST <EOL> @ csrf_exempt <EOL> @ cross_domain_post_response <EOL> def spellcheck_suggestions ( request ) : <EOL> """<STR_LIT>""" <EOL> if not settings . SPELLCHECK_ENABLED : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> word = request . POST . get ( '<STR_LIT>' ) <EOL> if not word : <EOL> return HttpResponseBadRequest ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> d = enchant . Dict ( settings . LANGUAGE_CODE ) <EOL> suggestions = d . suggest ( word ) if not d . check ( word ) else [ ] <EOL> return HttpResponse ( json . dumps ( { '<STR_LIT:data>' : suggestions } ) ) </s>
