idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
242,200
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 .
242,201
def resize_image ( self , data , size ) : from machina . core . compat import PILImage as Image image = Image . open ( BytesIO ( data ) ) 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 .
242,202
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 .
242,203
def set ( self , key , files ) : files_states = { } for name , upload in files . items ( ) : state = { 'name' : upload . name , 'size' : upload . size , 'content_type' : upload . content_type , 'charset' : upload . charset , 'content' : upload . file . read ( ) , } files_states [ name ] = state upload . file . seek ( 0...
Stores the state of each file embedded in the request . FILES MultiValueDict instance .
242,204
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 state [ 'size' ] > settings . FILE_UPLOAD_MAX_MEMORY_SIZE : upload = TemporaryUploadedFile (...
Regenerates a MultiValueDict instance containing the files related to all file states stored for the given key .
242,205
def get_readable_forums ( self , forums , user ) : if user . is_superuser : return forums 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 , mode...
Returns a queryset of forums that can be read by the considered user .
242,206
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 .
242,207
def can_edit_post ( self , post , user ) : checker = self . _get_checker ( user ) 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...
Given a forum post checks whether the user can edit the latter .
242,208
def can_delete_post ( self , post , user ) : checker = self . _get_checker ( user ) 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 . ...
Given a forum post checks whether the user can delete the latter .
242,209
def can_vote_in_poll ( self , poll , user ) : if poll . duration : poll_dtend = poll . created + dt . timedelta ( days = poll . duration ) if poll_dtend < now ( ) : return False can_vote = ( self . _perform_basic_permission_check ( poll . topic . forum , user , 'can_vote_in_polls' ) and not poll . topic . is_locked ) u...
Given a poll checks whether the user can answer to it .
242,210
def can_subscribe_to_topic ( self , topic , user ) : 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 .
242,211
def can_unsubscribe_from_topic ( self , topic , user ) : 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 .
242,212
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 .
242,213
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 .
242,214
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 .
242,215
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 .
242,216
def _perform_basic_permission_check ( self , forum , user , permission ) : checker = self . _get_checker ( user ) 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 .
242,217
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 .
242,218
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 .
242,219
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 .
242,220
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 .
242,221
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 .
242,222
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 .
242,223
def save ( self , * args , ** kwargs ) : old_instance = None if self . pk : old_instance = self . __class__ . _default_manager . get ( pk = self . pk ) self . slug = slugify ( force_text ( self . subject ) , allow_unicode = True ) super ( ) . save ( * args , ** kwargs ) if old_instance and old_instance . forum != self ...
Saves the topic instance .
242,224
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 .
242,225
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 .
242,226
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 .
242,227
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 .
242,228
def clean ( self ) : super ( ) . clean ( ) 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 associat...
Validates the post instance .
242,229
def save ( self , * args , ** kwargs ) : new_post = self . pk is None super ( ) . save ( * args , ** kwargs ) 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 . subjec...
Saves the post instance .
242,230
def delete ( self , using = None ) : if self . is_alone : self . topic . delete ( ) else : super ( AbstractPost , self ) . delete ( using ) self . topic . update_trackers ( )
Deletes the post instance .
242,231
def from_forums ( cls , forums ) : root_level = None current_path = [ ] nodes = [ ] forums = ( forums . select_related ( 'last_post' , 'last_post__poster' ) if isinstance ( forums , QuerySet ) else forums ) for forum in forums : level = forum . level if root_level is None : root_level = level vcontent_node = ForumVisib...
Initializes a ForumVisibilityContentTree instance from a list of forums .
242,232
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 .
242,233
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 .
242,234
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 .
242,235
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 .
242,236
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 .
242,237
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 .
242,238
def has_perm ( self , perm , forum ) : if not self . user . is_anonymous and not self . user . is_active : return False elif self . user and self . user . is_superuser : return True return perm in self . get_perms ( forum )
Checks if the considered user has given permission for the passed forum .
242,239
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 .
242,240
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 .
242,241
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 perms = self . get_required_permissions ( self ) has_permissions =...
Retrieves the controlled object and perform the permissions check .
242,242
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 .
242,243
def update_user_trackers ( sender , topic , user , request , response , ** kwargs ) : TrackingHandler = get_class ( 'forum_tracking.handler' , 'TrackingHandler' ) track_handler = TrackingHandler ( ) track_handler . mark_topic_read ( topic , user )
Receiver to mark a topic being viewed as read .
242,244
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 .
242,245
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 .
242,246
def get_queryset ( self ) : qs = super ( ) . get_queryset ( ) qs = qs . filter ( approved = True ) return qs
Returns all the approved topics or posts .
242,247
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 .
242,248
def clean ( self ) : super ( ) . clean ( ) 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 .
242,249
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 .
242,250
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 .
242,251
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 .
242,252
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 .
242,253
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 : app_config = apps . get_app_config ( app_label ) import_module ( '%s.%s' % ( app_config . name , MODELS_MODULE_NAME ) ) return apps . get_re...
Given an app label and a model name returns the corresponding model class .
242,254
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 .
242,255
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 .
242,256
def render_to_response ( self , context , ** response_kwargs ) : filename = os . path . basename ( self . object . file . name ) content_type , _ = mimetypes . guess_type ( self . object . file . name ) if not content_type : content_type = 'text/plain' response = HttpResponse ( self . object . file , content_type = con...
Generates the appropriate response .
242,257
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 .
242,258
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 .
242,259
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 .
242,260
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 .
242,261
def increase_posts_count ( sender , instance , ** kwargs ) : if instance . poster is None : 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...
Increases the member s post count after a post save .
242,262
def decrease_posts_count_after_post_unaproval ( sender , instance , ** kwargs ) : if not instance . pk : return profile , dummy = ForumProfile . objects . get_or_create ( user = instance . poster ) try : old_instance = instance . __class__ . _default_manager . get ( pk = instance . pk ) except ObjectDoesNotExist : retu...
Decreases the member s post count after a post unaproval .
242,263
def decrease_posts_count_after_post_deletion ( sender , instance , ** kwargs ) : if not instance . approved : return try : assert instance . poster_id is not None poster = User . objects . get ( pk = instance . poster_id ) except AssertionError : return except ObjectDoesNotExist : return profile , dummy = ForumProfile ...
Decreases the member s post count after a post deletion .
242,264
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 .
242,265
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 .
242,266
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 .
242,267
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 .
242,268
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 .
242,269
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 .
242,270
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 .
242,271
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 .
242,272
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 .
242,273
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 .
242,274
def init_attachment_cache ( self ) : if self . request . method == 'GET' : attachments_cache . delete ( self . get_attachments_cache_key ( self . request ) ) return attachments_cache_key = self . get_attachments_cache_key ( self . request ) restored_attachments_dict = attachments_cache . get ( attachments_cache_key ) i...
Initializes the attachment cache for the current view .
242,275
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 .
242,276
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 .
242,277
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 .
242,278
def get_forum ( self ) : pk = self . kwargs . get ( self . forum_pk_url_kwarg , None ) if not pk : return if not hasattr ( self , '_forum' ) : self . _forum = get_object_or_404 ( Forum , pk = pk ) return self . _forum
Returns the considered forum .
242,279
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 .
242,280
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 .
242,281
def get_poll_option_formset ( self , formset_class ) : if self . request . forum_permission_handler . can_create_polls ( self . get_forum ( ) , self . request . user , ) : return formset_class ( ** self . get_poll_option_formset_kwargs ( ) )
Returns an instance of the poll option formset to be used in the view .
242,282
def get_poll_option_formset_kwargs ( self ) : kwargs = { 'prefix' : 'poll' , } if self . request . method in ( 'POST' , 'PUT' ) : kwargs . update ( { 'data' : self . request . POST , 'files' : self . request . FILES , } ) else : topic = self . get_topic ( ) poll_option_queryset = TopicPollOption . objects . filter ( po...
Returns the keyword arguments for instantiating the poll option formset .
242,283
def _remove_exts ( self , string ) : if string . lower ( ) . endswith ( ( '.png' , '.gif' , '.jpg' , '.bmp' , '.jpeg' , '.ppm' , '.datauri' ) ) : format = string [ string . rfind ( '.' ) + 1 : len ( string ) ] if format . lower ( ) == 'jpg' : format = 'jpeg' self . format = format string = string [ 0 : string . rfind (...
Sets the string to create the Robohash
242,284
def _get_list_of_files ( self , path ) : chosen_files = [ ] directories = [ ] for root , dirs , files in natsort . natsorted ( os . walk ( path , topdown = False ) ) : for name in dirs : if name [ : 1 ] is not '.' : directories . append ( os . path . join ( root , name ) ) directories = natsort . natsorted ( directorie...
Go through each subdirectory of path and choose one file from each to use in our hash . Continue to increase self . iter so we use a different slot of randomness each time .
242,285
def assemble ( self , roboset = None , color = None , format = None , bgset = None , sizex = 300 , sizey = 300 ) : if roboset == 'any' : roboset = self . sets [ self . hasharray [ 1 ] % len ( self . sets ) ] elif roboset in self . sets : roboset = roboset else : roboset = self . sets [ 0 ] if roboset == 'set1' : if col...
Build our Robot! Returns the robot image itself .
242,286
def collect_members ( module_to_name ) : members = { } for module , module_name in module_to_name . items ( ) : all_names = getattr ( module , "__all__" , None ) for name , member in inspect . getmembers ( module ) : if ( ( inspect . isfunction ( member ) or inspect . isclass ( member ) ) and not _always_drop_symbol_re...
Collect all symbols from a list of modules .
242,287
def _get_anchor ( module_to_name , fullname ) : if not _anchor_re . match ( fullname ) : raise ValueError ( "'%s' is not a valid anchor" % fullname ) anchor = fullname for module_name in module_to_name . values ( ) : if fullname . startswith ( module_name + "." ) : rest = fullname [ len ( module_name ) + 1 : ] if len (...
Turn a full member name into an anchor .
242,288
def write_libraries ( dir , libraries ) : files = [ open ( os . path . join ( dir , k ) , "w" ) for k , _ in libraries ] for f , ( _ , v ) in zip ( files , libraries ) : v . write_markdown_to_file ( f ) for f , ( _ , v ) in zip ( files , libraries ) : v . write_other_members ( f ) f . close ( )
Write a list of libraries to disk .
242,289
def write_markdown_to_file ( self , f ) : print ( "---" , file = f ) print ( "---" , file = f ) print ( "<!-- This file is machine generated: DO NOT EDIT! , file = f ) print ( "" , file = f ) print ( "# TensorFlow Python reference documentation" , file = f ) print ( "" , file = f ) fullname_f = lambda name : self . _m...
Writes this index to file f .
242,290
def _should_include_member ( self , name , member ) : if _always_drop_symbol_re . match ( name ) : return False if name in self . _exclude_symbols : return False return True
Returns True if this member should be included in the document .
242,291
def get_imported_modules ( self , module ) : for name , member in inspect . getmembers ( module ) : if inspect . ismodule ( member ) : yield name , member
Returns the list of modules imported from module .
242,292
def get_class_members ( self , cls_name , cls ) : for name , member in inspect . getmembers ( cls ) : is_method = inspect . ismethod ( member ) or inspect . isfunction ( member ) if not ( is_method or isinstance ( member , property ) ) : continue if ( ( is_method and member . __name__ == "__init__" ) or self . _should_...
Returns the list of class members to document in cls .
242,293
def _generate_signature_for_function ( self , func ) : args_list = [ ] argspec = inspect . getargspec ( func ) first_arg_with_default = ( len ( argspec . args or [ ] ) - len ( argspec . defaults or [ ] ) ) for arg in argspec . args [ : first_arg_with_default ] : if arg == "self" : continue args_list . append ( arg ) if...
Given a function returns a string representing its args .
242,294
def _remove_docstring_indent ( self , docstring ) : docstring = docstring or "" lines = docstring . strip ( ) . split ( "\n" ) min_indent = len ( docstring ) for l in lines [ 1 : ] : l = l . rstrip ( ) if l : i = 0 while i < len ( l ) and l [ i ] == " " : i += 1 if i < min_indent : min_indent = i for i in range ( 1 , l...
Remove indenting .
242,295
def _print_formatted_docstring ( self , docstring , f ) : lines = self . _remove_docstring_indent ( docstring ) i = 0 def _at_start_of_section ( ) : l = lines [ i ] match = _section_re . match ( l ) if match and i + 1 < len ( lines ) and lines [ i + 1 ] . startswith ( " " ) : return match . group ( 1 ) else : return No...
Formats the given docstring as Markdown and prints it to f .
242,296
def _print_function ( self , f , prefix , fullname , func ) : heading = prefix + " `" + fullname if not isinstance ( func , property ) : heading += self . _generate_signature_for_function ( func ) heading += "` {#%s}" % _get_anchor ( self . _module_to_name , fullname ) print ( heading , file = f ) print ( "" , file = f...
Prints the given function to f .
242,297
def _write_member_markdown_to_file ( self , f , prefix , name , member ) : if ( inspect . isfunction ( member ) or inspect . ismethod ( member ) or isinstance ( member , property ) ) : print ( "- - -" , file = f ) print ( "" , file = f ) self . _print_function ( f , prefix , name , member ) print ( "" , file = f ) elif...
Print member to f .
242,298
def _write_class_markdown_to_file ( self , f , name , cls ) : methods = dict ( self . get_class_members ( name , cls ) ) num_methods = len ( methods ) try : self . _write_docstring_markdown_to_file ( f , "####" , inspect . getdoc ( cls ) , methods , { } ) except ValueError as e : raise ValueError ( str ( e ) + " in cla...
Write the class doc to f .
242,299
def write_markdown_to_file ( self , f ) : print ( "---" , file = f ) print ( "---" , file = f ) print ( "<!-- This file is machine generated: DO NOT EDIT! , file = f ) print ( "" , file = f ) print ( "#" , self . _title , file = f ) if self . _prefix : print ( self . _prefix , file = f ) print ( "[TOC]" , file = f ) p...
Prints this library to file f .