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... | 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 , f... | 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 ( _ ( 'Foru... | 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' ] = foru... | 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 ] f... | 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 la... | 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 ano... | 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 ... | 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 ) re... | 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 ... | 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 = for... | 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 . ma... | 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 paren... | 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 = se... | 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 (... | 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 ... | 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' ... | 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 for... | 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_autho... | 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... | 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 . _perfo... | 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 .... | 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 topi... | 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_pe... | 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 ( for... | 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 =... | 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_k... | 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... | 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_tracker... | 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 , Q... | 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 : ... | 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_o... | 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... | 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 . ... | 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_r... | 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_permiss... | 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 Va... | 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 . ... | 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. #... | 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 = HttpR... | 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 , ... | 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 = use... | 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 = f... | 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... | 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... | 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 A... | 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 ( ... | 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 . reques... | 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 ... | 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.