def author_links(self): """ Basically finds all full names for all the referenced authors. (lookup for all full names in just *one* query) """ if not self.authors: return [] return userdb.full_names(self.authors)
def __init__(self, ID, template_kwargs=None, data=None, editing=False, showing=False, saving=False, renaming=False, allow_deleted=False, timestamp=None): self.template_kwargs = template_kwargs or {} self.id = ID #given that we cache it's existence it is quicker to check for existence if data is None: if self.exists(allow_deleted=allow_deleted): if editing: # as we want to make edits on the most recent version timestamp = None data = knowldb.get_knowl(ID, allow_deleted=allow_deleted, timestamp=timestamp) else: data = {} self.title = data.get('title', '') self.content = data.get('content', '') self.status = data.get('status', 0) self.quality = reverse_status_code.get(self.status) self.authors = data.get('authors', []) # Because category is different from cat, the category will be recomputed when copying knowls. self.category = data.get('cat', extract_cat(ID)) self._last_author = data.get('last_author', data.get('_last_author', '')) self.timestamp = data.get('timestamp', datetime.utcnow()) self.ms_timestamp = datetime_to_timestamp_in_ms(self.timestamp) self.links = data.get('links', []) self.defines = data.get('defines', []) self.source = data.get('source') self.source_name = data.get('source_name') self.type = data.get('type') self.editing = editing # We need to have the source available on comments being created if self.type is None: self.type, self.source, self.source_name = extract_typ(ID) if self.type == 2: pieces = ID.split(".") # Ignore the title passed in self.title = f"Column {pieces[2]} of table {pieces[1]}" from lmfdb import db if pieces[1] in db.tablenames: self.coltype = db[pieces[1]].col_type.get(pieces[2], "DEFUNCT") else: self.coltype = "DEFUNCT" #self.reviewer = data.get('reviewer') # Not returned by get_knowl by default #self.review_timestamp = data.get('review_timestamp') # Not returned by get_knowl by default if showing: self.comments = knowldb.get_comments(ID) if self.type == 0: self.referrers = knowldb.ids_referencing(ID) self.code_referrers = [ code_snippet_knowl(D) for D in knowldb.code_references(self) ] if saving: self.sed_safety = knowldb.check_sed_safety(ID) self.reviewed_content = self.reviewed_title = self.reviewed_timestamp = None if renaming: # This should only occur on beta, so we get the most recent reviewed version reviewed_data = knowldb.get_knowl( ID, ['content', 'title', 'timestamp', 'status'], beta=False) if reviewed_data and reviewed_data['status'] == 1: self.reviewed_content = reviewed_data['content'] self.reviewed_title = reviewed_data['title'] self.reviewed_timestamp = reviewed_data['timestamp'] if editing: self.all_defines = { k: v for k, v in knowldb.all_defines.items() if len(k) > 3 and k not in common_words and ID not in v } if showing or editing: self.edit_history = knowldb.get_edit_history(ID) # Use to determine whether this is the most recent version of this knowl. self.most_recent = not self.edit_history or self.edit_history[-1][ 'timestamp'] == self.timestamp #if not self.edit_history: # # New knowl. This block should be edited according to the desired behavior for diffs # self.edit_history = [{"timestamp":datetime.utcnow(), # "last_author":"__nobody__", # "content":"", # "status":0}] uids = [elt['last_author'] for elt in self.edit_history] if uids: full_names = dict([(elt['username'], elt['full_name']) for elt in userdb.full_names(uids)]) else: full_names = dict({}) self.previous_review_spot = None for i, elt in enumerate(self.edit_history): elt['ms_timestamp'] = datetime_to_timestamp_in_ms( elt['timestamp']) elt['author_full_name'] = full_names.get( elt['last_author'], "") if elt['status'] == 1 and i != len(self.edit_history) - 1: self.previous_review_spot = elt['ms_timestamp']
def __init__(self, ID, template_kwargs=None, data=None, editing=False, showing=False, saving=False, renaming=False, allow_deleted=False, timestamp=None): self.template_kwargs = template_kwargs or {} self.id = ID #given that we cache it's existence it is quicker to check for existence if data is None: if self.exists(allow_deleted=allow_deleted): if editing: # as we want to make edits on the most recent version timestamp=None data = knowldb.get_knowl(ID, allow_deleted=allow_deleted, timestamp=timestamp) else: data = {} self.title = data.get('title', '') self.content = data.get('content', '') self.status = data.get('status', 0) self.quality = reverse_status_code.get(self.status) self.authors = data.get('authors', []) # Because category is different from cat, the category will be recomputed when copying knowls. self.category = data.get('cat', extract_cat(ID)) self._last_author = data.get('last_author', data.get('_last_author', '')) self.timestamp = data.get('timestamp', datetime.utcnow()) self.ms_timestamp = datetime_to_timestamp_in_ms(self.timestamp) self.links = data.get('links', []) self.defines = data.get('defines', []) self.source = data.get('source') self.source_name = data.get('source_name') self.type = data.get('type') self.editing = editing # We need to have the source available on comments being created if self.type is None: match = comment_knowl_re.match(ID) if match: self.source = match.group(1) self.type = -2 elif top_knowl_re.match(ID): self.type = 1 elif bottom_knowl_re.match(ID): self.type = -1 else: self.type = 0 #self.reviewer = data.get('reviewer') # Not returned by get_knowl by default #self.review_timestamp = data.get('review_timestamp') # Not returned by get_knowl by default if showing: self.comments = knowldb.get_comments(ID) if self.type == 0: self.referrers = knowldb.ids_referencing(ID) self.code_referrers = [code_snippet_knowl(D) for D in knowldb.code_references(self)] if saving: self.sed_safety = knowldb.check_sed_safety(ID) self.reviewed_content = self.reviewed_title = self.reviewed_timestamp = None if renaming: # This should only occur on beta, so we get the most recent reviewed version reviewed_data = knowldb.get_knowl(ID, ['content', 'title', 'timestamp', 'status'], beta=False) if reviewed_data and reviewed_data['status'] == 1: self.reviewed_content = reviewed_data['content'] self.reviewed_title = reviewed_data['title'] self.reviewed_timestamp = reviewed_data['timestamp'] if editing: self.all_defines = {k:v for k,v in knowldb.all_defines.items() if len(k) > 3 and k not in common_words and ID not in v} if showing or editing: self.edit_history = knowldb.get_edit_history(ID) # Use to determine whether this is the most recent version of this knowl. self.most_recent = not self.edit_history or self.edit_history[-1]['timestamp'] == self.timestamp #if not self.edit_history: # # New knowl. This block should be edited according to the desired behavior for diffs # self.edit_history = [{"timestamp":datetime.utcnow(), # "last_author":"__nobody__", # "content":"", # "status":0}] uids = [ elt['last_author'] for elt in self.edit_history] if uids: full_names = dict([ (elt['username'], elt['full_name']) for elt in userdb.full_names(uids)]) else: full_names = dict({}) self.previous_review_spot = None for i, elt in enumerate(self.edit_history): elt['ms_timestamp'] = datetime_to_timestamp_in_ms(elt['timestamp']) elt['author_full_name'] = full_names.get(elt['last_author'], "") if elt['status'] == 1 and i != len(self.edit_history) - 1: self.previous_review_spot = elt['ms_timestamp']