idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
241,200 | def editpermissions_index_view ( self , request , forum_id = None ) : forum = get_object_or_404 ( Forum , pk = forum_id ) if forum_id else None # Set up the context context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ] = _ ( 'Forum permissions' ) if forum else _ ( 'Global forum permissions' ) # Handles "copy permission from" form permissions_copied = False if forum and request . method == 'POST' : forum_form = PickForumForm ( request . POST ) if forum_form . is_valid ( ) and forum_form . cleaned_data [ 'forum' ] : self . _copy_forum_permissions ( forum_form . cleaned_data [ 'forum' ] , forum ) self . message_user ( request , _ ( 'Permissions successfully copied' ) ) permissions_copied = True context [ 'forum_form' ] = forum_form elif forum : context [ 'forum_form' ] = PickForumForm ( ) # Handles user or group selection if request . method == 'POST' and not permissions_copied : user_form = PickUserForm ( request . POST , admin_site = self . admin_site ) group_form = PickGroupForm ( request . POST , admin_site = self . admin_site ) if user_form . is_valid ( ) and group_form . is_valid ( ) : user = user_form . cleaned_data . get ( 'user' , None ) if user_form . cleaned_data else None anonymous_user = ( user_form . cleaned_data . get ( 'anonymous_user' , None ) if user_form . cleaned_data else None ) group = ( group_form . cleaned_data . get ( 'group' , None ) if group_form . cleaned_data else None ) if not user and not anonymous_user and not group : user_form . _errors [ NON_FIELD_ERRORS ] = user_form . error_class ( [ _ ( 'Choose either a user ID, a group ID or the anonymous user' ) , ] ) elif user : # Redirect to user url_kwargs = ( { 'forum_id' : forum . id , 'user_id' : user . id } if forum else { 'user_id' : user . id } ) return redirect ( reverse ( 'admin:forum_forum_editpermission_user' , kwargs = url_kwargs ) , ) elif anonymous_user : # Redirect to anonymous user url_kwargs = { 'forum_id' : forum . id } if forum else { } return redirect ( reverse ( 'admin:forum_forum_editpermission_anonymous_user' , kwargs = url_kwargs , ) , ) elif group : # Redirect to group url_kwargs = ( { 'forum_id' : forum . id , 'group_id' : group . id } if forum else { 'group_id' : group . id } ) return redirect ( reverse ( 'admin:forum_forum_editpermission_group' , kwargs = url_kwargs ) , ) context [ 'user_errors' ] = helpers . AdminErrorList ( user_form , [ ] ) context [ 'group_errors' ] = helpers . AdminErrorList ( group_form , [ ] ) else : user_form = PickUserForm ( admin_site = self . admin_site ) group_form = PickGroupForm ( admin_site = self . admin_site ) context [ 'user_form' ] = user_form context [ 'group_form' ] = group_form return render ( request , self . editpermissions_index_view_template_name , context ) | Allows to select how to edit forum permissions . | 839 | 9 |
241,201 | def editpermissions_user_view ( self , request , user_id , forum_id = None ) : user_model = get_user_model ( ) user = get_object_or_404 ( user_model , pk = user_id ) forum = get_object_or_404 ( Forum , pk = forum_id ) if forum_id else None # Set up the context context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ] = '{} - {}' . format ( _ ( 'Forum permissions' ) , user ) context [ 'form' ] = self . _get_permissions_form ( request , UserForumPermission , { 'forum' : forum , 'user' : user } , ) return render ( request , self . editpermissions_user_view_template_name , context ) | Allows to edit user permissions for the considered forum . | 201 | 10 |
241,202 | def editpermissions_anonymous_user_view ( self , request , forum_id = None ) : forum = get_object_or_404 ( Forum , pk = forum_id ) if forum_id else None # Set up the context context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ] = '{} - {}' . format ( _ ( 'Forum permissions' ) , _ ( 'Anonymous user' ) ) context [ 'form' ] = self . _get_permissions_form ( request , UserForumPermission , { 'forum' : forum , 'anonymous_user' : True } , ) return render ( request , self . editpermissions_anonymous_user_view_template_name , context ) | Allows to edit anonymous user permissions for the considered forum . | 180 | 11 |
241,203 | def editpermissions_group_view ( self , request , group_id , forum_id = None ) : group = get_object_or_404 ( Group , pk = group_id ) forum = get_object_or_404 ( Forum , pk = forum_id ) if forum_id else None # Set up the context context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ] = '{} - {}' . format ( _ ( 'Forum permissions' ) , group ) context [ 'form' ] = self . _get_permissions_form ( request , GroupForumPermission , { 'forum' : forum , 'group' : group } , ) return render ( request , self . editpermissions_group_view_template_name , context ) | Allows to edit group permissions for the considered forum . | 188 | 10 |
241,204 | def get_permission ( context , method , * args , * * kwargs ) : request = context . get ( 'request' , None ) perm_handler = request . forum_permission_handler if request else PermissionHandler ( ) allowed_methods = inspect . getmembers ( perm_handler , predicate = inspect . ismethod ) allowed_method_names = [ a [ 0 ] for a in allowed_methods if not a [ 0 ] . startswith ( '_' ) ] if method not in allowed_method_names : raise template . TemplateSyntaxError ( 'Only the following methods are allowed through ' 'this templatetag: {}' . format ( allowed_method_names ) ) perm_method = getattr ( perm_handler , method ) return perm_method ( * args , * * kwargs ) | This will return a boolean indicating if the considered permission is granted for the passed user . | 181 | 17 |
241,205 | def total_form_count ( self ) : total_forms = super ( ) . total_form_count ( ) if not self . data and not self . files and self . initial_form_count ( ) > 0 : total_forms -= self . extra return total_forms | This rewrite of total_form_count allows to add an empty form to the formset only when no initial data is provided . | 59 | 26 |
241,206 | def get_classes ( module_label , classnames ) : app_label = module_label . split ( '.' ) [ 0 ] app_module_path = _get_app_module_path ( module_label ) if not app_module_path : raise AppNotFoundError ( 'No app found matching \'{}\'' . format ( module_label ) ) # Determines the full module path by appending the module label # to the base package path of the considered application. module_path = app_module_path if '.' in app_module_path : base_package = app_module_path . rsplit ( '.' + app_label , 1 ) [ 0 ] module_path = '{}.{}' . format ( base_package , module_label ) # Try to import this module from the related app that is specified # in the Django settings. local_imported_module = _import_module ( module_path , classnames ) # If the module we tried to import is not located inside the machina # vanilla apps, try to import it from the corresponding machina app. machina_imported_module = None if not app_module_path . startswith ( 'machina.apps' ) : machina_imported_module = _import_module ( '{}.{}' . format ( 'machina.apps' , module_label ) , classnames , ) if local_imported_module is None and machina_imported_module is None : raise AppNotFoundError ( 'Error importing \'{}\'' . format ( module_path ) ) # Any local module is prioritized over the corresponding machina module imported_modules = [ m for m in ( local_imported_module , machina_imported_module ) if m is not None ] return _pick_up_classes ( imported_modules , classnames ) | Imports a set of classes from a given module . | 406 | 11 |
241,207 | def _import_module ( module_path , classnames ) : try : imported_module = __import__ ( module_path , fromlist = classnames ) return imported_module except ImportError : # In case of an ImportError, the module being loaded generally does not exist. But an # ImportError can occur if the module being loaded exists and another import located inside # it failed. # # In order to provide a meaningfull traceback, the execution information can be inspected in # order to determine which case to consider. If the execution information provides more than # a certain amount of frames, this means that an ImportError occured while loading the # initial Python module. __ , __ , exc_traceback = sys . exc_info ( ) frames = traceback . extract_tb ( exc_traceback ) if len ( frames ) > 1 : raise | Tries to import the given Python module path . | 179 | 10 |
241,208 | def _pick_up_classes ( modules , classnames ) : klasses = [ ] for classname in classnames : klass = None for module in modules : if hasattr ( module , classname ) : klass = getattr ( module , classname ) break if not klass : raise ClassNotFoundError ( 'Error fetching \'{}\' in {}' . format ( classname , str ( [ module . __name__ for module in modules ] ) ) ) klasses . append ( klass ) return klasses | Given a list of class names to retrieve try to fetch them from the specified list of modules and returns the list of the fetched classes . | 112 | 28 |
241,209 | def _get_app_module_path ( module_label ) : app_name = module_label . rsplit ( '.' , 1 ) [ 0 ] for app in settings . INSTALLED_APPS : if app . endswith ( '.' + app_name ) or app == app_name : return app return None | Given a module label loop over the apps specified in the INSTALLED_APPS to find the corresponding application module path . | 71 | 25 |
241,210 | def get_unread_forums ( self , user ) : return self . get_unread_forums_from_list ( user , self . perm_handler . get_readable_forums ( Forum . objects . all ( ) , user ) ) | Returns the list of unread forums for the given user . | 52 | 12 |
241,211 | def get_unread_forums_from_list ( self , user , forums ) : unread_forums = [ ] # A user which is not authenticated will never see a forum as unread if not user . is_authenticated : return unread_forums unread = ForumReadTrack . objects . get_unread_forums_from_list ( forums , user ) unread_forums . extend ( unread ) return unread_forums | Returns the list of unread forums for the given user from a given list of forums . | 94 | 18 |
241,212 | def get_unread_topics ( self , topics , user ) : unread_topics = [ ] # A user which is not authenticated will never see a topic as unread. # If there are no topics to consider, we stop here. if not user . is_authenticated or topics is None or not len ( topics ) : return unread_topics # A topic can be unread if a track for itself exists with a mark time that # is less important than its update date. topic_ids = [ topic . id for topic in topics ] topic_tracks = TopicReadTrack . objects . filter ( topic__in = topic_ids , user = user ) tracked_topics = dict ( topic_tracks . values_list ( 'topic__pk' , 'mark_time' ) ) if tracked_topics : for topic in topics : topic_last_modification_date = topic . last_post_on or topic . created if ( topic . id in tracked_topics . keys ( ) and topic_last_modification_date > tracked_topics [ topic . id ] ) : unread_topics . append ( topic ) # A topic can be unread if a track for its associated forum exists with # a mark time that is less important than its creation or update date. forum_ids = [ topic . forum_id for topic in topics ] forum_tracks = ForumReadTrack . objects . filter ( forum_id__in = forum_ids , user = user ) tracked_forums = dict ( forum_tracks . values_list ( 'forum__pk' , 'mark_time' ) ) if tracked_forums : for topic in topics : topic_last_modification_date = topic . last_post_on or topic . created if ( ( topic . forum_id in tracked_forums . keys ( ) and topic . id not in tracked_topics ) and topic_last_modification_date > tracked_forums [ topic . forum_id ] ) : unread_topics . append ( topic ) # A topic can be unread if no tracks exists for it for topic in topics : if topic . forum_id not in tracked_forums and topic . id not in tracked_topics : unread_topics . append ( topic ) return list ( set ( unread_topics ) ) | Returns a list of unread topics for the given user from a given set of topics . | 498 | 18 |
241,213 | def mark_forums_read ( self , forums , user ) : if not forums or not user . is_authenticated : return forums = sorted ( forums , key = lambda f : f . level ) # Update all forum tracks to the current date for the considered forums for forum in forums : forum_track = ForumReadTrack . objects . get_or_create ( forum = forum , user = user ) [ 0 ] forum_track . save ( ) # Delete all the unnecessary topic tracks TopicReadTrack . objects . filter ( topic__forum__in = forums , user = user ) . delete ( ) # Update parent forum tracks self . _update_parent_forum_tracks ( forums [ 0 ] , user ) | Marks a list of forums as read . | 148 | 9 |
241,214 | def mark_topic_read ( self , topic , user ) : if not user . is_authenticated : return forum = topic . forum try : forum_track = ForumReadTrack . objects . get ( forum = forum , user = user ) except ForumReadTrack . DoesNotExist : forum_track = None if ( forum_track is None or ( topic . last_post_on and forum_track . mark_time < topic . last_post_on ) ) : topic_track , created = TopicReadTrack . objects . get_or_create ( topic = topic , user = user ) if not created : topic_track . save ( ) # mark_time filled # If no other topic is unread inside the considered forum, the latter should also be # marked as read. unread_topics = ( forum . topics . filter ( Q ( tracks__user = user , tracks__mark_time__lt = F ( 'last_post_on' ) ) | Q ( forum__tracks__user = user , forum__tracks__mark_time__lt = F ( 'last_post_on' ) , tracks__isnull = True , ) ) . exclude ( id = topic . id ) ) forum_topic_tracks = TopicReadTrack . objects . filter ( topic__forum = forum , user = user ) if ( not unread_topics . exists ( ) and ( forum_track is not None or forum_topic_tracks . count ( ) == forum . topics . filter ( approved = True ) . count ( ) ) ) : # The topics that are marked as read inside the forum for the given user will be # deleted while the forum track associated with the user must be created or updated. # This is done only if there are as many topic tracks as approved topics in case # the related forum has not beem previously marked as read. TopicReadTrack . objects . filter ( topic__forum = forum , user = user ) . delete ( ) forum_track , _ = ForumReadTrack . objects . get_or_create ( forum = forum , user = user ) forum_track . save ( ) # Update parent forum tracks self . _update_parent_forum_tracks ( forum , user ) | Marks a topic as read . | 467 | 7 |
241,215 | def clean ( self ) : super ( ) . clean ( ) if self . parent and self . parent . is_link : raise ValidationError ( _ ( 'A forum can not have a link forum as parent' ) ) if self . is_category and self . parent and self . parent . is_category : raise ValidationError ( _ ( 'A category can not have another category as parent' ) ) if self . is_link and not self . link : raise ValidationError ( _ ( 'A link forum must have a link associated with it' ) ) | Validates the forum instance . | 119 | 6 |
241,216 | def get_image_upload_to ( self , filename ) : dummy , ext = os . path . splitext ( filename ) return os . path . join ( machina_settings . FORUM_IMAGE_UPLOAD_TO , '{id}{ext}' . format ( id = str ( uuid . uuid4 ( ) ) . replace ( '-' , '' ) , ext = ext ) , ) | Returns the path to upload a new associated image to . | 90 | 11 |
241,217 | def save ( self , * args , * * kwargs ) : # It is vital to track the changes of the parent associated with a forum in order to # maintain counters up-to-date and to trigger other operations such as permissions updates. old_instance = None if self . pk : old_instance = self . __class__ . _default_manager . get ( pk = self . pk ) # Update the slug field self . slug = slugify ( force_text ( self . name ) , allow_unicode = True ) # Do the save super ( ) . save ( * args , * * kwargs ) # If any change has been made to the forum parent, trigger the update of the counters if old_instance and old_instance . parent != self . parent : self . update_trackers ( ) # Trigger the 'forum_moved' signal signals . forum_moved . send ( sender = self , previous_parent = old_instance . parent ) | Saves the forum instance . | 208 | 6 |
241,218 | def update_trackers ( self ) : direct_approved_topics = self . topics . filter ( approved = True ) . order_by ( '-last_post_on' ) # Compute the direct topics count and the direct posts count. self . direct_topics_count = direct_approved_topics . count ( ) self . direct_posts_count = direct_approved_topics . aggregate ( total_posts_count = Sum ( 'posts_count' ) ) [ 'total_posts_count' ] or 0 # Forces the forum's 'last_post' ID and 'last_post_on' date to the corresponding values # associated with the topic with the latest post. if direct_approved_topics . exists ( ) : self . last_post_id = direct_approved_topics [ 0 ] . last_post_id self . last_post_on = direct_approved_topics [ 0 ] . last_post_on else : self . last_post_id = None self . last_post_on = None # Any save of a forum triggered from the update_tracker process will not result in checking # for a change of the forum's parent. self . _simple_save ( ) | Updates the denormalized trackers associated with the forum instance . | 264 | 14 |
241,219 | def get_unread_topics ( context , topics , user ) : request = context . get ( 'request' , None ) return TrackingHandler ( request = request ) . get_unread_topics ( topics , user ) | This will return a list of unread topics for the given user from a given set of topics . | 49 | 20 |
241,220 | def resize_image ( self , data , size ) : from machina . core . compat import PILImage as Image image = Image . open ( BytesIO ( data ) ) # Resize! image . thumbnail ( size , Image . ANTIALIAS ) string = BytesIO ( ) image . save ( string , format = 'PNG' ) return string . getvalue ( ) | Resizes the given image to fit inside a box of the given size . | 82 | 15 |
241,221 | def get_backend ( self ) : try : cache = caches [ machina_settings . ATTACHMENT_CACHE_NAME ] except InvalidCacheBackendError : raise ImproperlyConfigured ( 'The attachment cache backend ({}) is not configured' . format ( machina_settings . ATTACHMENT_CACHE_NAME , ) , ) return cache | Returns the associated cache backend . | 78 | 6 |
241,222 | def set ( self , key , files ) : files_states = { } for name , upload in files . items ( ) : # Generates the state of the file state = { 'name' : upload . name , 'size' : upload . size , 'content_type' : upload . content_type , 'charset' : upload . charset , 'content' : upload . file . read ( ) , } files_states [ name ] = state # Go to the first byte in the file for future use upload . file . seek ( 0 ) self . backend . set ( key , files_states ) | Stores the state of each file embedded in the request . FILES MultiValueDict instance . | 130 | 20 |
241,223 | def get ( self , key ) : upload = None files_states = self . backend . get ( key ) files = MultiValueDict ( ) if files_states : for name , state in files_states . items ( ) : f = BytesIO ( ) f . write ( state [ 'content' ] ) # If the post is too large, we cannot use a # InMemoryUploadedFile instance. if state [ 'size' ] > settings . FILE_UPLOAD_MAX_MEMORY_SIZE : upload = TemporaryUploadedFile ( state [ 'name' ] , state [ 'content_type' ] , state [ 'size' ] , state [ 'charset' ] , ) upload . file = f else : f = BytesIO ( ) f . write ( state [ 'content' ] ) upload = InMemoryUploadedFile ( file = f , field_name = name , name = state [ 'name' ] , content_type = state [ 'content_type' ] , size = state [ 'size' ] , charset = state [ 'charset' ] , ) files [ name ] = upload # Go to the first byte in the file for future use upload . file . seek ( 0 ) return files | Regenerates a MultiValueDict instance containing the files related to all file states stored for the given key . | 266 | 23 |
241,224 | def get_readable_forums ( self , forums , user ) : # Any superuser should be able to read all the forums. if user . is_superuser : return forums # Fetches the forums that can be read by the given user. readable_forums = self . _get_forums_for_user ( user , [ 'can_read_forum' , ] , use_tree_hierarchy = True ) return forums . filter ( id__in = [ f . id for f in readable_forums ] ) if isinstance ( forums , ( models . Manager , models . QuerySet ) ) else list ( filter ( lambda f : f in readable_forums , forums ) ) | Returns a queryset of forums that can be read by the considered user . | 144 | 16 |
241,225 | def can_add_post ( self , topic , user ) : can_add_post = self . _perform_basic_permission_check ( topic . forum , user , 'can_reply_to_topics' , ) can_add_post &= ( not topic . is_locked or self . _perform_basic_permission_check ( topic . forum , user , 'can_reply_to_locked_topics' ) ) return can_add_post | Given a topic checks whether the user can append posts to it . | 105 | 13 |
241,226 | def can_edit_post ( self , post , user ) : checker = self . _get_checker ( user ) # A user can edit a post if... # they are a superuser # they are the original poster of the forum post # they belong to the forum moderators is_author = self . _is_post_author ( post , user ) can_edit = ( user . is_superuser or ( is_author and checker . has_perm ( 'can_edit_own_posts' , post . topic . forum ) and not post . topic . is_locked ) or checker . has_perm ( 'can_edit_posts' , post . topic . forum ) ) return can_edit | Given a forum post checks whether the user can edit the latter . | 153 | 13 |
241,227 | def can_delete_post ( self , post , user ) : checker = self . _get_checker ( user ) # A user can delete a post if... # they are a superuser # they are the original poster of the forum post # they belong to the forum moderators is_author = self . _is_post_author ( post , user ) can_delete = ( user . is_superuser or ( is_author and checker . has_perm ( 'can_delete_own_posts' , post . topic . forum ) ) or checker . has_perm ( 'can_delete_posts' , post . topic . forum ) ) return can_delete | Given a forum post checks whether the user can delete the latter . | 144 | 13 |
241,228 | def can_vote_in_poll ( self , poll , user ) : # First we have to check if the poll is curently open if poll . duration : poll_dtend = poll . created + dt . timedelta ( days = poll . duration ) if poll_dtend < now ( ) : return False # Is this user allowed to vote in polls in the current forum? can_vote = ( self . _perform_basic_permission_check ( poll . topic . forum , user , 'can_vote_in_polls' ) and not poll . topic . is_locked ) # Retrieve the user votes for the considered poll user_votes = TopicPollVote . objects . filter ( poll_option__poll = poll ) if user . is_anonymous : forum_key = get_anonymous_user_forum_key ( user ) if forum_key : user_votes = user_votes . filter ( anonymous_key = forum_key ) else : # If the forum key of the anonymous user cannot be retrieved, the user should not be # allowed to vote in the considered poll. user_votes = user_votes . none ( ) can_vote = False else : user_votes = user_votes . filter ( voter = user ) # If the user has already voted, they can vote again if the vote changes are allowed if user_votes . exists ( ) and can_vote : can_vote = poll . user_changes return can_vote | Given a poll checks whether the user can answer to it . | 312 | 12 |
241,229 | def can_subscribe_to_topic ( self , topic , user ) : # A user can subscribe to topics if they are authenticated and if they have the permission # to read the related forum. Of course a user can subscribe only if they have not already # subscribed to the considered topic. return ( user . is_authenticated and not topic . has_subscriber ( user ) and self . _perform_basic_permission_check ( topic . forum , user , 'can_read_forum' ) ) | Given a topic checks whether the user can add it to their subscription list . | 109 | 15 |
241,230 | def can_unsubscribe_from_topic ( self , topic , user ) : # A user can unsubscribe from topics if they are authenticated and if they have the # permission to read the related forum. Of course a user can unsubscribe only if they are # already a subscriber of the considered topic. return ( user . is_authenticated and topic . has_subscriber ( user ) and self . _perform_basic_permission_check ( topic . forum , user , 'can_read_forum' ) ) | Given a topic checks whether the user can remove it from their subscription list . | 111 | 15 |
241,231 | def get_target_forums_for_moved_topics ( self , user ) : return [ f for f in self . _get_forums_for_user ( user , [ 'can_move_topics' , ] ) if f . is_forum ] | Returns a list of forums in which the considered user can add topics that have been moved from another forum . | 58 | 21 |
241,232 | def can_update_topics_to_sticky_topics ( self , forum , user ) : return ( self . _perform_basic_permission_check ( forum , user , 'can_edit_posts' ) and self . _perform_basic_permission_check ( forum , user , 'can_post_stickies' ) ) | Given a forum checks whether the user can change its topic types to sticky topics . | 78 | 16 |
241,233 | def can_update_topics_to_announces ( self , forum , user ) : return ( self . _perform_basic_permission_check ( forum , user , 'can_edit_posts' ) and self . _perform_basic_permission_check ( forum , user , 'can_post_announcements' ) ) | Given a forum checks whether the user can change its topic types to announces . | 76 | 15 |
241,234 | def _get_hidden_forum_ids ( self , forums , user ) : visible_forums = self . _get_forums_for_user ( user , [ 'can_see_forum' , 'can_read_forum' , ] , use_tree_hierarchy = True , ) return forums . exclude ( id__in = [ f . id for f in visible_forums ] ) | Given a set of forums and a user returns the list of forums that are not visible by this user . | 85 | 21 |
241,235 | def _perform_basic_permission_check ( self , forum , user , permission ) : checker = self . _get_checker ( user ) # The action is granted if... # the user is the superuser # the user has the permission to do so check = ( user . is_superuser or checker . has_perm ( permission , forum ) ) return check | Given a forum and a user checks whether the latter has the passed permission . | 81 | 15 |
241,236 | def _get_checker ( self , user ) : user_perm_checkers_cache_key = user . id if not user . is_anonymous else 'anonymous' if user_perm_checkers_cache_key in self . _user_perm_checkers_cache : return self . _user_perm_checkers_cache [ user_perm_checkers_cache_key ] checker = ForumPermissionChecker ( user ) self . _user_perm_checkers_cache [ user_perm_checkers_cache_key ] = checker return checker | Return a ForumPermissionChecker instance for the given user . | 127 | 13 |
241,237 | def _get_all_forums ( self ) : if not hasattr ( self , '_all_forums' ) : self . _all_forums = list ( Forum . objects . all ( ) ) return self . _all_forums | Returns all forums . | 50 | 4 |
241,238 | def get_forum ( self ) : if not hasattr ( self , 'forum' ) : self . forum = get_object_or_404 ( Forum , pk = self . kwargs [ 'pk' ] ) return self . forum | Returns the forum to consider . | 53 | 6 |
241,239 | def send_signal ( self , request , response , forum ) : self . view_signal . send ( sender = self , forum = forum , user = request . user , request = request , response = response , ) | Sends the signal associated with the view . | 47 | 9 |
241,240 | def has_subscriber ( self , user ) : if not hasattr ( self , '_subscribers' ) : self . _subscribers = list ( self . subscribers . all ( ) ) return user in self . _subscribers | Returns True if the given user is a subscriber of this topic . | 53 | 13 |
241,241 | def clean ( self ) : super ( ) . clean ( ) if self . forum . is_category or self . forum . is_link : raise ValidationError ( _ ( 'A topic can not be associated with a category or a link forum' ) ) | Validates the topic instance . | 54 | 6 |
241,242 | def save ( self , * args , * * kwargs ) : # It is vital to track the changes of the forum associated with a topic in order to # maintain counters up-to-date. old_instance = None if self . pk : old_instance = self . __class__ . _default_manager . get ( pk = self . pk ) # Update the slug field self . slug = slugify ( force_text ( self . subject ) , allow_unicode = True ) # Do the save super ( ) . save ( * args , * * kwargs ) # If any change has been made to the parent forum, trigger the update of the counters if old_instance and old_instance . forum != self . forum : self . update_trackers ( ) # The previous parent forum counters should also be updated if old_instance . forum : old_forum = old_instance . forum old_forum . refresh_from_db ( ) old_forum . update_trackers ( ) | Saves the topic instance . | 213 | 6 |
241,243 | def update_trackers ( self ) : self . posts_count = self . posts . filter ( approved = True ) . count ( ) first_post = self . posts . all ( ) . order_by ( 'created' ) . first ( ) last_post = self . posts . filter ( approved = True ) . order_by ( '-created' ) . first ( ) self . first_post = first_post self . last_post = last_post self . last_post_on = last_post . created if last_post else None self . _simple_save ( ) # Trigger the forum-level trackers update self . forum . update_trackers ( ) | Updates the denormalized trackers associated with the topic instance . | 145 | 14 |
241,244 | def is_topic_head ( self ) : return self . topic . first_post . id == self . id if self . topic . first_post else False | Returns True if the post is the first post of the topic . | 34 | 13 |
241,245 | def is_topic_tail ( self ) : return self . topic . last_post . id == self . id if self . topic . last_post else False | Returns True if the post is the last post of the topic . | 34 | 13 |
241,246 | def position ( self ) : position = self . topic . posts . filter ( Q ( created__lt = self . created ) | Q ( id = self . id ) ) . count ( ) return position | Returns an integer corresponding to the position of the post in the topic . | 42 | 14 |
241,247 | def clean ( self ) : super ( ) . clean ( ) # At least a poster (user) or a session key must be associated with # the post. if self . poster is None and self . anonymous_key is None : raise ValidationError ( _ ( 'A user id or an anonymous key must be associated with a post.' ) , ) if self . poster and self . anonymous_key : raise ValidationError ( _ ( 'A user id or an anonymous key must be associated with a post, but not both.' ) , ) if self . anonymous_key and not self . username : raise ValidationError ( _ ( 'A username must be specified if the poster is anonymous' ) ) | Validates the post instance . | 146 | 6 |
241,248 | def save ( self , * args , * * kwargs ) : new_post = self . pk is None super ( ) . save ( * args , * * kwargs ) # Ensures that the subject of the thread corresponds to the one associated # with the first post. Do the same with the 'approved' flag. if ( new_post and self . topic . first_post is None ) or self . is_topic_head : if self . subject != self . topic . subject or self . approved != self . topic . approved : self . topic . subject = self . subject self . topic . approved = self . approved # Trigger the topic-level trackers update self . topic . update_trackers ( ) | Saves the post instance . | 153 | 6 |
241,249 | def delete ( self , using = None ) : if self . is_alone : # The default way of operating is to trigger the deletion of the associated topic # only if the considered post is the only post embedded in the topic self . topic . delete ( ) else : super ( AbstractPost , self ) . delete ( using ) self . topic . update_trackers ( ) | Deletes the post instance . | 77 | 6 |
241,250 | def from_forums ( cls , forums ) : root_level = None current_path = [ ] nodes = [ ] # Ensures forums last posts and related poster relations are "followed" for better # performance (only if we're considering a queryset). forums = ( forums . select_related ( 'last_post' , 'last_post__poster' ) if isinstance ( forums , QuerySet ) else forums ) for forum in forums : level = forum . level # Set the root level to the top node level at the first iteration. if root_level is None : root_level = level # Initializes a visibility forum node associated with current forum instance. vcontent_node = ForumVisibilityContentNode ( forum ) # Computes a relative level associated to the node. relative_level = level - root_level vcontent_node . relative_level = relative_level # All children nodes will be stored in an array attached to the current node. vcontent_node . children = [ ] # Removes the forum that are not in the current branch. while len ( current_path ) > relative_level : current_path . pop ( - 1 ) if level != root_level : # Update the parent of the current forum. parent_node = current_path [ - 1 ] vcontent_node . parent = parent_node parent_node . children . append ( vcontent_node ) # Sets visible flag if applicable. The visible flag is used to determine whether a forum # can be seen in a forum list or not. A forum can be seen if one of the following # statements is true: # # * the forum is a direct child of the starting forum for the considered level # * the forum have a parent which is a category and this category is a direct child of # the starting forum # * the forum have its 'display_sub_forum_list' option set to True and have a parent # which is another forum. The latter is a direct child of the starting forum # * the forum have its 'display_sub_forum_list' option set to True and have a parent # which is another forum. The later have a parent which is a category and this # category is a direct child of the starting forum # # If forums at the root level don't have parents, the visible forums are those that can # be seen from the root of the forums tree. vcontent_node . visible = ( ( relative_level == 0 ) or ( forum . display_sub_forum_list and relative_level == 1 ) or ( forum . is_category and relative_level == 1 ) or ( relative_level == 2 and vcontent_node . parent . parent . obj . is_category and vcontent_node . parent . obj . is_forum ) ) # Add the current forum to the end of the current branch and inserts the node inside the # final node dictionary. current_path . append ( vcontent_node ) nodes . append ( vcontent_node ) tree = cls ( nodes = nodes ) for node in tree . nodes : node . tree = tree return tree | Initializes a ForumVisibilityContentTree instance from a list of forums . | 649 | 15 |
241,251 | def last_post ( self ) : posts = [ n . last_post for n in self . children if n . last_post is not None ] children_last_post = max ( posts , key = lambda p : p . created ) if posts else None if children_last_post and self . obj . last_post_id : return max ( self . obj . last_post , children_last_post , key = lambda p : p . created ) return children_last_post or self . obj . last_post | Returns the latest post associated with the node or one of its descendants . | 112 | 14 |
241,252 | def last_post_on ( self ) : dates = [ n . last_post_on for n in self . children if n . last_post_on is not None ] children_last_post_on = max ( dates ) if dates else None if children_last_post_on and self . obj . last_post_on : return max ( self . obj . last_post_on , children_last_post_on ) return children_last_post_on or self . obj . last_post_on | Returns the latest post date associated with the node or one of its descendants . | 112 | 15 |
241,253 | def next_sibling ( self ) : if self . parent : nodes = self . parent . children index = nodes . index ( self ) sibling = nodes [ index + 1 ] if index < len ( nodes ) - 1 else None else : nodes = self . tree . nodes index = nodes . index ( self ) sibling = ( next ( ( n for n in nodes [ index + 1 : ] if n . level == self . level ) , None ) if index < len ( nodes ) - 1 else None ) return sibling | Returns the next sibling of the current node . | 108 | 9 |
241,254 | def posts_count ( self ) : return self . obj . direct_posts_count + sum ( n . posts_count for n in self . children ) | Returns the number of posts associated with the current node and its descendants . | 33 | 14 |
241,255 | def previous_sibling ( self ) : if self . parent : nodes = self . parent . children index = nodes . index ( self ) sibling = nodes [ index - 1 ] if index > 0 else None else : nodes = self . tree . nodes index = nodes . index ( self ) sibling = ( next ( ( n for n in reversed ( nodes [ : index ] ) if n . level == self . level ) , None ) if index > 0 else None ) return sibling | Returns the previous sibling of the current node . | 99 | 9 |
241,256 | def topics_count ( self ) : return self . obj . direct_topics_count + sum ( n . topics_count for n in self . children ) | Returns the number of topics associated with the current node and its descendants . | 34 | 14 |
241,257 | def has_perm ( self , perm , forum ) : if not self . user . is_anonymous and not self . user . is_active : # An inactive user cannot have permissions return False elif self . user and self . user . is_superuser : # The superuser have all permissions return True return perm in self . get_perms ( forum ) | Checks if the considered user has given permission for the passed forum . | 77 | 14 |
241,258 | def save ( self , commit = True , * * kwargs ) : if self . post : for form in self . forms : form . instance . post = self . post super ( ) . save ( commit ) | Saves the considered instances . | 45 | 6 |
241,259 | def get_required_permissions ( self , request ) : perms = [ ] if not self . permission_required : return perms if isinstance ( self . permission_required , string_types ) : perms = [ self . permission_required , ] elif isinstance ( self . permission_required , Iterable ) : perms = [ perm for perm in self . permission_required ] else : raise ImproperlyConfigured ( '\'PermissionRequiredMixin\' requires \'permission_required\' ' 'attribute to be set to \'<app_label>.<permission codename>\' but is set to {} ' 'instead' . format ( self . permission_required ) ) return perms | Returns the required permissions to access the considered object . | 150 | 10 |
241,260 | def check_permissions ( self , request ) : obj = ( hasattr ( self , 'get_controlled_object' ) and self . get_controlled_object ( ) or hasattr ( self , 'get_object' ) and self . get_object ( ) or getattr ( self , 'object' , None ) ) user = request . user # Get the permissions to check perms = self . get_required_permissions ( self ) # Check permissions has_permissions = self . perform_permissions_check ( user , obj , perms ) if not has_permissions and not user . is_authenticated : return HttpResponseRedirect ( '{}?{}={}' . format ( resolve_url ( self . login_url ) , self . redirect_field_name , urlquote ( request . get_full_path ( ) ) ) ) elif not has_permissions : raise PermissionDenied | Retrieves the controlled object and perform the permissions check . | 200 | 12 |
241,261 | def dispatch ( self , request , * args , * * kwargs ) : self . request = request self . args = args self . kwargs = kwargs response = self . check_permissions ( request ) if response : return response return super ( ) . dispatch ( request , * args , * * kwargs ) | Dispatches an incoming request . | 70 | 7 |
241,262 | def update_user_trackers ( sender , topic , user , request , response , * * kwargs ) : TrackingHandler = get_class ( 'forum_tracking.handler' , 'TrackingHandler' ) # noqa track_handler = TrackingHandler ( ) track_handler . mark_topic_read ( topic , user ) | Receiver to mark a topic being viewed as read . | 71 | 11 |
241,263 | def update_forum_redirects_counter ( sender , forum , user , request , response , * * kwargs ) : if forum . is_link and forum . link_redirects : forum . link_redirects_count = F ( 'link_redirects_count' ) + 1 forum . save ( ) | Handles the update of the link redirects counter associated with link forums . | 72 | 15 |
241,264 | def get_avatar_upload_to ( self , filename ) : dummy , ext = os . path . splitext ( filename ) return os . path . join ( machina_settings . PROFILE_AVATAR_UPLOAD_TO , '{id}{ext}' . format ( id = str ( uuid . uuid4 ( ) ) . replace ( '-' , '' ) , ext = ext ) , ) | Returns the path to upload the associated avatar to . | 92 | 10 |
241,265 | def get_queryset ( self ) : qs = super ( ) . get_queryset ( ) qs = qs . filter ( approved = True ) return qs | Returns all the approved topics or posts . | 39 | 8 |
241,266 | def votes ( self ) : votes = [ ] for option in self . options . all ( ) : votes += option . votes . all ( ) return votes | Returns all the votes related to this topic poll . | 32 | 10 |
241,267 | def clean ( self ) : super ( ) . clean ( ) # At least a poster (user) or a session key must be associated with # the vote instance. if self . voter is None and self . anonymous_key is None : raise ValidationError ( _ ( 'A user id or an anonymous key must be used.' ) ) if self . voter and self . anonymous_key : raise ValidationError ( _ ( 'A user id or an anonymous key must be used, but not both.' ) ) | Validates the considered instance . | 106 | 6 |
241,268 | def get_top_level_forum_url ( self ) : return ( reverse ( 'forum:index' ) if self . top_level_forum is None else reverse ( 'forum:forum' , kwargs = { 'slug' : self . top_level_forum . slug , 'pk' : self . kwargs [ 'pk' ] } , ) ) | Returns the parent forum from which forums are marked as read . | 83 | 12 |
241,269 | def mark_as_read ( self , request , pk ) : if self . top_level_forum is not None : forums = request . forum_permission_handler . get_readable_forums ( self . top_level_forum . get_descendants ( include_self = True ) , request . user , ) else : forums = request . forum_permission_handler . get_readable_forums ( Forum . objects . all ( ) , request . user , ) # Marks forums as read track_handler . mark_forums_read ( forums , request . user ) if len ( forums ) : messages . success ( request , self . success_message ) return HttpResponseRedirect ( self . get_top_level_forum_url ( ) ) | Marks the considered forums as read . | 161 | 8 |
241,270 | def get_forum_url ( self ) : return reverse ( 'forum:forum' , kwargs = { 'slug' : self . forum . slug , 'pk' : self . forum . pk } ) | Returns the url of the forum whose topics will be marked read . | 48 | 13 |
241,271 | def mark_topics_read ( self , request , pk ) : track_handler . mark_forums_read ( [ self . forum , ] , request . user ) messages . success ( request , self . success_message ) return HttpResponseRedirect ( self . get_forum_url ( ) ) | Marks forum topics as read . | 66 | 7 |
241,272 | def get_model ( app_label , model_name ) : try : return apps . get_model ( app_label , model_name ) except AppRegistryNotReady : if apps . apps_ready and not apps . models_ready : # If the models module of the considered app has not been loaded yet, # we try to import it manually in order to retrieve the model class. # This trick is usefull in order to get the model class during the # ``apps.populate()`` call and the execution of related methods of AppConfig # instances (eg. ``ready``). # Firts, the config of the consideration must be retrieved app_config = apps . get_app_config ( app_label ) # Then the models module is manually imported import_module ( '%s.%s' % ( app_config . name , MODELS_MODULE_NAME ) ) # Finally, tries to return the registered model class return apps . get_registered_model ( app_label , model_name ) else : raise | Given an app label and a model name returns the corresponding model class . | 218 | 14 |
241,273 | def is_model_registered ( app_label , model_name ) : try : apps . get_registered_model ( app_label , model_name ) except LookupError : return False else : return True | Checks whether the given model is registered or not . | 45 | 11 |
241,274 | def clean ( self ) : super ( ) . clean ( ) if ( ( self . user is None and not self . anonymous_user ) or ( self . user and self . anonymous_user ) ) : raise ValidationError ( _ ( 'A permission should target either a user or an anonymous user' ) , ) | Validates the current instance . | 66 | 6 |
241,275 | def render_to_response ( self , context , * * response_kwargs ) : filename = os . path . basename ( self . object . file . name ) # Try to guess the content type of the given file content_type , _ = mimetypes . guess_type ( self . object . file . name ) if not content_type : content_type = 'text/plain' response = HttpResponse ( self . object . file , content_type = content_type ) response [ 'Content-Disposition' ] = 'attachment; filename={}' . format ( filename ) return response | Generates the appropriate response . | 129 | 6 |
241,276 | def get_form_kwargs ( self ) : kwargs = super ( ModelFormMixin , self ) . get_form_kwargs ( ) kwargs [ 'poll' ] = self . object return kwargs | Returns the keyword arguments to provide tp the associated form . | 49 | 12 |
241,277 | def form_invalid ( self , form ) : messages . error ( self . request , form . errors [ NON_FIELD_ERRORS ] ) return redirect ( reverse ( 'forum_conversation:topic' , kwargs = { 'forum_slug' : self . object . topic . forum . slug , 'forum_pk' : self . object . topic . forum . pk , 'slug' : self . object . topic . slug , 'pk' : self . object . topic . pk } , ) , ) | Handles an invalid form . | 117 | 6 |
241,278 | def has_been_completed_by ( poll , user ) : user_votes = TopicPollVote . objects . filter ( poll_option__poll = poll ) if user . is_anonymous : forum_key = get_anonymous_user_forum_key ( user ) user_votes = user_votes . filter ( anonymous_key = forum_key ) if forum_key else user_votes . none ( ) else : user_votes = user_votes . filter ( voter = user ) return user_votes . exists ( ) | This will return a boolean indicating if the passed user has already voted in the given poll . | 114 | 18 |
241,279 | def get_unread_forums_from_list ( self , forums , user ) : unread_forums = [ ] visibility_contents = ForumVisibilityContentTree . from_forums ( forums ) forum_ids_to_visibility_nodes = visibility_contents . as_dict tracks = super ( ) . get_queryset ( ) . select_related ( 'forum' ) . filter ( user = user , forum__in = forums ) tracked_forums = [ ] for track in tracks : forum_last_post_on = forum_ids_to_visibility_nodes [ track . forum_id ] . last_post_on if ( forum_last_post_on and track . mark_time < forum_last_post_on ) and track . forum not in unread_forums : unread_forums . extend ( track . forum . get_ancestors ( include_self = True ) ) tracked_forums . append ( track . forum ) for forum in forums : if forum not in tracked_forums and forum not in unread_forums and forum . direct_topics_count > 0 : unread_forums . extend ( forum . get_ancestors ( include_self = True ) ) return list ( set ( unread_forums ) ) | Filter a list of forums and return only those which are unread . | 275 | 14 |
241,280 | def increase_posts_count ( sender , instance , * * kwargs ) : if instance . poster is None : # An anonymous post is considered. No profile can be updated in # that case. return profile , dummy = ForumProfile . objects . get_or_create ( user = instance . poster ) increase_posts_count = False if instance . pk : try : old_instance = instance . __class__ . _default_manager . get ( pk = instance . pk ) except ObjectDoesNotExist : # pragma: no cover # This should never happen (except with django loaddata command) increase_posts_count = True old_instance = None if old_instance and old_instance . approved is False and instance . approved is True : increase_posts_count = True elif instance . approved : increase_posts_count = True if increase_posts_count : profile . posts_count = F ( 'posts_count' ) + 1 profile . save ( ) | Increases the member s post count after a post save . | 210 | 11 |
241,281 | def decrease_posts_count_after_post_unaproval ( sender , instance , * * kwargs ) : if not instance . pk : # Do not consider posts being created. return profile , dummy = ForumProfile . objects . get_or_create ( user = instance . poster ) try : old_instance = instance . __class__ . _default_manager . get ( pk = instance . pk ) except ObjectDoesNotExist : # pragma: no cover # This should never happen (except with django loaddata command) return if old_instance and old_instance . approved is True and instance . approved is False : profile . posts_count = F ( 'posts_count' ) - 1 profile . save ( ) | Decreases the member s post count after a post unaproval . | 159 | 15 |
241,282 | def decrease_posts_count_after_post_deletion ( sender , instance , * * kwargs ) : if not instance . approved : # If a post has not been approved, it has not been counted. # So do not decrement count return try : assert instance . poster_id is not None poster = User . objects . get ( pk = instance . poster_id ) except AssertionError : # An anonymous post is considered. No profile can be updated in # that case. return except ObjectDoesNotExist : # pragma: no cover # This can happen if a User instance is deleted. In that case the # User instance is not available and the receiver should return. return profile , dummy = ForumProfile . objects . get_or_create ( user = poster ) if profile . posts_count : profile . posts_count = F ( 'posts_count' ) - 1 profile . save ( ) | Decreases the member s post count after a post deletion . | 195 | 12 |
241,283 | def lock ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) success_url = self . get_success_url ( ) self . object . status = Topic . TOPIC_LOCKED self . object . save ( ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( success_url ) | Locks the considered topic and retirects the user to the success URL . | 86 | 16 |
241,284 | def unlock ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) success_url = self . get_success_url ( ) self . object . status = Topic . TOPIC_UNLOCKED self . object . save ( ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( success_url ) | Unlocks the considered topic and retirects the user to the success URL . | 87 | 16 |
241,285 | def update_type ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) success_url = self . get_success_url ( ) self . object . type = self . target_type self . object . save ( ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( success_url ) | Updates the type of the considered topic and retirects the user to the success URL . | 86 | 19 |
241,286 | def approve ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) success_url = self . get_success_url ( ) self . object . approved = True self . object . save ( ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( success_url ) | Approves the considered post and retirects the user to the success URL . | 80 | 17 |
241,287 | def disapprove ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) success_url = self . get_success_url ( ) self . object . delete ( ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( success_url ) | Disapproves the considered post and retirects the user to the success URL . | 73 | 17 |
241,288 | def poster ( self ) : user_model = get_user_model ( ) return get_object_or_404 ( user_model , pk = self . kwargs [ self . user_pk_url_kwarg ] ) | Returns the considered user . | 52 | 5 |
241,289 | def subscribe ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) self . object . subscribers . add ( request . user ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( self . get_success_url ( ) ) | Performs the subscribe action . | 71 | 6 |
241,290 | def unsubscribe ( self , request , * args , * * kwargs ) : self . object = self . get_object ( ) self . object . subscribers . remove ( request . user ) messages . success ( self . request , self . success_message ) return HttpResponseRedirect ( self . get_success_url ( ) ) | Performs the unsubscribe action . | 72 | 7 |
241,291 | def update_topic_counter ( sender , topic , user , request , response , * * kwargs ) : topic . __class__ . _default_manager . filter ( id = topic . id ) . update ( views_count = F ( 'views_count' ) + 1 ) | Handles the update of the views counter associated with topics . | 61 | 12 |
241,292 | def get_topic ( self ) : if not hasattr ( self , 'topic' ) : self . topic = get_object_or_404 ( Topic . objects . select_related ( 'forum' ) . all ( ) , pk = self . kwargs [ 'pk' ] , ) return self . topic | Returns the topic to consider . | 69 | 6 |
241,293 | def init_attachment_cache ( self ) : if self . request . method == 'GET' : # Invalidates previous attachments attachments_cache . delete ( self . get_attachments_cache_key ( self . request ) ) return # Try to restore previous uploaded attachments if applicable attachments_cache_key = self . get_attachments_cache_key ( self . request ) restored_attachments_dict = attachments_cache . get ( attachments_cache_key ) if restored_attachments_dict : restored_attachments_dict . update ( self . request . FILES ) self . request . _files = restored_attachments_dict # Updates the attachment cache if files are available if self . request . FILES : attachments_cache . set ( attachments_cache_key , self . request . FILES ) | Initializes the attachment cache for the current view . | 172 | 10 |
241,294 | def get_post_form_kwargs ( self ) : kwargs = { 'user' : self . request . user , 'forum' : self . get_forum ( ) , 'topic' : self . get_topic ( ) , } post = self . get_post ( ) if post : kwargs . update ( { 'instance' : post } ) if self . request . method in ( 'POST' , 'PUT' ) : kwargs . update ( { 'data' : self . request . POST , 'files' : self . request . FILES , } ) return kwargs | Returns the keyword arguments for instantiating the post form . | 130 | 11 |
241,295 | def get_attachment_formset ( self , formset_class ) : if ( self . request . forum_permission_handler . can_attach_files ( self . get_forum ( ) , self . request . user , ) ) : return formset_class ( * * self . get_attachment_formset_kwargs ( ) ) | Returns an instance of the attachment formset to be used in the view . | 76 | 15 |
241,296 | def get_attachment_formset_kwargs ( self ) : kwargs = { 'prefix' : 'attachment' , } if self . request . method in ( 'POST' , 'PUT' ) : kwargs . update ( { 'data' : self . request . POST , 'files' : self . request . FILES , } ) else : post = self . get_post ( ) attachment_queryset = Attachment . objects . filter ( post = post ) kwargs . update ( { 'queryset' : attachment_queryset , } ) return kwargs | Returns the keyword arguments for instantiating the attachment formset . | 130 | 12 |
241,297 | def get_forum ( self ) : pk = self . kwargs . get ( self . forum_pk_url_kwarg , None ) if not pk : # pragma: no cover # This should never happen return if not hasattr ( self , '_forum' ) : self . _forum = get_object_or_404 ( Forum , pk = pk ) return self . _forum | Returns the considered forum . | 89 | 5 |
241,298 | def get_topic ( self ) : pk = self . kwargs . get ( self . topic_pk_url_kwarg , None ) if not pk : return if not hasattr ( self , '_topic' ) : self . _topic = get_object_or_404 ( Topic , pk = pk ) return self . _topic | Returns the considered topic if applicable . | 78 | 7 |
241,299 | def get_post ( self ) : pk = self . kwargs . get ( self . post_pk_url_kwarg , None ) if not pk : return if not hasattr ( self , '_forum_post' ) : self . _forum_post = get_object_or_404 ( Post , pk = pk ) return self . _forum_post | Returns the considered post if applicable . | 84 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.