Decoupled the "reddit" application from the main program

This commit is contained in:
2010-12-20 12:17:14 +00:00
parent 0aef422d9a
commit cc4f986edb
15 changed files with 113 additions and 103 deletions

View File

@@ -4,6 +4,7 @@ from django.contrib.auth.models import User
from eve_api.models import EVEPlayerCharacter, EVEPlayerCorporation
from hr.app_defines import *
from utils import installed
class Application(models.Model):
""" Person's application to a corporation """
@@ -38,9 +39,10 @@ class Application(models.Model):
bl_items = Blacklist.objects.filter(models.Q(expiry_date__gt=datetime.now()) | models.Q(expiry_date=None))
# Check Reddit blacklists
reddit_uids = self.user.redditaccount_set.all().values_list('username', flat=True)
objs = bl_items.filter(type=BLACKLIST_TYPE_REDDIT, value__in=reddit_uids)
blacklist.extend(objs)
if installed('reddit'):
reddit_uids = self.user.redditaccount_set.all().values_list('username', flat=True)
objs = bl_items.filter(type=BLACKLIST_TYPE_REDDIT, value__in=reddit_uids)
blacklist.extend(objs)
# Check email blacklists
blacklist.extend(bl_items.filter(type=BLACKLIST_TYPE_EMAIL, value=self.user.email.lower()))

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
from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerCharacter
from reddit.models import RedditAccount
from hr.forms import CreateRecommendationForm, CreateApplicationForm, NoteForm
from hr.models import Recommendation, Application, Audit
from app_defines import *
@@ -28,9 +29,9 @@ def send_message(application, message_type, note=None):
except:
pass
if len(application.user.redditaccount_set.all()) > 0:
from reddit.tasks import send_reddit_message
send_reddit_message.delay(to=application.user.redditaccount_set.all()[0].username, subject=subject, message=message)
if installed('reddit') and len(application.user.redditaccount_set.all()) > 0:
from reddit.tasks import send_reddit_message
send_reddit_message.delay(to=application.user.redditaccount_set.all()[0].username, subject=subject, message=message)
def check_permissions(user, application=None):
@@ -87,7 +88,7 @@ def view_application(request, applicationid):
else:
return HttpResponseRedirect(reverse('hr.views.index'))
if request.GET.has_key('redditxhr') and request.is_ajax():
if installed('reddit') and request.GET.has_key('redditxhr') and request.is_ajax():
posts = []
for acc in app.user.redditaccount_set.all():
try: