mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 00:07:57 -05:00
wiki: Properly render revision user.
This commit is contained in:
@@ -86,10 +86,10 @@ class WikiController(RedditController):
|
||||
return self.redirect(url)
|
||||
|
||||
if version:
|
||||
edit_by = version.author_name()
|
||||
edit_by = version.get_author()
|
||||
edit_date = version.date
|
||||
else:
|
||||
edit_by = page.author_name()
|
||||
edit_by = page.get_author()
|
||||
edit_date = page._get('last_edit_date')
|
||||
|
||||
diffcontent = None
|
||||
|
||||
@@ -599,16 +599,19 @@ class WikiSettingsJsonTemplate(ThingJsonTemplate):
|
||||
class WikiViewJsonTemplate(ThingJsonTemplate):
|
||||
def render(self, thing, *a, **kw):
|
||||
edit_date = time.mktime(thing.edit_date.timetuple()) if thing.edit_date else None
|
||||
edit_by = Wrapped(thing.edit_by).render() if thing.edit_by else None
|
||||
return ObjectTemplate(dict(content_md=thing.page_content_md,
|
||||
content_html=wikimarkdown(thing.page_content_md),
|
||||
revision_by=thing.edit_by,
|
||||
revision_by=edit_by,
|
||||
revision_date=edit_date,
|
||||
may_revise=thing.may_revise))
|
||||
|
||||
class WikiRevisionJsonTemplate(ThingJsonTemplate):
|
||||
def render(self, thing, *a, **kw):
|
||||
timestamp = time.mktime(thing.date.timetuple()) if thing.date else None
|
||||
return ObjectTemplate(dict(author=thing._get('author'),
|
||||
author = thing.get_author()
|
||||
author = Wrapped(author).render() if author else None
|
||||
return ObjectTemplate(dict(author=author,
|
||||
id=str(thing._id),
|
||||
timestamp=timestamp,
|
||||
reason=thing._get('reason'),
|
||||
|
||||
@@ -69,14 +69,6 @@ class WikiPageEditors(tdb_cassandra.View):
|
||||
_value_type = 'str'
|
||||
_connection_pool = 'main'
|
||||
|
||||
def get_author_name(author_name):
|
||||
if not author_name:
|
||||
return "[unknown]"
|
||||
try:
|
||||
return Account._by_name(author_name).name
|
||||
except NotFound:
|
||||
return '[deleted]'
|
||||
|
||||
class WikiRevision(tdb_cassandra.UuidThing, Printable):
|
||||
""" Contains content (markdown), author of the edit, page the edit belongs to, and datetime of the edit """
|
||||
|
||||
@@ -88,14 +80,21 @@ class WikiRevision(tdb_cassandra.UuidThing, Printable):
|
||||
|
||||
cache_ignore = set(list(_str_props)).union(Printable.cache_ignore)
|
||||
|
||||
def author_name(self):
|
||||
return get_author_name(self._get('author', None))
|
||||
def get_author(self):
|
||||
author = self._get('author')
|
||||
return Account._by_name(author, allow_deleted=True) if author else None
|
||||
|
||||
@classmethod
|
||||
def add_props(cls, user, wrapped):
|
||||
from r2.lib.pages import WrappedUser
|
||||
for item in wrapped:
|
||||
item._hidden = item.is_hidden
|
||||
item._spam = False
|
||||
author = item.get_author()
|
||||
if author is None:
|
||||
item.printable_author = '[unknown]'
|
||||
else:
|
||||
item.printable_author = WrappedUser(author)
|
||||
item.reported = False
|
||||
|
||||
@classmethod
|
||||
@@ -168,8 +167,10 @@ class WikiPage(tdb_cassandra.Thing):
|
||||
_int_props = ('permlevel')
|
||||
_bool_props = ('listed_')
|
||||
|
||||
def author_name(self):
|
||||
return get_author_name(getattr(self, 'last_edit_by', None))
|
||||
def get_author(self):
|
||||
if self._get('last_edit_by'):
|
||||
return Account._by_name(self.last_edit_by, allow_deleted=True)
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get(cls, sr, name):
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
</td>
|
||||
|
||||
<td>
|
||||
${thing.author_name()}
|
||||
${thing.printable_author}
|
||||
</td>
|
||||
|
||||
<td style="font-style: italic;">
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<item>
|
||||
<title>${thing._id}</title>
|
||||
<link>http://${get_domain(subreddit=False)}/${c.wiki_base_url}/${thing.page}?v=${thing._id}</link>
|
||||
<author>${thing._get('author', 'Unknown')}</author>
|
||||
<author>${thing.printable_author}</author>
|
||||
<category>${thing.sr}/${thing.page}</category>
|
||||
<description>${thing._get('reason')}</description>
|
||||
<pubdate>${thing.date}</pubdate>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
<%!
|
||||
from r2.lib.filters import wikimarkdown
|
||||
from r2.lib.pages import WrappedUser
|
||||
%>
|
||||
|
||||
%if thing.diff:
|
||||
@@ -41,7 +42,10 @@
|
||||
%if thing.edit_date:
|
||||
<hr/>
|
||||
<em>
|
||||
${_("revision by %s") % thing.edit_by}
|
||||
— ${timestamp(thing.edit_date)} ago
|
||||
%if thing.edit_by:
|
||||
${unsafe(_("revision by %s") % WrappedUser(thing.edit_by).render())}
|
||||
—
|
||||
%endif
|
||||
${unsafe("%(time)s ago" % dict(time=timestamp(thing.edit_date)))}
|
||||
</em>
|
||||
%endif
|
||||
|
||||
Reference in New Issue
Block a user