idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
242,100 | def map_set_properties ( m : tcod . map . Map , x : int , y : int , isTrans : bool , isWalk : bool ) -> None : lib . TCOD_map_set_properties ( m . map_c , x , y , isTrans , isWalk ) | Set the properties of a single cell . |
242,101 | def map_clear ( m : tcod . map . Map , transparent : bool = False , walkable : bool = False ) -> None : m . transparent [ : ] = transparent m . walkable [ : ] = walkable | Change all map cells to a specific value . |
242,102 | def map_compute_fov ( m : tcod . map . Map , x : int , y : int , radius : int = 0 , light_walls : bool = True , algo : int = FOV_RESTRICTIVE , ) -> None : m . compute_fov ( x , y , radius , light_walls , algo ) | Compute the field - of - view for a map instance . |
242,103 | def map_is_in_fov ( m : tcod . map . Map , x : int , y : int ) -> bool : return bool ( lib . TCOD_map_is_in_fov ( m . map_c , x , y ) ) | Return True if the cell at x y is lit by the last field - of - view algorithm . |
242,104 | def noise_new ( dim : int , h : float = NOISE_DEFAULT_HURST , l : float = NOISE_DEFAULT_LACUNARITY , random : Optional [ tcod . random . Random ] = None , ) -> tcod . noise . Noise : return tcod . noise . Noise ( dim , hurst = h , lacunarity = l , seed = random ) | Return a new Noise instance . |
242,105 | def noise_set_type ( n : tcod . noise . Noise , typ : int ) -> None : n . algorithm = typ | Set a Noise objects default noise algorithm . |
242,106 | def noise_get ( n : tcod . noise . Noise , f : Sequence [ float ] , typ : int = NOISE_DEFAULT ) -> float : return float ( lib . TCOD_noise_get_ex ( n . noise_c , ffi . new ( "float[4]" , f ) , typ ) ) | Return the noise value sampled from the f coordinate . |
242,107 | def noise_get_fbm ( n : tcod . noise . Noise , f : Sequence [ float ] , oc : float , typ : int = NOISE_DEFAULT , ) -> float : return float ( lib . TCOD_noise_get_fbm_ex ( n . noise_c , ffi . new ( "float[4]" , f ) , oc , typ ) ) | Return the fractal Brownian motion sampled from the f coordinate . |
242,108 | def noise_get_turbulence ( n : tcod . noise . Noise , f : Sequence [ float ] , oc : float , typ : int = NOISE_DEFAULT , ) -> float : return float ( lib . TCOD_noise_get_turbulence_ex ( n . noise_c , ffi . new ( "float[4]" , f ) , oc , typ ) ) | Return the turbulence noise sampled from the f coordinate . |
242,109 | def random_get_instance ( ) -> tcod . random . Random : return tcod . random . Random . _new_from_cdata ( ffi . cast ( "mersenne_data_t*" , lib . TCOD_random_get_instance ( ) ) ) | Return the default Random instance . |
242,110 | def random_new ( algo : int = RNG_CMWC ) -> tcod . random . Random : return tcod . random . Random ( algo ) | Return a new Random instance . Using algo . |
242,111 | def random_new_from_seed ( seed : Hashable , algo : int = RNG_CMWC ) -> tcod . random . Random : return tcod . random . Random ( algo , seed ) | Return a new Random instance . Using the given seed and algo . |
242,112 | def random_set_distribution ( rnd : Optional [ tcod . random . Random ] , dist : int ) -> None : lib . TCOD_random_set_distribution ( rnd . random_c if rnd else ffi . NULL , dist ) | Change the distribution mode of a random number generator . |
242,113 | def random_save ( rnd : Optional [ tcod . random . Random ] ) -> tcod . random . Random : return tcod . random . Random . _new_from_cdata ( ffi . gc ( ffi . cast ( "mersenne_data_t*" , lib . TCOD_random_save ( rnd . random_c if rnd else ffi . NULL ) , ) , lib . TCOD_random_delete , ) ) | Return a copy of a random number generator . |
242,114 | def random_restore ( rnd : Optional [ tcod . random . Random ] , backup : tcod . random . Random ) -> None : lib . TCOD_random_restore ( rnd . random_c if rnd else ffi . NULL , backup . random_c ) | Restore a random number generator from a backed up copy . |
242,115 | def sys_set_renderer ( renderer : int ) -> None : lib . TCOD_sys_set_renderer ( renderer ) if tcod . console . _root_console is not None : tcod . console . Console . _get_root ( ) | Change the current rendering mode to renderer . |
242,116 | def sys_save_screenshot ( name : Optional [ str ] = None ) -> None : lib . TCOD_sys_save_screenshot ( _bytes ( name ) if name is not None else ffi . NULL ) | Save a screenshot to a file . |
242,117 | def sys_update_char ( asciiCode : int , fontx : int , fonty : int , img : tcod . image . Image , x : int , y : int , ) -> None : lib . TCOD_sys_update_char ( _int ( asciiCode ) , fontx , fonty , img , x , y ) | Dynamically update the current font with img . |
242,118 | def sys_register_SDL_renderer ( callback : Callable [ [ Any ] , None ] ) -> None : with _PropagateException ( ) as propagate : @ ffi . def_extern ( onerror = propagate ) def _pycall_sdl_hook ( sdl_surface : Any ) -> None : callback ( sdl_surface ) lib . TCOD_sys_register_SDL_renderer ( lib . _pycall_sdl_hook ) | Register a custom randering function with libtcod . |
242,119 | def sys_check_for_event ( mask : int , k : Optional [ Key ] , m : Optional [ Mouse ] ) -> int : return int ( lib . TCOD_sys_check_for_event ( mask , k . key_p if k else ffi . NULL , m . mouse_p if m else ffi . NULL ) ) | Check for and return an event . |
242,120 | def sys_wait_for_event ( mask : int , k : Optional [ Key ] , m : Optional [ Mouse ] , flush : bool ) -> int : return int ( lib . TCOD_sys_wait_for_event ( mask , k . key_p if k else ffi . NULL , m . mouse_p if m else ffi . NULL , flush , ) ) | Wait for an event then return . |
242,121 | def _atexit_verify ( ) -> None : if lib . TCOD_ctx . root : warnings . warn ( "The libtcod root console was implicitly deleted.\n" "Make sure the 'with' statement is used with the root console to" " ensure that it closes properly." , ResourceWarning , stacklevel = 2 , ) lib . TCOD_console_delete ( ffi . NULL ) | Warns if the libtcod root console is implicitly deleted . |
242,122 | def clear ( self , back_r : int = 0 , back_g : int = 0 , back_b : int = 0 , fore_r : int = 0 , fore_g : int = 0 , fore_b : int = 0 , char : str = " " , ) -> None : n = self . width * self . height self . back_r = [ back_r ] * n self . back_g = [ back_g ] * n self . back_b = [ back_b ] * n self . fore_r = [ fore_r ] * n... | Clears the console . Values to fill it with are optional defaults to black with no characters . |
242,123 | def copy ( self ) -> "ConsoleBuffer" : other = ConsoleBuffer ( 0 , 0 ) other . width = self . width other . height = self . height other . back_r = list ( self . back_r ) other . back_g = list ( self . back_g ) other . back_b = list ( self . back_b ) other . fore_r = list ( self . fore_r ) other . fore_g = list ( self ... | Returns a copy of this ConsoleBuffer . |
242,124 | def set_fore ( self , x : int , y : int , r : int , g : int , b : int , char : str ) -> None : i = self . width * y + x self . fore_r [ i ] = r self . fore_g [ i ] = g self . fore_b [ i ] = b self . char [ i ] = ord ( char ) | Set the character and foreground color of one cell . |
242,125 | def set_back ( self , x : int , y : int , r : int , g : int , b : int ) -> None : i = self . width * y + x self . back_r [ i ] = r self . back_g [ i ] = g self . back_b [ i ] = b | Set the background color of one cell . |
242,126 | def set ( self , x : int , y : int , back_r : int , back_g : int , back_b : int , fore_r : int , fore_g : int , fore_b : int , char : str , ) -> None : i = self . width * y + x self . back_r [ i ] = back_r self . back_g [ i ] = back_g self . back_b [ i ] = back_b self . fore_r [ i ] = fore_r self . fore_g [ i ] = fore_... | Set the background color foreground color and character of one cell . |
242,127 | def blit ( self , dest : tcod . console . Console , fill_fore : bool = True , fill_back : bool = True , ) -> None : if not dest : dest = tcod . console . Console . _from_cdata ( ffi . NULL ) if dest . width != self . width or dest . height != self . height : raise ValueError ( "ConsoleBuffer.blit: " "Destination consol... | Use libtcod s fill functions to write the buffer to a console . |
242,128 | def clear ( self , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_clear ( self . image_c , color ) | Fill this entire Image with color . |
242,129 | def scale ( self , width : int , height : int ) -> None : lib . TCOD_image_scale ( self . image_c , width , height ) self . width , self . height = width , height | Scale this Image to the new width and height . |
242,130 | def set_key_color ( self , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_set_key_color ( self . image_c , color ) | Set a color to be transparent during blitting functions . |
242,131 | def get_alpha ( self , x : int , y : int ) -> int : return lib . TCOD_image_get_alpha ( self . image_c , x , y ) | Get the Image alpha of the pixel at x y . |
242,132 | def get_pixel ( self , x : int , y : int ) -> Tuple [ int , int , int ] : color = lib . TCOD_image_get_pixel ( self . image_c , x , y ) return color . r , color . g , color . b | Get the color of a pixel in this Image . |
242,133 | def get_mipmap_pixel ( self , left : float , top : float , right : float , bottom : float ) -> Tuple [ int , int , int ] : color = lib . TCOD_image_get_mipmap_pixel ( self . image_c , left , top , right , bottom ) return ( color . r , color . g , color . b ) | Get the average color of a rectangle in this Image . |
242,134 | def put_pixel ( self , x : int , y : int , color : Tuple [ int , int , int ] ) -> None : lib . TCOD_image_put_pixel ( self . image_c , x , y , color ) | Change a pixel on this Image . |
242,135 | def blit ( self , console : tcod . console . Console , x : float , y : float , bg_blend : int , scale_x : float , scale_y : float , angle : float , ) -> None : lib . TCOD_image_blit ( self . image_c , _console ( console ) , x , y , bg_blend , scale_x , scale_y , angle , ) | Blit onto a Console using scaling and rotation . |
242,136 | def blit_rect ( self , console : tcod . console . Console , x : int , y : int , width : int , height : int , bg_blend : int , ) -> None : lib . TCOD_image_blit_rect ( self . image_c , _console ( console ) , x , y , width , height , bg_blend ) | Blit onto a Console without scaling or rotation . |
242,137 | def blit_2x ( self , console : tcod . console . Console , dest_x : int , dest_y : int , img_x : int = 0 , img_y : int = 0 , img_width : int = - 1 , img_height : int = - 1 , ) -> None : lib . TCOD_image_blit_2x ( self . image_c , _console ( console ) , dest_x , dest_y , img_x , img_y , img_width , img_height , ) | Blit onto a Console with double resolution . |
242,138 | def save_as ( self , filename : str ) -> None : lib . TCOD_image_save ( self . image_c , filename . encode ( "utf-8" ) ) | Save the Image to a 32 - bit . bmp or . png file . |
242,139 | def main ( ) : WIDTH , HEIGHT = 120 , 60 TITLE = None with tcod . console_init_root ( WIDTH , HEIGHT , TITLE , order = "F" , renderer = tcod . RENDERER_SDL ) as console : tcod . sys_set_fps ( 24 ) while True : tcod . console_flush ( ) for event in tcod . event . wait ( ) : print ( event ) if event . type == "QUIT" : ra... | Example program for tcod . event |
242,140 | def parse_changelog ( args : Any ) -> Tuple [ str , str ] : with open ( "CHANGELOG.rst" , "r" ) as file : match = re . match ( pattern = r"(.*?Unreleased\n---+\n)(.+?)(\n*[^\n]+\n---+\n.*)" , string = file . read ( ) , flags = re . DOTALL , ) assert match header , changes , tail = match . groups ( ) tag = "%s - %s" % (... | Return an updated changelog and and the list of changes . |
242,141 | def split_once ( self , horizontal : bool , position : int ) -> None : cdata = self . _as_cdata ( ) lib . TCOD_bsp_split_once ( cdata , horizontal , position ) self . _unpack_bsp_tree ( cdata ) | Split this partition into 2 sub - partitions . |
242,142 | def split_recursive ( self , depth : int , min_width : int , min_height : int , max_horizontal_ratio : float , max_vertical_ratio : float , seed : Optional [ tcod . random . Random ] = None , ) -> None : cdata = self . _as_cdata ( ) lib . TCOD_bsp_split_recursive ( cdata , seed or ffi . NULL , depth , min_width , min_h... | Divide this partition recursively . |
242,143 | def in_order ( self ) -> Iterator [ "BSP" ] : if self . children : yield from self . children [ 0 ] . in_order ( ) yield self yield from self . children [ 1 ] . in_order ( ) else : yield self | Iterate over this BSP s hierarchy in order . |
242,144 | def level_order ( self ) -> Iterator [ "BSP" ] : next = [ self ] while next : level = next next = [ ] yield from level for node in level : next . extend ( node . children ) | Iterate over this BSP s hierarchy in level order . |
242,145 | def inverted_level_order ( self ) -> Iterator [ "BSP" ] : levels = [ ] next = [ self ] while next : levels . append ( next ) level = next next = [ ] for node in level : next . extend ( node . children ) while levels : yield from levels . pop ( ) | Iterate over this BSP s hierarchy in inverse level order . |
242,146 | def contains ( self , x : int , y : int ) -> bool : return ( self . x <= x < self . x + self . width and self . y <= y < self . y + self . height ) | Returns True if this node contains these coordinates . |
242,147 | def find_node ( self , x : int , y : int ) -> Optional [ "BSP" ] : if not self . contains ( x , y ) : return None for child in self . children : found = child . find_node ( x , y ) if found : return found return self | Return the deepest node which contains these coordinates . |
242,148 | def backport ( func ) : if not __debug__ : return func @ _functools . wraps ( func ) def deprecated_function ( * args , ** kargs ) : _warnings . warn ( 'This function name is deprecated' , DeprecationWarning , 2 ) return func ( * args , ** kargs ) deprecated_function . __doc__ = None return deprecated_function | Backport a function name into an old style for compatibility . |
242,149 | def _get_fov_type ( fov ) : "Return a FOV from a string" oldFOV = fov fov = str ( fov ) . upper ( ) if fov in _FOVTYPES : return _FOVTYPES [ fov ] if fov [ : 10 ] == 'PERMISSIVE' and fov [ 10 ] . isdigit ( ) and fov [ 10 ] != '9' : return 4 + int ( fov [ 10 ] ) raise _tdl . TDLError ( 'No such fov option as %s' % oldFO... | Return a FOV from a string |
242,150 | def quick_fov ( x , y , callback , fov = 'PERMISSIVE' , radius = 7.5 , lightWalls = True , sphere = True ) : trueRadius = radius radius = int ( _math . ceil ( radius ) ) mapSize = radius * 2 + 1 fov = _get_fov_type ( fov ) setProp = _lib . TCOD_map_set_properties inFOV = _lib . TCOD_map_is_in_fov tcodMap = _lib . TCOD_... | All field - of - view functionality in one call . |
242,151 | def bresenham ( x1 , y1 , x2 , y2 ) : points = [ ] issteep = abs ( y2 - y1 ) > abs ( x2 - x1 ) if issteep : x1 , y1 = y1 , x1 x2 , y2 = y2 , x2 rev = False if x1 > x2 : x1 , x2 = x2 , x1 y1 , y2 = y2 , y1 rev = True deltax = x2 - x1 deltay = abs ( y2 - y1 ) error = int ( deltax / 2 ) y = y1 ystep = None if y1 < y2 : ys... | Return a list of points in a bresenham line . |
242,152 | def compute_fov ( self , x , y , fov = 'PERMISSIVE' , radius = None , light_walls = True , sphere = True , cumulative = False ) : if radius is None : radius = 0 if cumulative : fov_copy = self . fov . copy ( ) lib . TCOD_map_compute_fov ( self . map_c , x , y , radius , light_walls , _get_fov_type ( fov ) ) if cumulati... | Compute the field - of - view of this Map and return an iterator of the points touched . |
242,153 | def compute_path ( self , start_x , start_y , dest_x , dest_y , diagonal_cost = _math . sqrt ( 2 ) ) : return tcod . path . AStar ( self , diagonal_cost ) . get_path ( start_x , start_y , dest_x , dest_y ) | Get the shortest path between two points . |
242,154 | def get_path ( self , origX , origY , destX , destY ) : return super ( AStar , self ) . get_path ( origX , origY , destX , destY ) | Get the shortest path from origXY to destXY . |
242,155 | def get_long_description ( ) : with open ( "README.rst" , "r" ) as f : readme = f . read ( ) with open ( "CHANGELOG.rst" , "r" ) as f : changelog = f . read ( ) changelog = changelog . replace ( "\nUnreleased\n------------------" , "" ) return "\n" . join ( [ readme , changelog ] ) | Return this projects description . |
242,156 | def get_height_rect ( width : int , string : str ) -> int : string_ = string . encode ( "utf-8" ) return int ( lib . get_height_rect2 ( width , string_ , len ( string_ ) ) ) | Return the number of lines which would be printed from these parameters . |
242,157 | def _get_root ( cls , order : Optional [ str ] = None ) -> "Console" : global _root_console if _root_console is None : _root_console = object . __new__ ( cls ) self = _root_console if order is not None : self . _order = order self . console_c = ffi . NULL self . _init_setup_console_data ( self . _order ) return self | Return a root console singleton with valid buffers . |
242,158 | def _init_setup_console_data ( self , order : str = "C" ) -> None : global _root_console self . _key_color = None if self . console_c == ffi . NULL : _root_console = self self . _console_data = lib . TCOD_ctx . root else : self . _console_data = ffi . cast ( "struct TCOD_Console*" , self . console_c ) self . _tiles = n... | Setup numpy arrays over libtcod data buffers . |
242,159 | def tiles ( self ) -> np . array : return self . _tiles . T if self . _order == "F" else self . _tiles | An array of this consoles tile data . |
242,160 | def __clear_warning ( self , name : str , value : Tuple [ int , int , int ] ) -> None : warnings . warn ( "Clearing with the console default values is deprecated.\n" "Add %s=%r to this call." % ( name , value ) , DeprecationWarning , stacklevel = 3 , ) | Raise a warning for bad default values during calls to clear . |
242,161 | def __deprecate_defaults ( self , new_func : str , bg_blend : Any , alignment : Any = ... , clear : Any = ... , ) -> None : if not __debug__ : return fg = self . default_fg bg = self . default_bg if bg_blend == tcod . constants . BKGND_NONE : bg = None if bg_blend == tcod . constants . BKGND_DEFAULT : bg_blend = self .... | Return the parameters needed to recreate the current default state . |
242,162 | def get_height_rect ( self , x : int , y : int , width : int , height : int , string : str ) -> int : string_ = string . encode ( "utf-8" ) return int ( lib . get_height_rect ( self . console_c , x , y , width , height , string_ , len ( string_ ) ) ) | Return the height of this text word - wrapped into this rectangle . |
242,163 | def print_frame ( self , x : int , y : int , width : int , height : int , string : str = "" , clear : bool = True , bg_blend : int = tcod . constants . BKGND_DEFAULT , ) -> None : self . __deprecate_defaults ( "draw_frame" , bg_blend ) string = _fmt ( string ) if string else ffi . NULL lib . TCOD_console_printf_frame (... | Draw a framed rectangle with optional text . |
242,164 | def blit ( self , dest : "Console" , dest_x : int = 0 , dest_y : int = 0 , src_x : int = 0 , src_y : int = 0 , width : int = 0 , height : int = 0 , fg_alpha : float = 1.0 , bg_alpha : float = 1.0 , key_color : Optional [ Tuple [ int , int , int ] ] = None , ) -> None : if hasattr ( src_y , "console_c" ) : ( src_x , src... | Blit from this console onto the dest console . |
242,165 | def print ( self , x : int , y : int , string : str , fg : Optional [ Tuple [ int , int , int ] ] = None , bg : Optional [ Tuple [ int , int , int ] ] = None , bg_blend : int = tcod . constants . BKGND_SET , alignment : int = tcod . constants . LEFT , ) -> None : x , y = self . _pythonic_index ( x , y ) string_ = strin... | Print a string on a console with manual line breaks . |
242,166 | def draw_frame ( self , x : int , y : int , width : int , height : int , title : str = "" , clear : bool = True , fg : Optional [ Tuple [ int , int , int ] ] = None , bg : Optional [ Tuple [ int , int , int ] ] = None , bg_blend : int = tcod . constants . BKGND_SET , ) -> None : x , y = self . _pythonic_index ( x , y )... | Draw a framed rectangle with an optional title . |
242,167 | def draw_rect ( self , x : int , y : int , width : int , height : int , ch : int , fg : Optional [ Tuple [ int , int , int ] ] = None , bg : Optional [ Tuple [ int , int , int ] ] = None , bg_blend : int = tcod . constants . BKGND_SET , ) -> None : x , y = self . _pythonic_index ( x , y ) lib . draw_rect ( self . conso... | Draw characters and colors over a rectangular region . |
242,168 | def blit ( self , image , x , y ) : x += self . font_bbox [ 2 ] - self . bbox [ 2 ] y += self . font_bbox [ 3 ] - self . bbox [ 3 ] x += self . font_bbox [ 0 ] - self . bbox [ 0 ] y += self . font_bbox [ 1 ] - self . bbox [ 1 ] image [ y : y + self . height , x : x + self . width ] = self . bitmap * 255 | blit to the image array |
242,169 | def parseBits ( self , hexcode , width ) : bitarray = [ ] for byte in hexcode [ : : - 1 ] : bits = int ( byte , 16 ) for x in range ( 4 ) : bitarray . append ( bool ( ( 2 ** x ) & bits ) ) bitarray = bitarray [ : : - 1 ] return enumerate ( bitarray [ : width ] ) | enumerate over bits in a line of data |
242,170 | def memory_warning ( config , context ) : used = psutil . Process ( os . getpid ( ) ) . memory_info ( ) . rss / 1048576 limit = float ( context . memory_limit_in_mb ) p = used / limit memory_threshold = config . get ( 'memory_warning_threshold' ) if p >= memory_threshold : config [ 'raven_client' ] . captureMessage ( '... | Determines when memory usage is nearing it s max . |
242,171 | def install_timers ( config , context ) : timers = [ ] if config . get ( 'capture_timeout_warnings' ) : timeout_threshold = config . get ( 'timeout_warning_threshold' ) time_remaining = context . get_remaining_time_in_millis ( ) / 1000 timers . append ( Timer ( time_remaining * timeout_threshold , timeout_warning , ( c... | Create the timers as specified by the plugin configuration . |
242,172 | def recurseforumcontents ( parser , token ) : bits = token . contents . split ( ) forums_contents_var = template . Variable ( bits [ 1 ] ) template_nodes = parser . parse ( ( 'endrecurseforumcontents' , ) ) parser . delete_first_token ( ) return RecurseTreeForumVisibilityContentNode ( template_nodes , forums_contents_v... | Iterates over the content nodes and renders the contained forum block for each node . |
242,173 | def forum_list ( context , forum_visibility_contents ) : request = context . get ( 'request' ) tracking_handler = TrackingHandler ( request = request ) data_dict = { 'forum_contents' : forum_visibility_contents , 'unread_forums' : tracking_handler . get_unread_forums_from_list ( request . user , forum_visibility_conten... | Renders the considered forum list . |
242,174 | def get_object ( self , request , * args , ** kwargs ) : forum_pk = kwargs . get ( 'forum_pk' , None ) descendants = kwargs . get ( 'descendants' , None ) self . user = request . user if forum_pk : forum = get_object_or_404 ( Forum , pk = forum_pk ) forums_qs = ( forum . get_descendants ( include_self = True ) if desce... | Handles the considered object . |
242,175 | def items ( self ) : return Topic . objects . filter ( forum__in = self . forums , approved = True ) . order_by ( '-last_post_on' ) | Returns the items to include into the feed . |
242,176 | def item_link ( self , item ) : return reverse_lazy ( 'forum_conversation:topic' , kwargs = { 'forum_slug' : item . forum . slug , 'forum_pk' : item . forum . pk , 'slug' : item . slug , 'pk' : item . id , } , ) | Generates a link for a specific item of the feed . |
242,177 | def topic_pages_inline_list ( topic ) : data_dict = { 'topic' : topic , } pages_number = ( ( topic . posts_count - 1 ) // machina_settings . TOPIC_POSTS_NUMBER_PER_PAGE ) + 1 if pages_number > 5 : data_dict [ 'first_pages' ] = range ( 1 , 5 ) data_dict [ 'last_page' ] = pages_number elif pages_number > 1 : data_dict [ ... | This will render an inline pagination for the posts related to the given topic . |
242,178 | def get_urls ( self ) : urls = super ( ) . get_urls ( ) forum_admin_urls = [ url ( r'^(?P<forum_id>[0-9]+)/move-forum/(?P<direction>up|down)/$' , self . admin_site . admin_view ( self . moveforum_view ) , name = 'forum_forum_move' , ) , url ( r'^edit-global-permissions/$' , self . admin_site . admin_view ( self . editp... | Returns the URLs associated with the admin abstraction . |
242,179 | def get_forum_perms_base_context ( self , request , obj = None ) : context = { 'adminform' : { 'model_admin' : self } , 'media' : self . media , 'object' : obj , 'app_label' : self . model . _meta . app_label , 'opts' : self . model . _meta , 'has_change_permission' : self . has_change_permission ( request , obj ) , } ... | Returns the context to provide to the template for permissions contents . |
242,180 | def moveforum_view ( self , request , forum_id , direction ) : forum = get_object_or_404 ( Forum , pk = forum_id ) target , position = None , None if direction == 'up' : target , position = forum . get_previous_sibling ( ) , 'left' elif direction == 'down' : target , position = forum . get_next_sibling ( ) , 'right' tr... | Moves the given forum toward the requested direction . |
242,181 | def editpermissions_index_view ( self , request , forum_id = None ) : forum = get_object_or_404 ( Forum , pk = forum_id ) if forum_id else None context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ] = _ ( 'Forum permissions' ) if forum else _ ( 'Global forum pe... | Allows to select how to edit forum permissions . |
242,182 | 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 context = self . get_forum_perms_base_context ( request , forum ) context [ 'for... | Allows to edit user permissions for the considered forum . |
242,183 | def editpermissions_anonymous_user_view ( self , request , forum_id = None ) : forum = get_object_or_404 ( Forum , pk = forum_id ) if forum_id else None context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ] = '{} - {}' . format ( _ ( 'Forum permissions' ) , _ ... | Allows to edit anonymous user permissions for the considered forum . |
242,184 | 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 context = self . get_forum_perms_base_context ( request , forum ) context [ 'forum' ] = forum context [ 'title' ]... | Allows to edit group permissions for the considered forum . |
242,185 | 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 ] fo... | This will return a boolean indicating if the considered permission is granted for the passed user . |
242,186 | 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 . |
242,187 | 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 ) ) module_path = app_module_path if '.' in app_module_path : ba... | Imports a set of classes from a given module . |
242,188 | def _import_module ( module_path , classnames ) : try : imported_module = __import__ ( module_path , fromlist = classnames ) return imported_module except ImportError : __ , __ , exc_traceback = sys . exc_info ( ) frames = traceback . extract_tb ( exc_traceback ) if len ( frames ) > 1 : raise | Tries to import the given Python module path . |
242,189 | 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 . |
242,190 | 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 . |
242,191 | 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 . |
242,192 | def get_unread_forums_from_list ( self , user , forums ) : unread_forums = [ ] 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 . |
242,193 | def get_unread_topics ( self , topics , user ) : unread_topics = [ ] if not user . is_authenticated or topics is None or not len ( topics ) : return unread_topics topic_ids = [ topic . id for topic in topics ] topic_tracks = TopicReadTrack . objects . filter ( topic__in = topic_ids , user = user ) tracked_topics = dict... | Returns a list of unread topics for the given user from a given set of topics . |
242,194 | def mark_forums_read ( self , forums , user ) : if not forums or not user . is_authenticated : return forums = sorted ( forums , key = lambda f : f . level ) for forum in forums : forum_track = ForumReadTrack . objects . get_or_create ( forum = forum , user = user ) [ 0 ] forum_track . save ( ) TopicReadTrack . objects... | Marks a list of forums as read . |
242,195 | 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 . |
242,196 | 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 . |
242,197 | 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 . |
242,198 | 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 . name ) , allow_unicode = True ) super ( ) . save ( * args , ** kwargs ) if old_instance and old_instance . parent != self . ... | Saves the forum instance . |
242,199 | def update_trackers ( self ) : direct_approved_topics = self . topics . filter ( approved = True ) . order_by ( '-last_post_on' ) self . direct_topics_count = direct_approved_topics . count ( ) self . direct_posts_count = direct_approved_topics . aggregate ( total_posts_count = Sum ( 'posts_count' ) ) [ 'total_posts_co... | Updates the denormalized trackers associated with the forum instance . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.