Flesh out and enable the Reddit gargoyle switch

This commit is contained in:
2011-08-26 13:36:34 +01:00
parent 6d8f491326
commit 2428987e53
7 changed files with 30 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
{% load if_extra %}
{% load installed %}
{% load naturaltimediff %}
{% load gargoyle_tags %}
{% block title %}View Application{% endblock %}
@@ -128,6 +129,7 @@
{% endfor %}
</table>
{% if "reddit"|installed %}
{% ifswitch reddit %}
{% if app.user.redditaccount_set.all %}
<h3>Reddit Accounts</h3>
<table>
@@ -193,6 +195,7 @@ function handleResponse() {
<div id="redditposts">
</div>
{% endif %}
{% endifswitch %}
{% endif %}
{% endif %}
{% endblock %}

View File

@@ -10,8 +10,9 @@ from django.template import RequestContext
from django.template.loader import render_to_string
from django.conf import settings
from utils import installed, blacklist_values
from gargoyle import gargoyle
from utils import installed, blacklist_values
from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerCharacter
from hr.forms import CreateRecommendationForm, CreateApplicationForm, NoteForm, BlacklistUserForm, AdminNoteForm
from hr.models import Recommendation, Application, Audit, Blacklist, BlacklistSource
@@ -95,7 +96,7 @@ def view_application(request, applicationid):
# Respond to Reddit Comment Load
# TODO: Move to reddit app?
if installed('reddit') and request.GET.has_key('redditxhr') and request.is_ajax():
if installed('reddit') and gargoyle.is_active('reddit', request) and request.GET.has_key('redditxhr') and request.is_ajax():
posts = []
for acc in app.user.redditaccount_set.all():
try:
@@ -330,8 +331,9 @@ def blacklist_user(request, userid):
for ea in u.eveaccount_set.all():
blacklist_item(BLACKLIST_TYPE_APIUSERID, ea.api_user_id)
for ra in u.redditaccount_set.all():
blacklist_item(BLACKLIST_TYPE_REDDIT, ra.username)
if installed('reddit'):
for ra in u.redditaccount_set.all():
blacklist_item(BLACKLIST_TYPE_REDDIT, ra.username)
for char in EVEPlayerCharacter.objects.filter(eveaccount__user=u):
blacklist_item(BLACKLIST_TYPE_CHARACTER, char.name)

View File

@@ -3,10 +3,13 @@ from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from django.contrib import messages
from gargoyle.decorators import switch_is_active
from reddit.forms import RedditAccountForm
from reddit.models import RedditAccount
@login_required
@switch_is_active('reddit')
def reddit_add(request):
""" Add a Reddit account to a user's account """
@@ -32,6 +35,7 @@ def reddit_add(request):
return render_to_response('reddit/add_reddit_account.html', locals(), context_instance=RequestContext(request))
@login_required
@switch_is_active('reddit')
def reddit_del(request, redditid=0):
""" Delete a Reddit account from a user's account """

View File

@@ -4,6 +4,8 @@ from django import forms
from django.contrib.auth.models import User
from django.conf import settings
from gargoyle import gargoyle
from utils import installed
from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation
@@ -92,12 +94,13 @@ class UserLookupForm(forms.Form):
""" User Lookup Form """
def __init__(self, *args, **kwargs):
request = kwargs.pop('request', None)
super(UserLookupForm, self).__init__(*args, **kwargs)
choices = [(1, "Auth Username"),
(2, "Character"),
(4, "Email Address"),
(5, "EVE API User ID"), ]
if installed('reddit'):
if installed('reddit') and gargoyle.is_active('reddit', request):
choices.append((3, "Reddit ID"))
self.fields['type'] = forms.ChoiceField(label=u'Search type', choices=choices)

View File

@@ -2,6 +2,7 @@
{% load naturaltimediff %}
{% load installed %}
{% load gargoyle_tags %}
{% block content %}
@@ -108,6 +109,7 @@
{% endif %}
{% if "reddit"|installed %}
{% ifswitch reddit %}
<br/>
<h2>Reddit Accounts</h2>
{% if user.redditaccount_set.all %}
@@ -125,6 +127,7 @@
</tbody>
</table>
{% endif %}
{% endifswitch %}
{% endif %}
{% endblock %}

View File

@@ -2,6 +2,7 @@
{% load naturaltimediff %}
{% load installed %}
{% load gargoyle_tags %}
{% block title %}Your Profile{% endblock %}
@@ -125,6 +126,7 @@ setup.</p>
<br/>
{% if "reddit"|installed %}
{% ifswitch reddit %}
<h2>Reddit Accounts</h2>
<p>This is a list of all your current linked Reddit accounts</p>
{% if user.redditaccount_set.all %}
@@ -144,6 +146,7 @@ setup.</p>
</p>
<p>
Reddit account tagging is {% if user.get_profile.tag_reddit_accounts %}Enabled{% else %}Disabled{% endif %}. <a href="{% url sso.views.toggle_reddit_tagging %}">{% if user.get_profile.tag_reddit_accounts %}Disable{% else %}Enable{% endif %}</a>
{% endifswitch %}
{% endif %}
{% endblock %}

View File

@@ -14,15 +14,14 @@ from django.template import RequestContext
from django.core import serializers
from django.conf import settings
from utils import installed
from gargoyle import gargoyle
from gargoyle.decorators import switch_is_active
from utils import installed
from eve_api.models import EVEAccount, EVEPlayerCharacter
from eve_api.tasks import import_apikey, import_apikey_result, update_user_access
from eve_proxy.models import ApiAccessLog
from reddit.tasks import update_user_flair
from sso.models import ServiceAccount, Service, SSOUser, ExistingUser, ServiceError
from sso.forms import UserServiceAccountForm, ServiceAccountResetForm, UserLookupForm, APIPasswordForm, EmailChangeForm, PrimaryCharacterForm
@@ -182,13 +181,13 @@ def user_view(request, username, template='sso/lookup/user.html'):
def user_lookup(request):
""" Lookup a user's account by providing a matching criteria """
form = UserLookupForm()
form = UserLookupForm(request=request)
if not request.user.has_perm('sso.can_search_users'):
return redirect('sso.views.profile')
if request.method == 'POST':
form = UserLookupForm(request.POST)
form = UserLookupForm(request.POST, request=request)
if form.is_valid():
users = None
uids = []
@@ -200,7 +199,7 @@ def user_lookup(request):
for u in uid:
uids.append(u['user'])
users = User.objects.filter(id__in=uids).only('username')
elif installed('reddit') and form.cleaned_data['type'] == '3':
elif installed('reddit') and gargoyle.is_active('reddit', request) and form.cleaned_data['type'] == '3':
from reddit.models import RedditAccount
uid = RedditAccount.objects.filter(username__icontains=username).values('user')
for u in uid:
@@ -291,6 +290,7 @@ def primarychar_change(request):
@login_required
@switch_is_active('reddit')
def toggle_reddit_tagging(request):
profile = request.user.get_profile()
if profile.primary_character: