<s> from __future__ import unicode_literals <EOL> from django . contrib import messages <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import HttpResponseRedirect <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . views . generic import DeleteView <EOL> from django . views . generic import FormView <EOL> from django . views . generic import ListView <EOL> from django . views . generic . detail import SingleObjectMixin <EOL> from machina . apps . forum_conversation . signals import topic_viewed <EOL> from machina . apps . forum_conversation . utils import get_client_ip <EOL> from machina . conf import settings as machina_settings <EOL> from machina . core . db . models import get_model <EOL> from machina . core . loading import get_class <EOL> Attachment = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Forum = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Post = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Topic = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> TopicPollOption = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> AttachmentFormset = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> PostForm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> TopicForm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> TopicPollOptionFormset = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> TopicPollVoteForm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> attachments_cache = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> PermissionRequiredMixin = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TopicView ( PermissionRequiredMixin , ListView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> context_object_name = '<STR_LIT>' <EOL> permission_required = [ '<STR_LIT>' , ] <EOL> paginate_by = machina_settings . TOPIC_POSTS_NUMBER_PER_PAGE <EOL> view_signal = topic_viewed <EOL> poll_form_class = TopicPollVoteForm <EOL> def get ( self , request , ** kwargs ) : <EOL> topic = self . get_topic ( ) <EOL> requested_post = request . GET . get ( '<STR_LIT>' , None ) <EOL> if requested_post : <EOL> try : <EOL> assert requested_post . isdigit ( ) <EOL> post = topic . posts . get ( pk = requested_post ) <EOL> requested_page = ( post . position // machina_settings . TOPIC_POSTS_NUMBER_PER_PAGE ) + <NUM_LIT:1> <EOL> request . GET = request . GET . copy ( ) <EOL> request . GET . update ( { '<STR_LIT>' : requested_page } ) <EOL> except ( Post . DoesNotExist , AssertionError ) : <EOL> pass <EOL> response = super ( TopicView , self ) . get ( request , ** kwargs ) <EOL> self . send_signal ( request , response , topic ) <EOL> return response <EOL> def get_topic ( self ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . topic = get_object_or_404 ( Topic , pk = self . kwargs [ '<STR_LIT>' ] ) <EOL> return self . topic <EOL> def get_queryset ( self ) : <EOL> self . topic = self . get_topic ( ) <EOL> qs = self . topic . posts . all ( ) . exclude ( approved = False ) . select_related ( '<STR_LIT>' ) . prefetch_related ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return qs <EOL> def get_controlled_object ( self ) : <EOL> return self . get_topic ( ) . forum <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( TopicView , self ) . get_context_data ( ** kwargs ) <EOL> topic = self . get_topic ( ) <EOL> context [ '<STR_LIT>' ] = topic <EOL> context [ '<STR_LIT>' ] = topic . forum <EOL> try : <EOL> if hasattr ( topic , '<STR_LIT>' ) and topic . poll . options . exists ( ) : <EOL> context [ '<STR_LIT>' ] = topic . poll <EOL> context [ '<STR_LIT>' ] = self . poll_form_class ( poll = topic . poll ) <EOL> context [ '<STR_LIT>' ] = self . request . GET . get ( '<STR_LIT>' , None ) <EOL> context [ '<STR_LIT>' ] = self . request . GET . get ( '<STR_LIT>' , None ) <EOL> except ObjectDoesNotExist : <EOL> pass <EOL> return context <EOL> def send_signal ( self , request , response , topic ) : <EOL> self . view_signal . send ( <EOL> sender = self , topic = topic , user = request . user , <EOL> request = request , response = response ) <EOL> class BasePostFormView ( FormView ) : <EOL> """<STR_LIT>""" <EOL> post_form_class = PostForm <EOL> attachment_formset_class = AttachmentFormset <EOL> post_pk_url_kwarg = None <EOL> topic_pk_url_kwarg = None <EOL> forum_pk_url_kwarg = None <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> approval_required_message = _ ( '<STR_LIT>' ) <EOL> attachment_formset_general_error_message = _ ( <EOL> '<STR_LIT>' ) <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> self . init_attachment_cache ( ) <EOL> post_form_class = self . get_post_form_class ( ) <EOL> post_form = self . get_post_form ( post_form_class ) <EOL> attachment_formset_class = self . get_attachment_formset_class ( ) <EOL> attachment_formset = self . get_attachment_formset ( attachment_formset_class ) <EOL> return self . render_to_response ( <EOL> self . get_context_data ( <EOL> post_form = post_form , <EOL> attachment_formset = attachment_formset ) ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> self . init_attachment_cache ( ) <EOL> self . preview = '<STR_LIT>' in self . request . POST <EOL> post_form_class = self . get_post_form_class ( ) <EOL> post_form = self . get_post_form ( post_form_class ) <EOL> attachment_formset_class = self . get_attachment_formset_class ( ) <EOL> attachment_formset = self . get_attachment_formset ( attachment_formset_class ) <EOL> self . attachment_preview = self . preview if attachment_formset and attachment_formset . is_valid ( ) else None <EOL> post_form_valid = post_form . is_valid ( ) <EOL> if ( post_form_valid and attachment_formset is None ) or ( post_form_valid and attachment_formset . is_valid ( ) ) : <EOL> return self . form_valid ( post_form , attachment_formset ) <EOL> else : <EOL> return self . form_invalid ( post_form , attachment_formset ) <EOL> def init_attachment_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . request . method == '<STR_LIT:GET>' : <EOL> attachments_cache . delete ( self . get_attachments_cache_key ( self . request ) ) <EOL> return <EOL> attachments_cache_key = self . get_attachments_cache_key ( self . request ) <EOL> restored_attachments_dict = attachments_cache . get ( attachments_cache_key ) <EOL> if restored_attachments_dict : <EOL> restored_attachments_dict . update ( self . request . FILES ) <EOL> self . request . _files = restored_attachments_dict <EOL> if self . request . FILES : <EOL> attachments_cache . set ( attachments_cache_key , self . request . FILES ) <EOL> def get_attachments_cache_key ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . format ( request . session . session_key ) <EOL> def get_post_form_class ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . post_form_class <EOL> def get_post_form ( self , form_class ) : <EOL> """<STR_LIT>""" <EOL> return form_class ( ** self . get_post_form_kwargs ( ) ) <EOL> def get_post_form_kwargs ( self ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { <EOL> '<STR_LIT:user>' : self . request . user , <EOL> '<STR_LIT>' : get_client_ip ( self . request ) , <EOL> '<STR_LIT>' : self . get_forum ( ) , <EOL> '<STR_LIT>' : self . get_topic ( ) , <EOL> } <EOL> post = self . get_post ( ) <EOL> if post : <EOL> kwargs . update ( { '<STR_LIT>' : post } ) <EOL> if self . request . method in ( '<STR_LIT:POST>' , '<STR_LIT>' ) : <EOL> kwargs . update ( { <EOL> '<STR_LIT:data>' : self . request . POST , <EOL> '<STR_LIT>' : self . request . FILES , <EOL> } ) <EOL> return kwargs <EOL> def get_attachment_formset_class ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . attachment_formset_class <EOL> def get_attachment_formset ( self , formset_class ) : <EOL> """<STR_LIT>""" <EOL> if self . request . forum_permission_handler . can_attach_files ( <EOL> self . get_forum ( ) , self . request . user ) : <EOL> return formset_class ( ** self . get_attachment_formset_kwargs ( ) ) <EOL> def get_attachment_formset_kwargs ( self ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if self . request . method in ( '<STR_LIT:POST>' , '<STR_LIT>' ) : <EOL> kwargs . update ( { <EOL> '<STR_LIT:data>' : self . request . POST , <EOL> '<STR_LIT>' : self . request . FILES , <EOL> } ) <EOL> else : <EOL> post = self . get_post ( ) <EOL> attachment_queryset = Attachment . objects . filter ( post = post ) <EOL> kwargs . update ( { <EOL> '<STR_LIT>' : attachment_queryset , <EOL> } ) <EOL> return kwargs <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = kwargs <EOL> if '<STR_LIT>' not in context : <EOL> context [ '<STR_LIT>' ] = self <EOL> context [ '<STR_LIT>' ] = self . get_forum ( ) <EOL> context [ '<STR_LIT>' ] = self . get_topic ( ) <EOL> context [ '<STR_LIT>' ] = self . get_post ( ) <EOL> if context [ '<STR_LIT>' ] : <EOL> if hasattr ( self , '<STR_LIT>' ) and self . attachment_preview : <EOL> context [ '<STR_LIT>' ] = self . attachment_preview <EOL> attachments = [ ] <EOL> for form in context [ '<STR_LIT>' ] . forms : <EOL> if form [ '<STR_LIT>' ] . value ( ) or ( not form [ '<STR_LIT:file>' ] . html_name in self . request . _files and <EOL> not form . instance . pk ) : <EOL> continue <EOL> attachments . append ( <EOL> ( <EOL> form , <EOL> self . request . _files [ form [ '<STR_LIT:file>' ] . html_name ] . name if not form . instance <EOL> else form . instance . filename <EOL> ) ) <EOL> context [ '<STR_LIT>' ] = attachments <EOL> return context <EOL> def get_forum ( self ) : <EOL> """<STR_LIT>""" <EOL> pk = self . kwargs . get ( self . forum_pk_url_kwarg , None ) <EOL> if not pk : <EOL> return <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _forum = get_object_or_404 ( Forum , pk = pk ) <EOL> return self . _forum <EOL> def get_topic ( self ) : <EOL> """<STR_LIT>""" <EOL> pk = self . kwargs . get ( self . topic_pk_url_kwarg , None ) <EOL> if not pk : <EOL> return <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _topic = get_object_or_404 ( Topic , pk = pk ) <EOL> return self . _topic <EOL> def get_post ( self ) : <EOL> """<STR_LIT>""" <EOL> pk = self . kwargs . get ( self . post_pk_url_kwarg , None ) <EOL> if not pk : <EOL> return <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _forum_post = get_object_or_404 ( Post , pk = pk ) <EOL> return self . _forum_post <EOL> def form_valid ( self , post_form , attachment_formset , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> save_attachment_formset = attachment_formset is not None and not self . preview <EOL> if self . preview : <EOL> return self . render_to_response ( <EOL> self . get_context_data ( <EOL> preview = True , <EOL> post_form = post_form , <EOL> attachment_formset = attachment_formset , ** kwargs ) ) <EOL> self . forum_post = post_form . save ( ) <EOL> if save_attachment_formset : <EOL> attachment_formset . post = self . forum_post <EOL> attachment_formset . save ( ) <EOL> messages . success ( self . request , self . success_message ) <EOL> if not self . forum_post . approved : <EOL> messages . warning ( self . request , self . approval_required_message ) <EOL> return HttpResponseRedirect ( self . get_success_url ( ) ) <EOL> def form_invalid ( self , post_form , attachment_formset , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if attachment_formset and not attachment_formset . is_valid ( ) and len ( attachment_formset . errors ) : <EOL> messages . error ( <EOL> self . request , self . attachment_formset_general_error_message ) <EOL> return self . render_to_response ( <EOL> self . get_context_data ( <EOL> post_form = post_form , <EOL> attachment_formset = attachment_formset , ** kwargs ) ) <EOL> class BaseTopicFormView ( BasePostFormView ) : <EOL> """<STR_LIT>""" <EOL> post_form_class = TopicForm <EOL> poll_option_formset_class = TopicPollOptionFormset <EOL> poll_option_formset_general_error_message = _ ( <EOL> '<STR_LIT>' ) <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> self . init_attachment_cache ( ) <EOL> post_form_class = self . get_post_form_class ( ) <EOL> post_form = self . get_post_form ( post_form_class ) <EOL> attachment_formset_class = self . get_attachment_formset_class ( ) <EOL> attachment_formset = self . get_attachment_formset ( attachment_formset_class ) <EOL> poll_option_formset_class = self . get_poll_option_formset_class ( ) <EOL> poll_option_formset = self . get_poll_option_formset ( poll_option_formset_class ) <EOL> return self . render_to_response ( <EOL> self . get_context_data ( <EOL> post_form = post_form , <EOL> attachment_formset = attachment_formset , <EOL> poll_option_formset = poll_option_formset ) ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> self . init_attachment_cache ( ) <EOL> self . preview = '<STR_LIT>' in self . request . POST <EOL> post_form_class = self . get_post_form_class ( ) <EOL> post_form = self . get_post_form ( post_form_class ) <EOL> attachment_formset_class = self . get_attachment_formset_class ( ) <EOL> attachment_formset = self . get_attachment_formset ( attachment_formset_class ) <EOL> poll_option_formset_class = self . get_poll_option_formset_class ( ) <EOL> poll_option_formset = self . get_poll_option_formset ( poll_option_formset_class ) <EOL> post_form_valid = post_form . is_valid ( ) <EOL> attachment_formset_valid = attachment_formset . is_valid ( ) if attachment_formset else None <EOL> poll_option_formset_valid = poll_option_formset . is_valid ( ) if poll_option_formset and len ( post_form . cleaned_data [ '<STR_LIT>' ] ) else None <EOL> self . attachment_preview = self . preview if attachment_formset_valid else None <EOL> self . poll_preview = self . preview if poll_option_formset_valid else None <EOL> poll_options_validated = poll_option_formset_valid is not None <EOL> if post_form_valid and attachment_formset_valid is not False and poll_option_formset_valid is not False : <EOL> return self . form_valid ( <EOL> post_form , attachment_formset , poll_option_formset , <EOL> poll_options_validated = poll_options_validated ) <EOL> else : <EOL> return self . form_invalid ( <EOL> post_form , attachment_formset , poll_option_formset , <EOL> poll_options_validated = poll_options_validated ) <EOL> def get_poll_option_formset_class ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . poll_option_formset_class <EOL> def get_poll_option_formset ( self , formset_class ) : <EOL> """<STR_LIT>""" <EOL> if self . request . forum_permission_handler . can_create_polls ( <EOL> self . get_forum ( ) , self . request . user ) : <EOL> return formset_class ( ** self . get_poll_option_formset_kwargs ( ) ) <EOL> def get_poll_option_formset_kwargs ( self ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if self . request . method in ( '<STR_LIT:POST>' , '<STR_LIT>' ) : <EOL> kwargs . update ( { <EOL> '<STR_LIT:data>' : self . request . POST , <EOL> '<STR_LIT>' : self . request . FILES , <EOL> } ) <EOL> else : <EOL> topic = self . get_topic ( ) <EOL> poll_option_queryset = TopicPollOption . objects . filter ( poll__topic = topic ) <EOL> kwargs . update ( { <EOL> '<STR_LIT>' : poll_option_queryset , <EOL> } ) <EOL> return kwargs <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( BaseTopicFormView , self ) . get_context_data ( ** kwargs ) <EOL> if context [ '<STR_LIT>' ] : <EOL> if hasattr ( self , '<STR_LIT>' ) and self . poll_preview : <EOL> context [ '<STR_LIT>' ] = self . poll_preview <EOL> context [ '<STR_LIT>' ] = filter ( <EOL> lambda f : f [ '<STR_LIT:text>' ] . value ( ) and not f [ '<STR_LIT>' ] . value ( ) , <EOL> context [ '<STR_LIT>' ] . forms ) <EOL> return context <EOL> def form_valid ( self , post_form , attachment_formset , poll_option_formset , ** kwargs ) : <EOL> save_poll_option_formset = poll_option_formset is not None and not self . preview <EOL> valid = super ( BaseTopicFormView , self ) . form_valid ( <EOL> post_form , attachment_formset , poll_option_formset = poll_option_formset , ** kwargs ) <EOL> if save_poll_option_formset : <EOL> poll_option_formset . topic = self . forum_post . topic <EOL> poll_option_formset . save ( <EOL> poll_question = post_form . cleaned_data . pop ( '<STR_LIT>' , None ) , <EOL> poll_max_options = post_form . cleaned_data . pop ( '<STR_LIT>' , None ) , <EOL> poll_duration = post_form . cleaned_data . pop ( '<STR_LIT>' , None ) , <EOL> poll_user_changes = post_form . cleaned_data . pop ( '<STR_LIT>' , None ) , <EOL> ) <EOL> return valid <EOL> def form_invalid ( self , post_form , attachment_formset , poll_option_formset , ** kwargs ) : <EOL> poll_errors = [ k for k in post_form . errors . keys ( ) if k . startswith ( '<STR_LIT>' ) ] <EOL> if poll_errors or ( poll_option_formset and not poll_option_formset . is_valid ( ) and <EOL> len ( post_form . cleaned_data [ '<STR_LIT>' ] ) ) : <EOL> messages . error ( self . request , self . poll_option_formset_general_error_message ) <EOL> return super ( BaseTopicFormView , self ) . form_invalid ( <EOL> post_form , attachment_formset , poll_option_formset = poll_option_formset , ** kwargs ) <EOL> class PostFormView ( SingleObjectMixin , BasePostFormView ) : <EOL> """<STR_LIT>""" <EOL> post_pk_url_kwarg = '<STR_LIT>' <EOL> topic_pk_url_kwarg = '<STR_LIT>' <EOL> forum_pk_url_kwarg = '<STR_LIT>' <EOL> class TopicFormView ( SingleObjectMixin , BaseTopicFormView ) : <EOL> """<STR_LIT>""" <EOL> topic_pk_url_kwarg = '<STR_LIT>' <EOL> forum_pk_url_kwarg = '<STR_LIT>' <EOL> class TopicCreateView ( PermissionRequiredMixin , TopicFormView ) : <EOL> """<STR_LIT>""" <EOL> model = Topic <EOL> template_name = '<STR_LIT>' <EOL> permission_required = [ '<STR_LIT>' , ] <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> self . object = None <EOL> return super ( TopicCreateView , self ) . get ( request , * args , ** kwargs ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> self . object = None <EOL> return super ( TopicCreateView , self ) . post ( request , * args , ** kwargs ) <EOL> def get_success_url ( self ) : <EOL> if not self . forum_post . approved : <EOL> return reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . forum_post . topic . forum . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . forum . pk } ) <EOL> return reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . forum_post . topic . forum . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . forum . pk , <EOL> '<STR_LIT>' : self . forum_post . topic . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . pk } ) <EOL> def get_controlled_object ( self ) : <EOL> return self . get_forum ( ) <EOL> class TopicUpdateView ( PermissionRequiredMixin , TopicFormView ) : <EOL> """<STR_LIT>""" <EOL> model = Topic <EOL> template_name = '<STR_LIT>' <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> self . object = self . get_object ( ) <EOL> return super ( TopicUpdateView , self ) . get ( request , * args , ** kwargs ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> self . object = self . get_object ( ) <EOL> return super ( TopicUpdateView , self ) . post ( request , * args , ** kwargs ) <EOL> def get_object ( self , queryset = None ) : <EOL> return self . get_topic ( ) <EOL> def get_post ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . get_topic ( ) . first_post <EOL> def get_success_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . forum_post . topic . forum . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . forum . pk , <EOL> '<STR_LIT>' : self . forum_post . topic . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . pk } ) <EOL> def get_controlled_object ( self ) : <EOL> return self . get_topic ( ) . first_post <EOL> def perform_permissions_check ( self , user , obj , perms ) : <EOL> return self . request . forum_permission_handler . can_edit_post ( obj , user ) <EOL> class PostCreateView ( PermissionRequiredMixin , PostFormView ) : <EOL> """<STR_LIT>""" <EOL> model = Post <EOL> template_name = '<STR_LIT>' <EOL> permission_required = [ '<STR_LIT>' , ] <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> self . object = None <EOL> return super ( PostCreateView , self ) . get ( request , * args , ** kwargs ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> self . object = None <EOL> return super ( PostCreateView , self ) . post ( request , * args , ** kwargs ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PostCreateView , self ) . get_context_data ( ** kwargs ) <EOL> topic = self . get_topic ( ) <EOL> previous_posts = topic . posts . filter ( approved = True ) . order_by ( '<STR_LIT>' ) <EOL> previous_posts = previous_posts [ : machina_settings . TOPIC_REVIEW_POSTS_NUMBER ] <EOL> context [ '<STR_LIT>' ] = previous_posts <EOL> return context <EOL> def get_success_url ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . forum_post . topic . forum . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . forum . pk , <EOL> '<STR_LIT>' : self . forum_post . topic . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . pk } ) , <EOL> self . forum_post . pk ) <EOL> def get_controlled_object ( self ) : <EOL> return self . get_forum ( ) <EOL> class PostUpdateView ( PermissionRequiredMixin , PostFormView ) : <EOL> """<STR_LIT>""" <EOL> model = Post <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> template_name = '<STR_LIT>' <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> self . object = self . get_object ( ) <EOL> return super ( PostUpdateView , self ) . get ( request , * args , ** kwargs ) <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> self . object = self . get_object ( ) <EOL> return super ( PostUpdateView , self ) . post ( request , * args , ** kwargs ) <EOL> def get_object ( self , queryset = None ) : <EOL> return self . get_post ( ) <EOL> def get_success_url ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . forum_post . topic . forum . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . forum . pk , <EOL> '<STR_LIT>' : self . forum_post . topic . slug , <EOL> '<STR_LIT>' : self . forum_post . topic . pk } ) , <EOL> self . forum_post . pk ) <EOL> def get_controlled_object ( self ) : <EOL> return self . get_post ( ) <EOL> def perform_permissions_check ( self , user , obj , perms ) : <EOL> return self . request . forum_permission_handler . can_edit_post ( obj , user ) <EOL> class PostDeleteView ( PermissionRequiredMixin , DeleteView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> success_message = _ ( '<STR_LIT>' ) <EOL> model = Post <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PostDeleteView , self ) . get_context_data ( ** kwargs ) <EOL> post = self . get_object ( ) <EOL> context [ '<STR_LIT>' ] = post . topic <EOL> context [ '<STR_LIT>' ] = post . topic . forum <EOL> return context <EOL> def delete ( self , request , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object = self . get_object ( ) <EOL> success_url = self . get_success_url ( ) <EOL> self . object . delete ( ) <EOL> return HttpResponseRedirect ( success_url ) <EOL> def get_success_url ( self ) : <EOL> messages . success ( self . request , self . success_message ) <EOL> if self . object . is_topic_head and self . object . is_topic_tail : <EOL> return reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . object . topic . forum . slug , <EOL> '<STR_LIT>' : self . object . topic . forum . pk } ) <EOL> return reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . object . topic . forum . slug , <EOL> '<STR_LIT>' : self . object . topic . forum . pk , <EOL> '<STR_LIT>' : self . object . topic . slug , <EOL> '<STR_LIT>' : self . object . topic . pk } ) <EOL> def get_controlled_object ( self ) : <EOL> return self . get_object ( ) <EOL> def perform_permissions_check ( self , user , obj , perms ) : <EOL> return self . request . forum_permission_handler . can_delete_post ( obj , user ) </s>
