Commit 518baa69 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added support for storing peoplefinder names (helps with moderation)

parent c4dd0be8
......@@ -48,6 +48,11 @@ def create_user(tree):
print "world"
user.save()
new_student = Student.objects.create(user=user)
# save the name off of peoplefinder for later quality assurance purposes
new_student.pf_first_name = user.first_name
new_student.pf_last_name = user.last_name
new_student.save()
print("Created user %s!" % username)
......@@ -12,10 +12,35 @@ class Student(TimeStampedModel):
# django user includes username, password, first name, and last name
user = models.OneToOneField(User)
pf_first_name = models.CharField(max_length=255, blank=True)
pf_last_name = models.CharField(max_length=255, blank=True)
slug = AutoSlugField(populate_from='user', unique=True)
emails_sent = models.PositiveIntegerField(default=0)
def has_nickname(self):
pf_name = "%s %s" % (self.pf_first_name, self.pf_last_name)
if (self.user.get_full_name() != pf_name) and (pf_name != " "):
return True
else:
return False
def get_nickname(self):
# different first name
if (self.user.first_name != self.pf_first_name) and (self.user.last_name == self.pf_last_name):
return "%s \"%s\" %s" % (self.pf_first_name, self.user.first_name, self.user.last_name)
# different last name
elif (self.user.first_name == self.pf_first_name) and (self.user.last_name != self.pf_last_name):
return "%s %s \"%s\"" % (self.user.first_name, self.pf_last_name, self.user.last_name)
# both
elif (self.user.first_name != self.pf_first_name) and (self.user.last_name != self.pf_last_name):
return "%s \"%s %s\" %s" % (self.pf_first_name, self.user.first_name, self.user.last_name, self.pf_last_name)
# failing gracefully
else:
return self.user.get_full_name()
def get_absolute_url(self):
return reverse('profile', kwargs={'slug': self.slug})
......
......@@ -30,7 +30,12 @@ SRCT Bookshare • Mod
{% widthratio student.emails_sent student.num_books 1 as ratio %}
<td>{{ ratio }}</td>
<td><a href="{{ student.get_absolute_url }}" target="_blank">
<strong>{{ student.user.get_full_name }}</strong> (<em>{{ student.user.username }}</em>)
{% if student.has_nickname %}
<strong>{{ student.get_nickname }}</strong>
{% else %}
<strong>{{ student.user.get_full_name }}</strong>
{% endif %}
(<em>{{ student.user.username }}</em>)
</a></td>
<td>
<a href="#">
......
......@@ -29,7 +29,11 @@ SRCT Bookshare &bull; Mod
<strong>{{ listing.title }}</strong>
</a></td>
<td><a href="{{ listing.poster.get_absolute_url }}" target="_blank">
{{ listing.poster.user.get_full_name }}
{% if listing.poster.has_nickname %}
{{ listing.poster.get_nickname }}
{% else %}
{{ listing.poster.user.get_full_name }}
{% endif %}
</a></td>
<td><a href="{% url 'delete_listing' listing.slug %}">
<span class="label label-danger"><strong>Delete</strong></span>
......
......@@ -25,7 +25,12 @@ SRCT Bookshare &bull; Mod
<tr>
<td>{{ student.num_books }}</td>
<td><a href="{{ student.get_absolute_url }}" target="_blank">
<strong>{{ student.user.get_full_name }}</strong> (<em>{{ student.user.username }}</em>)
{% if student.has_nickname %}
<strong>{{ student.get_nickname }}</strong>
{% else %}
<strong>{{ student.user.get_full_name }}</strong>
{% endif %}
(<em>{{ student.user.username }}</em>)
</a></td>
<td>
<a href="#">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment