Skip to content

Commit

Permalink
Finally getting around to adding gittip support.
Browse files Browse the repository at this point in the history
Fixes: #43
  • Loading branch information
Robert Myers committed Jan 23, 2013
1 parent a87c77d commit 35e6e6c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
19 changes: 19 additions & 0 deletions july/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ def add_auth_id(self, auth_str):
provider, uid = auth_str.split(':')
UserSocialAuth.create_social_auth(self, uid, provider)

def get_provider(self, provider):
"""Return the uid of the provider or None if not set."""
try:
return self.social_auth.filter(provider=provider).get()
except UserSocialAuth.DoesNotExist:
return None

@property
def gittip(self):
return self.get_provider('gittip')

@property
def twitter(self):
return self.get_provider('twitter')

@property
def github(self):
return self.get_provider('github')

@classmethod
def get_by_auth_id(cls, auth_str):
"""
Expand Down
28 changes: 27 additions & 1 deletion july/people/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ class EditUserForm(forms.Form):
'data-bind':'typeahead: $data.filterTeam'
}))

gittip = forms.CharField(
label=ugettext_lazy("Gittip Username"), required=False)

email = forms.EmailField(
label=ugettext_lazy("Add Email Address"), required=False)

def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
self.emails = set([])
self._gittip = None
super(EditUserForm, self).__init__(*args, **kwargs)
if self.user:
self.fields['first_name'].initial=self.user.first_name
Expand All @@ -100,12 +104,15 @@ def __init__(self, *args, **kwargs):
# initialize the emails
for auth in self.user.social_auth.filter(provider="email"):
self.emails.add(auth.uid)
self._gittip = self.user.get_provider("gittip")
if self._gittip:
self.fields['gittip'].initial = self._gittip.uid

def clean_location(self):
location = self.data.get('location', '')
try:
l = Location.objects.get(slug=slugify(location))
except Location.DoesNotExist as ex:
except Location.DoesNotExist:
l = Location.objects.create(name=location, slug=slugify(location), total=0)
return l

Expand All @@ -117,6 +124,25 @@ def clean_team(self):
t = Team.objects.create(slug=slugify(team), name=team, total=0)
return t

def clean_gittip(self):
uid = self.cleaned_data['gittip']
if not uid:
return None
if self._gittip is not None:
self._gittip.uid = uid
self._gittip.save()
return uid
else:
try:
self.user.add_auth_id('gittip:%s' % uid)
except:
error_msg = ugettext_lazy(
"This gittip username is already in use, if this is not"
" right please email [email protected]"
)
raise forms.ValidationError(error_msg)
return uid

def clean_email(self):
email = self.cleaned_data['email']
if not email:
Expand Down
7 changes: 5 additions & 2 deletions july/templates/july/user_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="media-body">
<h2 class="media-heading">{{ profile }}
{% if profile.twitter %}
<a href="https://twitter.com/{{ profile.twitter }}" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">{% trans "Follow" %}</a>
<a href="https://twitter.com/{{ profile.twitter.uid }}" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">{% trans "Follow" %}</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
{% endif %}
<small class="points pull-right">
Expand All @@ -26,7 +26,7 @@ <h2 class="media-heading">{{ profile }}
<p class="about-me">{% if profile.description %}{{ profile.description }}{% else %}{% trans "Python Hacker" %}{% endif %}</p>
<ul class="nav nav-pills">
{% if profile.github %}
<li><i class="icon-globe"></i> <a href="http://github.com/{{ profile.github }}">{% trans "Follow on Github" %}</a></li>
<li><a href="http://github.com/{{ profile.github.uid }}"><i class="icon-globe"></i> {% trans "Follow on Github" %}</a></li>
{% endif %}
{% if profile.url %}
<li><a href="{{ profile.url }}"><i class="icon-globe"></i> {{profile.url}}</a></li>
Expand All @@ -37,6 +37,9 @@ <h2 class="media-heading">{{ profile }}
{% if profile.team %}
<li><a href="{% url 'team-details' profile.team.slug %}"><i class="icon-th"></i> {{ profile.team.name }}</a></li>
{% endif %}
{% if profile.gittip %}
<iframe style="position: relative; top: 9px; left: 5px; border: 0; margin: 0; padding: 0;" src="https://www.gittip.com/{{ profile.gittip.uid }}/widget.html" width="48pt" height="22pt"></iframe>
{% endif %}
</ul>
</div>
<ul class="nav nav-tabs">
Expand Down

0 comments on commit 35e6e6c

Please sign in to comment.