idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
239,300
def save ( self , f ) : return pickle . dump ( ( self . perceptron . weights , self . tagdict , self . classes , self . clusters ) , f , protocol = pickle . HIGHEST_PROTOCOL )
Save pickled model to file .
239,301
def load ( self , model ) : self . perceptron . weights , self . tagdict , self . classes , self . clusters = load_model ( model ) self . perceptron . classes = self . classes
Load pickled model .
239,302
def train ( self , sentences , model ) : trainer = pycrfsuite . Trainer ( verbose = True ) trainer . set_params ( self . params ) for sentence in sentences : tokens , labels = zip ( * sentence ) features = [ self . _get_features ( tokens , i ) for i in range ( len ( tokens ) ) ] trainer . append ( features , labels ) t...
Train the CRF tagger using CRFSuite .
239,303
def load ( self , model ) : self . _dawg . load ( find_data ( model ) ) self . _loaded_model = True
Load pickled DAWG from disk .
239,304
def build ( self , words ) : words = [ self . _normalize ( tokens ) for tokens in words ] self . _dawg = dawg . CompletionDAWG ( words ) self . _loaded_model = True
Construct dictionary DAWG from tokenized words .
239,305
def _normalize ( self , tokens ) : if self . case_sensitive : return ' ' . join ( self . lexicon [ t ] . normalized for t in tokens ) else : return ' ' . join ( self . lexicon [ t ] . lower for t in tokens )
Normalization transform to apply to both dictionary words and input tokens .
239,306
def standardize_role ( role ) : role = role . lower ( ) if any ( c in role for c in { 'synthesis' , 'give' , 'yield' , 'afford' , 'product' , 'preparation of' } ) : return 'product' return role
Convert role text into standardized form .
239,307
def list ( ctx ) : log . debug ( 'chemdataextractor.data.list' ) click . echo ( 'Downloaded\tPackage' ) for package in PACKAGES : click . echo ( '%s\t%s' % ( package . local_exists ( ) , package . path ) )
List active data packages .
239,308
def download ( ctx ) : log . debug ( 'chemdataextractor.data.download' ) count = 0 for package in PACKAGES : success = package . download ( ) if success : count += 1 click . echo ( 'Successfully downloaded %s new data packages (%s existing)' % ( count , len ( PACKAGES ) - count ) )
Download data .
239,309
def find_data ( path , warn = True ) : full_path = os . path . join ( get_data_dir ( ) , path ) if warn and not os . path . isfile ( full_path ) : for package in PACKAGES : if path == package . path : log . warn ( '%s doesn\'t exist. Run `cde data download` to get it.' % path ) break return full_path
Return the absolute path to a data file within the data directory .
239,310
def load_model ( path ) : abspath = find_data ( path ) cached = _model_cache . get ( abspath ) if cached is not None : log . debug ( 'Using cached copy of %s' % path ) return cached log . debug ( 'Loading model %s' % path ) try : with io . open ( abspath , 'rb' ) as f : model = six . moves . cPickle . load ( f ) except...
Load a model from a pickle file in the data directory . Cached so model is only loaded once .
239,311
def normalize ( self , text ) : text = super ( ChemNormalizer , self ) . normalize ( text ) if self . chem_spell : text = re . sub ( r'sulph' , r'sulf' , text , flags = re . I ) text = re . sub ( r'aluminum' , r'aluminium' , text , flags = re . I ) text = re . sub ( r'cesium' , r'caesium' , text , flags = re . I ) retu...
Normalize unicode hyphens whitespace and some chemistry terms and formatting .
239,312
def add ( self , text ) : if text not in self . lexemes : normalized = self . normalized ( text ) self . lexemes [ text ] = Lexeme ( text = text , normalized = normalized , lower = self . lower ( normalized ) , first = self . first ( normalized ) , suffix = self . suffix ( normalized ) , shape = self . shape ( normaliz...
Add text to the lexicon .
239,313
def serialize ( self ) : data = { 'type' : self . __class__ . __name__ , 'caption' : self . caption . serialize ( ) , 'headings' : [ [ cell . serialize ( ) for cell in hrow ] for hrow in self . headings ] , 'rows' : [ [ cell . serialize ( ) for cell in row ] for row in self . rows ] , } return data
Convert Table element to python dictionary .
239,314
def merge ( self , other ) : log . debug ( 'Merging: %s and %s' % ( self . serialize ( ) , other . serialize ( ) ) ) for k in self . keys ( ) : for new_item in other [ k ] : if new_item not in self [ k ] : self [ k ] . append ( new_item ) log . debug ( 'Result: %s' % self . serialize ( ) ) return self
Merge data from another Compound into this Compound .
239,315
def merge_contextual ( self , other ) : for k in self . keys ( ) : for item in self [ k ] : for other_item in other . get ( k , [ ] ) : if isinstance ( other_item , six . text_type ) : continue for otherk in other_item . keys ( ) : if isinstance ( other_item [ otherk ] , list ) : if len ( other_item [ otherk ] ) > 0 an...
Merge in contextual info from a template Compound .
239,316
def is_id_only ( self ) : for key , value in self . items ( ) : if key not in { 'names' , 'labels' , 'roles' } and value : return False if self . names or self . labels : return True return False
Return True if identifier information only .
239,317
def join ( tokens , start , result ) : texts = [ ] if len ( result ) > 0 : for e in result : for child in e . iter ( ) : if child . text is not None : texts . append ( child . text ) return [ E ( result [ 0 ] . tag , ' ' . join ( texts ) ) ]
Join tokens into a single string with spaces between .
239,318
def strip_stop ( tokens , start , result ) : for e in result : for child in e . iter ( ) : if child . text . endswith ( '.' ) : child . text = child . text [ : - 1 ] return result
Remove trailing full stop from tokens .
239,319
def fix_whitespace ( tokens , start , result ) : for e in result : for child in e . iter ( ) : child . text = child . text . replace ( ' , ' , ', ' ) for hyphen in HYPHENS : child . text = child . text . replace ( ' %s ' % hyphen , '%s' % hyphen ) child . text = re . sub ( r'- (.) -' , r'-\1-' , child . text ) return r...
Fix whitespace around hyphens and commas . Can be used to remove whitespace tokenization artefacts .
239,320
def detect ( self , fstring , fname = None ) : if fname is not None and '.' in fname : extension = fname . rsplit ( '.' , 1 ) [ 1 ] if extension in { 'pdf' , 'html' , 'xml' } : return False return True
Have a stab at most files .
239,321
def _process_layout ( self , layout ) : elements = [ ] for lt_obj in layout : if isinstance ( lt_obj , LTTextBox ) or isinstance ( lt_obj , LTTextLine ) : elements . append ( Paragraph ( lt_obj . get_text ( ) . strip ( ) ) ) elif isinstance ( lt_obj , LTFigure ) : elements . extend ( self . _process_layout ( lt_obj ) )...
Process an LTPage layout and return a list of elements .
239,322
def get_encoding ( input_string , guesses = None , is_html = False ) : converted = UnicodeDammit ( input_string , override_encodings = [ guesses ] if guesses else [ ] , is_html = is_html ) return converted . original_encoding
Return the encoding of a byte string . Uses bs4 UnicodeDammit .
239,323
def levenshtein ( s1 , s2 , allow_substring = False ) : len1 , len2 = len ( s1 ) , len ( s2 ) lev = [ ] for i in range ( len1 + 1 ) : lev . append ( [ 0 ] * ( len2 + 1 ) ) for i in range ( len1 + 1 ) : lev [ i ] [ 0 ] = i for j in range ( len2 + 1 ) : lev [ 0 ] [ j ] = 0 if allow_substring else j for i in range ( len1 ...
Return the Levenshtein distance between two strings .
239,324
def bracket_level ( text , open = { '(' , '[' , '{' } , close = { ')' , ']' , '}' } ) : level = 0 for c in text : if c in open : level += 1 elif c in close : level -= 1 return level
Return 0 if string contains balanced brackets or no brackets .
239,325
def list ( ctx ) : log . debug ( 'chemdataextractor.config.list' ) for k in config : click . echo ( '%s : %s' % ( k , config [ k ] ) )
List all config values .
239,326
def train_crf ( ctx , input , output , clusters ) : click . echo ( 'chemdataextractor.crf.train' ) sentences = [ ] for line in input : sentence = [ ] for t in line . split ( ) : token , tag , iob = t . rsplit ( '/' , 2 ) sentence . append ( ( ( token , tag ) , iob ) ) if sentence : sentences . append ( sentence ) tagge...
Train CRF CEM recognizer .
239,327
def sentences ( self ) : sents = [ ] spans = self . sentence_tokenizer . span_tokenize ( self . text ) for span in spans : sent = Sentence ( text = self . text [ span [ 0 ] : span [ 1 ] ] , start = span [ 0 ] , end = span [ 1 ] , word_tokenizer = self . word_tokenizer , lexicon = self . lexicon , abbreviation_detector ...
Return a list of Sentences that make up this text passage .
239,328
def records ( self ) : return ModelList ( * [ r for sent in self . sentences for r in sent . records ] )
Return a list of records for this text passage .
239,329
def tokens ( self ) : spans = self . word_tokenizer . span_tokenize ( self . text ) toks = [ Token ( text = self . text [ span [ 0 ] : span [ 1 ] ] , start = span [ 0 ] + self . start , end = span [ 1 ] + self . start , lexicon = self . lexicon ) for span in spans ] return toks
Return a list of token Spans for this sentence .
239,330
def tags ( self ) : tags = self . pos_tags for i , tag in enumerate ( self . ner_tags ) : if tag is not None : tags [ i ] = tag return tags
Return combined POS and NER tags .
239,331
def records ( self ) : compounds = ModelList ( ) seen_labels = set ( ) tagged_tokens = [ ( CONTROL_RE . sub ( '' , token ) , tag ) for token , tag in self . tagged_tokens ] for parser in self . parsers : for record in parser . parse ( tagged_tokens ) : p = record . serialize ( ) if not p : continue if record in compoun...
Return a list of records for this sentence .
239,332
def prepare_gold ( ctx , annotations , gout ) : click . echo ( 'chemdataextractor.chemdner.prepare_gold' ) for line in annotations : pmid , ta , start , end , text , category = line . strip ( ) . split ( '\t' ) gout . write ( '%s\t%s:%s:%s\n' % ( pmid , ta , start , end ) )
Prepare bc - evaluate gold file from annotations supplied by CHEMDNER .
239,333
def prepare_tokens ( ctx , input , annotations , tout , lout ) : click . echo ( 'chemdataextractor.chemdner.prepare_tokens' ) anndict = defaultdict ( list ) for line in annotations : pmid , ta , start , end , text , category = line . strip ( ) . split ( '\t' ) anndict [ ( pmid , ta ) ] . append ( ( int ( start ) , int ...
Prepare tokenized and tagged corpus file from those supplied by CHEMDNER .
239,334
def _prep_tags ( t , annotations ) : tags = [ [ 'O' for _ in sent . tokens ] for sent in t . sentences ] for start , end , text in annotations : done_first = False for i , sent in enumerate ( t . sentences ) : for j , token in enumerate ( sent . tokens ) : if start <= token . start < end or start < token . end <= end :...
Apply IOB chemical entity tags and POS tags to text .
239,335
def train_all ( ctx , output ) : click . echo ( 'chemdataextractor.pos.train_all' ) click . echo ( 'Output: %s' % output ) ctx . invoke ( train , output = '%s_wsj_nocluster.pickle' % output , corpus = 'wsj' , clusters = False ) ctx . invoke ( train , output = '%s_wsj.pickle' % output , corpus = 'wsj' , clusters = True ...
Train POS tagger on WSJ GENIA and both . With and without cluster features .
239,336
def evaluate_all ( ctx , model ) : click . echo ( 'chemdataextractor.pos.evaluate_all' ) click . echo ( 'Model: %s' % model ) ctx . invoke ( evaluate , model = '%s_wsj_nocluster.pickle' % model , corpus = 'wsj' , clusters = False ) ctx . invoke ( evaluate , model = '%s_wsj_nocluster.pickle' % model , corpus = 'genia' ,...
Evaluate POS taggers on WSJ and GENIA .
239,337
def train ( ctx , output , corpus , clusters ) : click . echo ( 'chemdataextractor.pos.train' ) click . echo ( 'Output: %s' % output ) click . echo ( 'Corpus: %s' % corpus ) click . echo ( 'Clusters: %s' % clusters ) wsj_sents = [ ] genia_sents = [ ] if corpus == 'wsj' or corpus == 'wsj+genia' : wsj_sents = list ( wsj_...
Train POS Tagger .
239,338
def evaluate ( ctx , model , corpus , clusters ) : click . echo ( 'chemdataextractor.pos.evaluate' ) if corpus == 'wsj' : evaluation = wsj_evaluation sents = list ( evaluation . tagged_sents ( ) ) for i , wsj_sent in enumerate ( sents ) : sents [ i ] = [ t for t in wsj_sent if not t [ 1 ] == '-NONE-' ] elif corpus == '...
Evaluate performance of POS Tagger .
239,339
def evaluate_perceptron ( ctx , model , corpus ) : click . echo ( 'chemdataextractor.pos.evaluate' ) if corpus == 'wsj' : evaluation = wsj_evaluation sents = list ( evaluation . tagged_sents ( ) ) for i , wsj_sent in enumerate ( sents ) : sents [ i ] = [ t for t in wsj_sent if not t [ 1 ] == u'-NONE-' ] elif corpus == ...
Evaluate performance of Averaged Perceptron POS Tagger .
239,340
def tag ( ctx , input , output ) : log . info ( 'chemdataextractor.pos.tag' ) log . info ( 'Reading %s' % input . name ) doc = Document . from_file ( input ) for element in doc . elements : if isinstance ( element , Text ) : for sentence in element . sentences : output . write ( u' ' . join ( u'/' . join ( [ token , ta...
Output POS - tagged tokens .
239,341
def make_request ( self , session , url , ** kwargs ) : log . debug ( 'Making request: GET %s %s' % ( url , kwargs ) ) return session . get ( url , ** kwargs )
Make a HTTP GET request .
239,342
def make_request ( self , session , url , ** kwargs ) : log . debug ( 'Making request: POST %s %s' % ( url , kwargs ) ) return session . post ( url , ** kwargs )
Make a HTTP POST request .
239,343
def run ( self , url ) : url = self . process_url ( url ) if not url : return response = self . make_request ( self . http , url ) selector = self . process_response ( response ) entities = [ ] for root in self . get_roots ( selector ) : entity = self . entity ( root ) entity = self . process_entity ( entity ) if entit...
Request URL scrape response and return an EntityList .
239,344
def clean_html ( self , html ) : result_type = type ( html ) if isinstance ( html , six . string_types ) : doc = html_fromstring ( html ) else : doc = copy . deepcopy ( html ) self ( doc ) if issubclass ( result_type , six . binary_type ) : return tostring ( doc , encoding = 'utf-8' ) elif issubclass ( result_type , si...
Apply Cleaner to HTML string or document and return a cleaned string or document .
239,345
def clean_markup ( self , markup , parser = None ) : result_type = type ( markup ) if isinstance ( markup , six . string_types ) : doc = fromstring ( markup , parser = parser ) else : doc = copy . deepcopy ( markup ) self ( doc ) if issubclass ( result_type , six . binary_type ) : return tostring ( doc , encoding = 'ut...
Apply Cleaner to markup string or document and return a cleaned string or document .
239,346
def floats ( s ) : try : return float ( s ) except ValueError : s = re . sub ( r'(\d)\s*\(\d+(\.\d+)?\)' , r'\1' , s ) s = re . sub ( r'(\d)\s*±\s*\d+(\.\d+)?', '\1', ) s = s . rstrip ( '\'"+-=<>/,.:;!?)]}…∼~≈×*_≥≤') s = s . lstrip ( '\'"+=<>/([{∼~≈×*_≥≤£$€#§') s = s . replace ( ',' , ''...
Convert string to float . Handles more string formats that the standard python conversion .
239,347
def strip_querystring ( url ) : p = six . moves . urllib . parse . urlparse ( url ) return p . scheme + "://" + p . netloc + p . path
Remove the querystring from the end of a URL .
239,348
def extract_emails ( text ) : text = text . replace ( u'\u2024' , '.' ) emails = [ ] for m in EMAIL_RE . findall ( text ) : emails . append ( m [ 0 ] ) return emails
Return a list of email addresses extracted from the string .
239,349
def unapostrophe ( text ) : text = re . sub ( r'[%s]s?$' % '' . join ( APOSTROPHES ) , '' , text ) return text
Strip apostrophe and s from the end of a string .
239,350
def getLocalTime ( date , time , * args , ** kwargs ) : if time is not None : return getLocalDateAndTime ( date , time , * args , ** kwargs ) [ 1 ]
Get the time in the local timezone from date and time
239,351
def getLocalDateAndTime ( date , time , * args , ** kwargs ) : localDt = getLocalDatetime ( date , time , * args , ** kwargs ) if time is not None : return ( localDt . date ( ) , localDt . timetz ( ) ) else : return ( localDt . date ( ) , None )
Get the date and time in the local timezone from date and optionally time
239,352
def getLocalDatetime ( date , time , tz = None , timeDefault = dt . time . max ) : localTZ = timezone . get_current_timezone ( ) if tz is None or tz == localTZ : localDt = getAwareDatetime ( date , time , tz , timeDefault ) else : eventDt = getAwareDatetime ( date , time , tz , timeDefault ) localDt = eventDt . astimez...
Get a datetime in the local timezone from date and optionally time
239,353
def getAwareDatetime ( date , time , tz , timeDefault = dt . time . max ) : if time is None : time = timeDefault datetime = dt . datetime . combine ( date , time ) datetime = timezone . make_aware ( datetime , tz , is_dst = False ) return datetime
Get a datetime in the given timezone from date and optionally time . If time is not given it will default to timeDefault if that is given or if not then to the end of the day .
239,354
def _iso_num_weeks ( iso_year ) : "Get the number of ISO-weeks in this year" year_start = _iso_year_start ( iso_year ) next_year_start = _iso_year_start ( iso_year + 1 ) year_num_weeks = ( ( next_year_start - year_start ) . days ) // 7 return year_num_weeks
Get the number of ISO - weeks in this year
239,355
def _iso_info ( iso_year , iso_week ) : "Give all the iso info we need from one calculation" prev_year_start = _iso_year_start ( iso_year - 1 ) year_start = _iso_year_start ( iso_year ) next_year_start = _iso_year_start ( iso_year + 1 ) first_day = year_start + dt . timedelta ( weeks = iso_week - 1 ) last_day = first_d...
Give all the iso info we need from one calculation
239,356
def _iso_week_of_month ( date_value ) : "0-starting index which ISO-week in the month this date is" weekday_of_first = date_value . replace ( day = 1 ) . weekday ( ) return ( date_value . day + weekday_of_first - 1 ) // 7
0 - starting index which ISO - week in the month this date is
239,357
def _ssweek_year_start ( ssweek_year ) : "The gregorian calendar date of the first day of the given Sundaystarting-week year" fifth_jan = dt . date ( ssweek_year , 1 , 5 ) delta = dt . timedelta ( fifth_jan . weekday ( ) + 1 ) return fifth_jan - delta
The gregorian calendar date of the first day of the given Sundaystarting - week year
239,358
def _ssweek_to_gregorian ( ssweek_year , ssweek_week , ssweek_day ) : "Gregorian calendar date for the given Sundaystarting-week year, week and day" year_start = _ssweek_year_start ( ssweek_year ) return year_start + dt . timedelta ( days = ssweek_day - 1 , weeks = ssweek_week - 1 )
Gregorian calendar date for the given Sundaystarting - week year week and day
239,359
def _ssweek_num_weeks ( ssweek_year ) : "Get the number of Sundaystarting-weeks in this year" year_start = _ssweek_year_start ( ssweek_year ) next_year_start = _ssweek_year_start ( ssweek_year + 1 ) year_num_weeks = ( ( next_year_start - year_start ) . days ) // 7 return year_num_weeks
Get the number of Sundaystarting - weeks in this year
239,360
def _ssweek_info ( ssweek_year , ssweek_week ) : "Give all the ssweek info we need from one calculation" prev_year_start = _ssweek_year_start ( ssweek_year - 1 ) year_start = _ssweek_year_start ( ssweek_year ) next_year_start = _ssweek_year_start ( ssweek_year + 1 ) first_day = year_start + dt . timedelta ( weeks = ssw...
Give all the ssweek info we need from one calculation
239,361
def _gregorian_to_ssweek ( date_value ) : "Sundaystarting-week year, week and day for the given Gregorian calendar date" yearStart = _ssweek_year_start ( date_value . year ) weekNum = ( ( date_value - yearStart ) . days ) // 7 + 1 dayOfWeek = date_value . weekday ( ) + 1 return ( date_value . year , weekNum , dayOfWee...
Sundaystarting - week year week and day for the given Gregorian calendar date
239,362
def _ssweek_of_month ( date_value ) : "0-starting index which Sundaystarting-week in the month this date is" weekday_of_first = ( date_value . replace ( day = 1 ) . weekday ( ) + 1 ) % 7 return ( date_value . day + weekday_of_first - 1 ) // 7
0 - starting index which Sundaystarting - week in the month this date is
239,363
def byweekday ( self ) : retval = [ ] if self . rule . _byweekday : retval += [ Weekday ( day ) for day in self . rule . _byweekday ] if self . rule . _bynweekday : retval += [ Weekday ( day , n ) for day , n in self . rule . _bynweekday ] return retval
The weekdays where the recurrence will be applied . In RFC5545 this is called BYDAY but is renamed by dateutil to avoid ambiguity .
239,364
def bymonthday ( self ) : retval = [ ] if self . rule . _bymonthday : retval += self . rule . _bymonthday if self . rule . _bynmonthday : retval += self . rule . _bynmonthday return retval
The month days where the recurrence will be applied .
239,365
def routeDefault ( self , request , year = None ) : eventsView = request . GET . get ( 'view' , self . default_view ) if eventsView in ( "L" , "list" ) : return self . serveUpcoming ( request ) elif eventsView in ( "W" , "weekly" ) : return self . serveWeek ( request , year ) else : return self . serveMonth ( request ,...
Route a request to the default calendar view .
239,366
def routeByMonthAbbr ( self , request , year , monthAbbr ) : month = ( DatePictures [ 'Mon' ] . index ( monthAbbr . lower ( ) ) // 4 ) + 1 return self . serveMonth ( request , year , month )
Route a request with a month abbreviation to the monthly view .
239,367
def serveMonth ( self , request , year = None , month = None ) : myurl = self . get_url ( request ) def myUrl ( urlYear , urlMonth ) : if 1900 <= urlYear <= 2099 : return myurl + self . reverse_subpage ( 'serveMonth' , args = [ urlYear , urlMonth ] ) today = timezone . localdate ( ) if year is None : year = today . yea...
Monthly calendar view .
239,368
def serveWeek ( self , request , year = None , week = None ) : myurl = self . get_url ( request ) def myUrl ( urlYear , urlWeek ) : if ( urlYear < 1900 or urlYear > 2099 or urlYear == 2099 and urlWeek == 53 ) : return None if urlWeek == 53 and num_weeks_in_year ( urlYear ) == 52 : urlWeek = 52 return myurl + self . rev...
Weekly calendar view .
239,369
def serveDay ( self , request , year = None , month = None , dom = None ) : myurl = self . get_url ( request ) today = timezone . localdate ( ) if year is None : year = today . year if month is None : month = today . month if dom is None : dom = today . day year = int ( year ) month = int ( month ) dom = int ( dom ) da...
The events of the day list view .
239,370
def serveUpcoming ( self , request ) : myurl = self . get_url ( request ) today = timezone . localdate ( ) monthlyUrl = myurl + self . reverse_subpage ( 'serveMonth' , args = [ today . year , today . month ] ) weekNum = gregorian_to_week_date ( today ) [ 1 ] weeklyUrl = myurl + self . reverse_subpage ( 'serveWeek' , ar...
Upcoming events list view .
239,371
def serveMiniMonth ( self , request , year = None , month = None ) : if not request . is_ajax ( ) : raise Http404 ( "/mini/ is for ajax requests only" ) today = timezone . localdate ( ) if year is None : year = today . year if month is None : month = today . month year = int ( year ) month = int ( month ) return render...
Serve data for the MiniMonth template tag .
239,372
def _allowAnotherAt ( cls , parent ) : site = parent . get_site ( ) if site is None : return False return not cls . peers ( ) . descendant_of ( site . root_page ) . exists ( )
You can only create one of these pages per site .
239,373
def peers ( cls ) : contentType = ContentType . objects . get_for_model ( cls ) return cls . objects . filter ( content_type = contentType )
Return others of the same concrete type .
239,374
def _getEventsOnDay ( self , request , day ) : home = request . site . root_page return getAllEventsByDay ( request , day , day , home = home ) [ 0 ]
Return all the events in this site for a given day .
239,375
def _getEventsByDay ( self , request , firstDay , lastDay ) : home = request . site . root_page return getAllEventsByDay ( request , firstDay , lastDay , home = home )
Return the events in this site for the dates given grouped by day .
239,376
def _getEventsByWeek ( self , request , year , month ) : home = request . site . root_page return getAllEventsByWeek ( request , year , month , home = home )
Return the events in this site for the given month grouped by week .
239,377
def _getUpcomingEvents ( self , request ) : home = request . site . root_page return getAllUpcomingEvents ( request , home = home )
Return the upcoming events in this site .
239,378
def _getPastEvents ( self , request ) : home = request . site . root_page return getAllPastEvents ( request , home = home )
Return the past events in this site .
239,379
def _getEventFromUid ( self , request , uid ) : event = getEventFromUid ( request , uid ) home = request . site . root_page if event . get_ancestors ( ) . filter ( id = home . id ) . exists ( ) : return event
Try and find an event with the given UID in this site .
239,380
def _getAllEvents ( self , request ) : home = request . site . root_page return getAllEvents ( request , home = home )
Return all the events in this site .
239,381
def _getEventsOnDay ( self , request , day ) : return getAllEventsByDay ( request , day , day , home = self ) [ 0 ]
Return my child events for a given day .
239,382
def _getEventsByDay ( self , request , firstDay , lastDay ) : return getAllEventsByDay ( request , firstDay , lastDay , home = self )
Return my child events for the dates given grouped by day .
239,383
def _getEventsByWeek ( self , request , year , month ) : return getAllEventsByWeek ( request , year , month , home = self )
Return my child events for the given month grouped by week .
239,384
def _getEventFromUid ( self , request , uid ) : event = getEventFromUid ( request , uid ) if event . get_ancestors ( ) . filter ( id = self . id ) . exists ( ) : return event
Try and find a child event with the given UID .
239,385
def events_this_week ( context ) : request = context [ 'request' ] home = request . site . root_page cal = CalendarPage . objects . live ( ) . descendant_of ( home ) . first ( ) calUrl = cal . get_url ( request ) if cal else None calName = cal . title if cal else None today = dt . date . today ( ) beginOrd = today . to...
Displays a week s worth of events . Starts week with Monday unless today is Sunday .
239,386
def minicalendar ( context ) : today = dt . date . today ( ) request = context [ 'request' ] home = request . site . root_page cal = CalendarPage . objects . live ( ) . descendant_of ( home ) . first ( ) calUrl = cal . get_url ( request ) if cal else None if cal : events = cal . _getEventsByWeek ( request , today . yea...
Displays a little ajax version of the calendar .
239,387
def subsite_upcoming_events ( context ) : request = context [ 'request' ] home = request . site . root_page return { 'request' : request , 'events' : getAllUpcomingEvents ( request , home = home ) }
Displays a list of all upcoming events in this site .
239,388
def group_upcoming_events ( context , group = None ) : request = context . get ( 'request' ) if group is None : group = context . get ( 'page' ) if group : events = getGroupUpcomingEvents ( request , group ) else : events = [ ] return { 'request' : request , 'events' : events }
Displays a list of all upcoming events that are assigned to a specific group . If the group is not specified it is assumed to be the current page .
239,389
def next_on ( context , rrevent = None ) : request = context [ 'request' ] if rrevent is None : rrevent = context . get ( 'page' ) eventNextOn = getattr ( rrevent , '_nextOn' , lambda _ : None ) return eventNextOn ( request )
Displays when the next occurence of a recurring event will be . If the recurring event is not specified it is assumed to be the current page .
239,390
def location_gmap ( context , location ) : gmapq = None if getattr ( MapFieldPanel , "UsingWagtailGMaps" , False ) : gmapq = location return { 'gmapq' : gmapq }
Display a link to Google maps iff we are using WagtailGMaps
239,391
def getGroupUpcomingEvents ( request , group ) : rrEvents = RecurringEventPage . events ( request ) . exclude ( group_page = group ) . upcoming ( ) . child_of ( group ) . this ( ) qrys = [ SimpleEventPage . events ( request ) . exclude ( group_page = group ) . upcoming ( ) . child_of ( group ) . this ( ) , MultidayEven...
Return all the upcoming events that are assigned to the specified group .
239,392
def group ( self ) : retval = None parent = self . get_parent ( ) Group = get_group_model ( ) if issubclass ( parent . specific_class , Group ) : retval = parent . specific if retval is None : retval = self . group_page return retval
The group this event belongs to . Adding the event as a child of a group automatically assigns the event to that group .
239,393
def isAuthorized ( self , request ) : restrictions = self . get_view_restrictions ( ) if restrictions and request is None : return False else : return all ( restriction . accept_request ( request ) for restriction in restrictions )
Is the user authorized for the requested action with this event?
239,394
def _upcoming_datetime_from ( self ) : nextDt = self . __localAfter ( timezone . localtime ( ) , dt . time . max , excludeCancellations = True , excludeExtraInfo = True ) return nextDt
The datetime this event next starts in the local time zone or None if it is finished .
239,395
def _past_datetime_from ( self ) : prevDt = self . __localBefore ( timezone . localtime ( ) , dt . time . max , excludeCancellations = True , excludeExtraInfo = True ) return prevDt
The datetime this event previously started in the local time zone or None if it never did .
239,396
def _first_datetime_from ( self ) : myFromDt = self . _getMyFirstDatetimeFrom ( ) localTZ = timezone . get_current_timezone ( ) return myFromDt . astimezone ( localTZ )
The datetime this event first started in the local time zone or None if it never did .
239,397
def _getFromTime ( self , atDate = None ) : if atDate is None : atDate = timezone . localdate ( timezone = self . tz ) return getLocalTime ( atDate , self . time_from , self . tz )
What was the time of this event? Due to time zones that depends what day we are talking about . If no day is given assume today .
239,398
def _getFromDt ( self ) : myNow = timezone . localtime ( timezone = self . tz ) return self . __after ( myNow ) or self . __before ( myNow )
Get the datetime of the next event after or before now .
239,399
def _futureExceptions ( self , request ) : retval = [ ] myToday = timezone . localdate ( timezone = self . tz ) for extraInfo in ExtraInfoPage . events ( request ) . child_of ( self ) . filter ( except_date__gte = myToday ) : retval . append ( extraInfo ) for cancellation in CancellationPage . events ( request ) . chil...
Returns all future extra info cancellations and postponements created for this recurring event