1
0
mirror of https://github.com/djohnlewis/stackdump synced 2024-12-04 23:17:37 +00:00

Stackdump now handles cases where the user has been deleted and does not exist anymore.

This commit is contained in:
Samuel Lai 2012-08-07 22:07:22 +10:00
parent b1a5977012
commit 7d6bace28a
4 changed files with 29 additions and 22 deletions

View File

@ -264,7 +264,7 @@ class PostContentHandler(xml.sax.ContentHandler):
d['body'] = attrs.get('Body', '')
d['ownerUserId'] = int(attrs.get('OwnerUserId', 0))
if 'LastEditorUserId' in attrs:
d['lastEditorUserId'] = int(attrs.get('LastEditorUserId', ''))
d['lastEditorUserId'] = int(attrs.get('LastEditorUserId', 0))
if 'LastEditDate' in attrs:
d['lastEditDate'] = datetime.strptime(attrs.get('LastEditDate'), ISO_DATE_FORMAT)
d['lastActivityDate'] = datetime.strptime(attrs.get('LastActivityDate'), ISO_DATE_FORMAT)

View File

@ -0,0 +1,18 @@
{% macro user_card(user) %}
<div class="user-card">
{% if user == None %}
<p class="user-name"><em title="This user account has since been deleted from the site.">Anonymous User</em></p>
{% else %}
<p class="user-rep">{{ user.reputation }}</p>
<p class="user-name">{{ user.displayName }}</p>
{% endif %}
</div>
{% endmacro %}
{% macro user_name(user) %}
{% if user == None %}
<em title="This user account has since been deleted from the site.">Anonymous User</em>
{% else %}
{{ user.displayName }}
{% endif %}
{% endmacro %}

View File

@ -1,3 +1,5 @@
{% import 'common.macros' as macros %}
{% if results|length == 0 %}
<p><em>No questions or answers found for your query.</em></p>
{% if site and sites|list|length > 1 %}
@ -34,7 +36,7 @@
<h3><a href="{{ SETTINGS.APP_URL_ROOT }}{{ r.site.key }}/{{ r.id }}">{{ r.question.title }}</a></h3>
<p>{{ r.question.body|striptags|truncate(256) }}</p>
<p class="post-details">
Asked by <strong>{{ r.question.ownerUser.displayName }}</strong> on
Asked by <strong>{{ macros.user_name(r.question.ownerUser) }}</strong> on
<strong>{{ r.question.creationDate|format_datetime }}</strong>.
</p>
<div class="post-tags">

View File

@ -1,4 +1,5 @@
{% extends 'base.html' %}
{% import 'common.macros' as macros %}
{% block title %}Stackdump // {{ site.name }} // {{ result.question.title }}{% endblock %}
@ -41,20 +42,13 @@
<div class="post-metadata">
<div class="post-user">
<p>asked on <strong>{{ r.question.creationDate|format_datetime }}</strong></p>
<div class="user-card">
<p class="user-rep">{{ r.question.ownerUser.reputation }}</p>
<p class="user-name">{{ r.question.ownerUser.displayName }}</p>
</div>
{{ macros.user_card(r.question.ownerUser) }}
</div>
{% if r.question.lastEditorUser %}
<div class="post-user">
<p>last edited <strong>{{ r.question.lastActivityDate|format_datetime }}</strong></p>
<div class="user-card">
<p class="user-rep">{{ r.question.lastEditorUser.reputation }}</p>
<p class="user-name">{{ r.question.lastEditorUser.displayName }}</p>
</div>
{{ macros.user_card(r.question.lastEditorUser) }}
</div>
{% endif %}
<div class="post-tags">
@ -74,7 +68,7 @@
<p class="post-comment-text">
{{ c.text }} &mdash;
<span class="post-comment-metadata">
<strong>{{ c.user.displayName }}</strong> on
<strong>{{ macros.user_name(c.user) }}</strong> on
<strong>{{ c.creationDate|format_datetime }}</strong>
</span>
</p>
@ -114,20 +108,13 @@
<div class="post-metadata">
<div class="post-user">
<p>answered on <strong>{{ a.creationDate|format_datetime }}</strong></p>
<div class="user-card">
<p class="user-rep">{{ a.ownerUser.reputation }}</p>
<p class="user-name">{{ a.ownerUser.displayName }}</p>
</div>
{{ macros.user_card(a.ownerUser) }}
</div>
{% if a.lastEditorUser %}
<div class="post-user">
<p>last edited <strong>{{ a.lastEditDate|format_datetime }}</strong></p>
<div class="user-card">
<p class="user-rep">{{ a.lastEditorUser.reputation }}</p>
<p class="user-name">{{ a.lastEditorUser.displayName }}</p>
</div>
{{ macros.user_card(a.lastEditorUser) }}
</div>
{% endif %}
<div class="post-tags">
@ -148,7 +135,7 @@
<p class="post-comment-text">
{{ c.text }} &mdash;
<span class="post-comment-metadata">
<strong>{{ c.user.displayName }}</strong> on
<strong>{{ macros.user_name(c.user) }}</strong> on
<strong>{{ c.creationDate|format_datetime }}</strong>
</span>
</p>