2012-09-19 19:39:34 +02:00
|
|
|
from django.conf import settings
|
2012-08-28 18:44:51 +02:00
|
|
|
from django.contrib.auth import authenticate, login
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.core.urlresolvers import reverse
|
2012-09-07 19:41:47 +02:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
|
2012-08-28 18:44:51 +02:00
|
|
|
from django.shortcuts import render_to_response
|
|
|
|
from django.template import RequestContext
|
|
|
|
from django.shortcuts import render
|
2012-08-28 23:41:04 +02:00
|
|
|
from django.utils.timezone import utc
|
2012-08-28 18:44:51 +02:00
|
|
|
|
|
|
|
from django.contrib.auth.models import User
|
2012-08-30 19:56:15 +02:00
|
|
|
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Subscription, \
|
2012-09-21 16:40:46 +02:00
|
|
|
Recipient, get_display_recipient, get_huddle, Realm, UserMessage, \
|
|
|
|
create_user
|
2012-08-28 18:44:51 +02:00
|
|
|
from zephyr.forms import RegistrationForm
|
|
|
|
|
2012-08-28 22:56:21 +02:00
|
|
|
from zephyr.decorator import asynchronous
|
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
import datetime
|
|
|
|
import simplejson
|
2012-09-05 01:11:25 +02:00
|
|
|
import socket
|
2012-09-07 19:20:04 +02:00
|
|
|
import re
|
2012-09-17 20:25:00 +02:00
|
|
|
import markdown
|
2012-09-19 19:39:34 +02:00
|
|
|
import hashlib
|
2012-08-28 18:44:51 +02:00
|
|
|
|
2012-09-05 23:38:20 +02:00
|
|
|
def require_post(view_func):
|
|
|
|
def _wrapped_view_func(request, *args, **kwargs):
|
|
|
|
if request.method != "POST":
|
|
|
|
return HttpResponseBadRequest('This form can only be submitted by POST.')
|
|
|
|
return view_func(request, *args, **kwargs)
|
|
|
|
return _wrapped_view_func
|
|
|
|
|
2012-09-18 16:22:37 +02:00
|
|
|
def json_response(res_type="success", msg="", data={}, status=200):
|
|
|
|
content = {"result":res_type, "msg":msg}
|
|
|
|
content.update(data)
|
|
|
|
return HttpResponse(content=simplejson.dumps(content),
|
2012-09-05 22:21:25 +02:00
|
|
|
mimetype='application/json', status=status)
|
|
|
|
|
2012-09-18 16:22:37 +02:00
|
|
|
def json_success(data={}):
|
|
|
|
return json_response(data=data)
|
2012-09-05 22:21:25 +02:00
|
|
|
|
2012-09-18 16:22:37 +02:00
|
|
|
def json_error(msg, data={}):
|
|
|
|
return json_response(res_type="error", msg=msg, data=data, status=400)
|
2012-09-05 22:21:25 +02:00
|
|
|
|
2012-09-17 21:20:11 +02:00
|
|
|
def sanitize_identifier(x):
|
2012-09-21 00:26:59 +02:00
|
|
|
"""Sanitize an email, class name, etc."""
|
2012-09-17 21:20:11 +02:00
|
|
|
# We remove <> in order to avoid </script> within JSON embedded in HTML.
|
|
|
|
#
|
|
|
|
# FIXME: consider a whitelist
|
|
|
|
return x.replace('<','').replace('>','')
|
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
def register(request):
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = RegistrationForm(request.POST)
|
|
|
|
if form.is_valid():
|
2012-09-21 00:26:59 +02:00
|
|
|
email = sanitize_identifier(request.POST['email'])
|
2012-09-17 21:20:11 +02:00
|
|
|
password = request.POST['password']
|
|
|
|
full_name = sanitize_identifier(request.POST['full_name'])
|
|
|
|
short_name = sanitize_identifier(request.POST['short_name'])
|
|
|
|
email = sanitize_identifier(request.POST['email'])
|
|
|
|
domain = sanitize_identifier(request.POST['domain'])
|
2012-09-05 21:49:56 +02:00
|
|
|
realm = Realm.objects.filter(domain=domain)
|
|
|
|
if not realm:
|
|
|
|
realm = Realm(domain=domain)
|
2012-09-11 19:20:01 +02:00
|
|
|
realm.save()
|
2012-09-05 21:49:56 +02:00
|
|
|
else:
|
|
|
|
realm = Realm.objects.get(domain=domain)
|
2012-09-21 00:26:59 +02:00
|
|
|
# FIXME: sanitize email addresses
|
2012-09-21 16:40:46 +02:00
|
|
|
create_user(email, password, realm, full_name, short_name)
|
2012-09-21 16:10:36 +02:00
|
|
|
login(request, authenticate(username=email, password=password))
|
2012-08-28 18:44:51 +02:00
|
|
|
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
|
|
|
else:
|
|
|
|
form = RegistrationForm()
|
|
|
|
|
|
|
|
return render(request, 'zephyr/register.html', {
|
|
|
|
'form': form,
|
|
|
|
})
|
|
|
|
|
|
|
|
def accounts_home(request):
|
|
|
|
return render_to_response('zephyr/accounts_home.html',
|
2012-09-04 23:21:30 +02:00
|
|
|
context_instance=RequestContext(request))
|
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
def home(request):
|
|
|
|
if not request.user.is_authenticated():
|
|
|
|
return HttpResponseRedirect('accounts/home/')
|
2012-09-07 17:04:41 +02:00
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
2012-08-28 18:44:51 +02:00
|
|
|
|
2012-09-07 17:04:41 +02:00
|
|
|
zephyrs = [um.message for um in
|
|
|
|
UserMessage.objects.filter(user_profile=user_profile)]
|
2012-08-28 21:27:42 +02:00
|
|
|
|
|
|
|
if user_profile.pointer == -1 and zephyrs:
|
2012-08-28 18:44:51 +02:00
|
|
|
user_profile.pointer = min([zephyr.id for zephyr in zephyrs])
|
|
|
|
user_profile.save()
|
2012-09-12 22:55:37 +02:00
|
|
|
|
2012-08-30 19:56:15 +02:00
|
|
|
zephyr_json = simplejson.dumps([zephyr.to_dict() for zephyr in zephyrs])
|
2012-09-04 20:31:23 +02:00
|
|
|
|
2012-09-07 17:15:03 +02:00
|
|
|
# Populate personals autocomplete list based on everyone in your
|
|
|
|
# realm. Later we might want a 2-layer autocomplete, where we
|
|
|
|
# consider specially some sort of "buddy list" who e.g. you've
|
|
|
|
# talked to before, but for small organizations, the right list is
|
|
|
|
# everyone in your realm.
|
2012-09-21 00:26:59 +02:00
|
|
|
people = [profile.user.email for profile in
|
2012-09-07 17:26:58 +02:00
|
|
|
UserProfile.objects.filter(realm=user_profile.realm) if
|
|
|
|
profile != user_profile]
|
2012-09-04 20:31:23 +02:00
|
|
|
|
2012-09-05 22:15:38 +02:00
|
|
|
subscriptions = Subscription.objects.filter(userprofile_id=user_profile, active=True)
|
2012-09-07 17:26:58 +02:00
|
|
|
classes = [get_display_recipient(sub.recipient) for sub in subscriptions
|
2012-09-07 20:14:13 +02:00
|
|
|
if sub.recipient.type == Recipient.CLASS]
|
2012-09-05 22:15:38 +02:00
|
|
|
|
2012-09-07 17:26:58 +02:00
|
|
|
instances = list(set([zephyr.instance for zephyr in zephyrs
|
2012-09-07 20:14:13 +02:00
|
|
|
if zephyr.recipient.type == Recipient.CLASS]))
|
2012-09-04 20:31:23 +02:00
|
|
|
|
2012-08-30 19:56:15 +02:00
|
|
|
return render_to_response('zephyr/index.html',
|
2012-09-12 22:55:37 +02:00
|
|
|
{'zephyr_array' : zephyr_json,
|
2012-09-04 20:31:23 +02:00
|
|
|
'user_profile': user_profile,
|
2012-09-21 17:08:02 +02:00
|
|
|
'email_hash' : hashlib.md5(settings.HASH_SALT + user_profile.user.email).hexdigest(),
|
2012-09-07 17:26:58 +02:00
|
|
|
'people' : simplejson.dumps(people),
|
|
|
|
'classes' : simplejson.dumps(classes),
|
|
|
|
'instances' : simplejson.dumps(instances)},
|
2012-08-28 18:44:51 +02:00
|
|
|
context_instance=RequestContext(request))
|
|
|
|
|
2012-09-04 17:39:12 +02:00
|
|
|
@login_required
|
2012-09-05 23:38:20 +02:00
|
|
|
@require_post
|
2012-08-28 18:44:51 +02:00
|
|
|
def update(request):
|
2012-09-06 20:52:23 +02:00
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
|
|
|
pointer = request.POST.get('pointer')
|
|
|
|
if not pointer:
|
|
|
|
return json_error("Missing pointer")
|
|
|
|
|
|
|
|
try:
|
|
|
|
pointer = int(pointer)
|
|
|
|
except ValueError:
|
|
|
|
return json_error("Invalid pointer: must be an integer")
|
|
|
|
|
|
|
|
if pointer < 0:
|
|
|
|
return json_error("Invalid pointer value")
|
|
|
|
|
|
|
|
user_profile.pointer = pointer
|
|
|
|
user_profile.save()
|
2012-09-05 22:21:25 +02:00
|
|
|
return json_success()
|
2012-08-28 18:44:51 +02:00
|
|
|
|
2012-09-07 19:32:20 +02:00
|
|
|
@login_required
|
2012-08-28 22:56:21 +02:00
|
|
|
@asynchronous
|
2012-09-05 23:38:20 +02:00
|
|
|
@require_post
|
2012-08-28 22:56:21 +02:00
|
|
|
def get_updates_longpoll(request, handler):
|
2012-08-28 23:32:05 +02:00
|
|
|
last_received = request.POST.get('last_received')
|
2012-08-28 22:56:21 +02:00
|
|
|
if not last_received:
|
2012-09-07 19:09:30 +02:00
|
|
|
return json_error("Missing last_received argument")
|
2012-09-07 19:31:01 +02:00
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
2012-08-28 22:56:21 +02:00
|
|
|
|
|
|
|
def on_receive(zephyrs):
|
|
|
|
if handler.request.connection.stream.closed():
|
|
|
|
return
|
|
|
|
try:
|
2012-08-30 19:56:15 +02:00
|
|
|
handler.finish({'zephyrs': [zephyr.to_dict() for zephyr in zephyrs]})
|
2012-09-07 19:46:50 +02:00
|
|
|
except socket.error:
|
2012-08-28 22:56:21 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
# We need to replace this abstraction with the message list
|
|
|
|
user_profile.add_callback(handler.async_callback(on_receive), last_received)
|
2012-08-28 18:44:51 +02:00
|
|
|
|
2012-09-06 22:00:39 +02:00
|
|
|
@login_required
|
|
|
|
@require_post
|
2012-09-06 21:52:03 +02:00
|
|
|
def zephyr(request):
|
|
|
|
return zephyr_backend(request, request.user)
|
|
|
|
|
2012-09-06 22:00:39 +02:00
|
|
|
@login_required
|
|
|
|
@require_post
|
2012-09-06 22:01:50 +02:00
|
|
|
def forge_zephyr(request):
|
2012-09-21 00:26:59 +02:00
|
|
|
email = sanitize_identifier(request.POST['sender'])
|
2012-09-06 22:00:39 +02:00
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
|
|
|
try:
|
2012-09-21 00:26:59 +02:00
|
|
|
user = User.objects.get(email=email)
|
2012-09-06 22:04:42 +02:00
|
|
|
except User.DoesNotExist:
|
2012-09-06 22:00:39 +02:00
|
|
|
# forge a user for this person
|
2012-09-21 20:01:43 +02:00
|
|
|
user = create_user(email, "test", user_profile.realm,
|
|
|
|
sanitize_identifier(request.POST['fullname']),
|
|
|
|
sanitize_identifier(request.POST['shortname']))
|
2012-09-21 16:40:46 +02:00
|
|
|
|
2012-09-06 22:00:39 +02:00
|
|
|
return zephyr_backend(request, user)
|
|
|
|
|
2012-09-17 20:25:00 +02:00
|
|
|
md_engine = markdown.Markdown(
|
|
|
|
extensions = ['fenced_code', 'codehilite'],
|
|
|
|
safe_mode = True,
|
|
|
|
output_format = 'xhtml' )
|
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
@login_required
|
2012-09-05 23:38:20 +02:00
|
|
|
@require_post
|
2012-09-06 21:52:03 +02:00
|
|
|
def zephyr_backend(request, sender):
|
2012-09-05 22:30:50 +02:00
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
2012-09-07 19:20:04 +02:00
|
|
|
if "type" not in request.POST:
|
|
|
|
return json_error("Missing type")
|
|
|
|
if "new_zephyr" not in request.POST:
|
|
|
|
return json_error("Missing message contents")
|
|
|
|
|
2012-09-07 20:14:13 +02:00
|
|
|
zephyr_type_name = request.POST["type"]
|
|
|
|
if zephyr_type_name == 'class':
|
2012-09-13 23:48:20 +02:00
|
|
|
if "class" not in request.POST or not request.POST["class"]:
|
2012-09-07 19:20:04 +02:00
|
|
|
return json_error("Missing class")
|
|
|
|
if "instance" not in request.POST:
|
|
|
|
return json_error("Missing instance")
|
|
|
|
|
2012-09-17 21:20:11 +02:00
|
|
|
class_name = sanitize_identifier(request.POST['class']).strip()
|
2012-09-18 20:24:52 +02:00
|
|
|
my_classes = ZephyrClass.objects.filter(name=class_name, realm=user_profile.realm)
|
|
|
|
if my_classes:
|
|
|
|
my_class = my_classes[0]
|
2012-09-04 23:43:56 +02:00
|
|
|
else:
|
|
|
|
my_class = ZephyrClass()
|
|
|
|
my_class.name = class_name
|
2012-09-06 21:34:05 +02:00
|
|
|
my_class.realm = user_profile.realm
|
2012-09-04 23:43:56 +02:00
|
|
|
my_class.save()
|
2012-09-07 20:14:13 +02:00
|
|
|
recipient = Recipient(type_id=my_class.id, type=Recipient.CLASS)
|
2012-09-06 21:43:35 +02:00
|
|
|
recipient.save()
|
2012-09-05 22:26:20 +02:00
|
|
|
try:
|
2012-09-07 20:14:13 +02:00
|
|
|
recipient = Recipient.objects.get(type_id=my_class.id, type=Recipient.CLASS)
|
2012-09-05 22:26:20 +02:00
|
|
|
except Recipient.DoesNotExist:
|
|
|
|
return json_error("Invalid class")
|
2012-09-07 20:14:13 +02:00
|
|
|
elif zephyr_type_name == 'personal':
|
2012-09-07 19:20:04 +02:00
|
|
|
if "recipient" not in request.POST:
|
|
|
|
return json_error("Missing recipient")
|
|
|
|
|
2012-09-17 21:20:11 +02:00
|
|
|
recipient_data = sanitize_identifier(request.POST['recipient'])
|
2012-09-04 23:20:21 +02:00
|
|
|
if ',' in recipient_data:
|
2012-09-05 17:19:03 +02:00
|
|
|
# This is actually a huddle message, which shares the
|
|
|
|
# "personal" zephyr sending form
|
2012-09-04 23:20:21 +02:00
|
|
|
recipients = [r.strip() for r in recipient_data.split(',')]
|
2012-09-05 17:19:03 +02:00
|
|
|
# Ignore any blank recipients
|
2012-09-05 17:14:12 +02:00
|
|
|
recipients = [r for r in recipients if r]
|
2012-09-05 23:49:24 +02:00
|
|
|
recipient_ids = []
|
|
|
|
for recipient in recipients:
|
|
|
|
try:
|
|
|
|
recipient_ids.append(
|
2012-09-21 00:26:59 +02:00
|
|
|
UserProfile.objects.get(user=User.objects.get(email=recipient)).id)
|
2012-09-07 19:46:50 +02:00
|
|
|
except User.DoesNotExist:
|
2012-09-21 00:26:59 +02:00
|
|
|
return json_error("Invalid email '%s'" % (recipient))
|
2012-09-05 17:32:05 +02:00
|
|
|
# Make sure the sender is included in the huddle
|
2012-09-04 23:20:21 +02:00
|
|
|
recipient_ids.append(UserProfile.objects.get(user=request.user).id)
|
|
|
|
huddle = get_huddle(recipient_ids)
|
2012-09-10 19:43:11 +02:00
|
|
|
recipient = Recipient.objects.get(type_id=huddle.id, type=Recipient.HUDDLE)
|
2012-09-04 23:20:21 +02:00
|
|
|
else:
|
2012-09-05 17:19:03 +02:00
|
|
|
# This is actually a personal message
|
2012-09-21 00:26:59 +02:00
|
|
|
if not User.objects.filter(email=recipient_data):
|
|
|
|
return json_error("Invalid email")
|
2012-09-05 19:36:58 +02:00
|
|
|
|
2012-09-21 00:26:59 +02:00
|
|
|
recipient_user = User.objects.get(email=recipient_data)
|
2012-09-04 23:20:21 +02:00
|
|
|
recipient_user_profile = UserProfile.objects.get(user=recipient_user)
|
2012-09-07 20:14:13 +02:00
|
|
|
recipient = Recipient.objects.get(type_id=recipient_user_profile.id,
|
|
|
|
type=Recipient.PERSONAL)
|
2012-09-04 23:43:56 +02:00
|
|
|
else:
|
2012-09-06 21:53:26 +02:00
|
|
|
return json_error("Invalid zephyr type")
|
2012-08-28 21:27:42 +02:00
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
new_zephyr = Zephyr()
|
2012-09-06 21:52:03 +02:00
|
|
|
new_zephyr.sender = UserProfile.objects.get(user=sender)
|
2012-09-17 20:25:00 +02:00
|
|
|
new_zephyr.content = md_engine.convert(request.POST['new_zephyr'])
|
2012-08-28 21:27:42 +02:00
|
|
|
new_zephyr.recipient = recipient
|
2012-09-07 20:14:13 +02:00
|
|
|
if zephyr_type_name == 'class':
|
2012-09-17 21:20:11 +02:00
|
|
|
new_zephyr.instance = sanitize_identifier(request.POST['instance'])
|
2012-08-28 23:08:38 +02:00
|
|
|
new_zephyr.pub_date = datetime.datetime.utcnow().replace(tzinfo=utc)
|
2012-08-28 18:44:51 +02:00
|
|
|
new_zephyr.save()
|
2012-08-28 21:27:42 +02:00
|
|
|
|
2012-09-06 21:36:44 +02:00
|
|
|
return json_success()
|
2012-08-30 18:04:35 +02:00
|
|
|
|
2012-09-18 16:30:25 +02:00
|
|
|
def gather_subscriptions(userprofile):
|
|
|
|
subscriptions = Subscription.objects.filter(userprofile=userprofile, active=True)
|
|
|
|
# For now, don't display the subscription for your ability to receive personals.
|
|
|
|
return [get_display_recipient(sub.recipient) for sub in subscriptions
|
|
|
|
if sub.recipient.type == Recipient.CLASS]
|
|
|
|
|
2012-08-30 18:04:35 +02:00
|
|
|
@login_required
|
|
|
|
def subscriptions(request):
|
|
|
|
userprofile = UserProfile.objects.get(user=request.user)
|
|
|
|
|
|
|
|
return render_to_response('zephyr/subscriptions.html',
|
2012-09-18 16:30:25 +02:00
|
|
|
{'subscriptions': gather_subscriptions(userprofile),
|
|
|
|
'user_profile': userprofile},
|
2012-08-30 18:04:35 +02:00
|
|
|
context_instance=RequestContext(request))
|
|
|
|
|
2012-09-18 16:30:25 +02:00
|
|
|
@login_required
|
|
|
|
def json_subscriptions(request):
|
|
|
|
subs = gather_subscriptions(UserProfile.objects.get(user=request.user))
|
|
|
|
return HttpResponse(content=simplejson.dumps({"subscriptions": subs}),
|
|
|
|
mimetype='application/json', status=200)
|
|
|
|
|
2012-08-30 18:04:35 +02:00
|
|
|
@login_required
|
2012-09-07 19:07:41 +02:00
|
|
|
@require_post
|
2012-08-30 18:04:35 +02:00
|
|
|
def manage_subscriptions(request):
|
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
2012-09-07 19:20:04 +02:00
|
|
|
if 'subscription' not in request.POST:
|
|
|
|
return json_error("Missing subscriptions")
|
2012-08-30 18:04:35 +02:00
|
|
|
|
|
|
|
unsubs = request.POST.getlist('subscription')
|
|
|
|
for sub_name in unsubs:
|
2012-09-05 22:30:50 +02:00
|
|
|
zephyr_class = ZephyrClass.objects.get(name=sub_name, realm=user_profile.realm)
|
2012-09-07 20:14:13 +02:00
|
|
|
recipient = Recipient.objects.get(type_id=zephyr_class.id,
|
|
|
|
type=Recipient.CLASS)
|
2012-08-30 18:04:35 +02:00
|
|
|
subscription = Subscription.objects.get(
|
2012-09-05 21:55:40 +02:00
|
|
|
userprofile=user_profile, recipient=recipient)
|
2012-08-30 18:04:35 +02:00
|
|
|
subscription.active = False
|
|
|
|
subscription.save()
|
|
|
|
|
2012-09-18 17:45:03 +02:00
|
|
|
return json_success({"data": unsubs})
|
2012-08-30 20:00:04 +02:00
|
|
|
|
|
|
|
@login_required
|
2012-09-07 19:07:41 +02:00
|
|
|
@require_post
|
2012-08-30 20:00:04 +02:00
|
|
|
def add_subscriptions(request):
|
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
|
|
|
|
2012-09-07 19:20:04 +02:00
|
|
|
if "new_subscriptions" not in request.POST:
|
2012-08-30 20:00:04 +02:00
|
|
|
return HttpResponseRedirect(reverse('zephyr.views.subscriptions'))
|
|
|
|
|
2012-09-07 19:20:04 +02:00
|
|
|
new_subs = [s.strip() for s in
|
|
|
|
request.POST.get('new_subscriptions').split(",")]
|
|
|
|
for sub_name in new_subs:
|
|
|
|
if not re.match('^[a-zA-z0-9_-]+$', sub_name):
|
|
|
|
return json_error("Invalid characters in class names")
|
|
|
|
|
2012-09-18 16:30:25 +02:00
|
|
|
actually_new_subs = []
|
2012-09-07 19:20:04 +02:00
|
|
|
for sub_name in new_subs:
|
2012-09-05 22:30:50 +02:00
|
|
|
zephyr_class = ZephyrClass.objects.filter(name=sub_name, realm=user_profile.realm)
|
2012-08-30 20:00:04 +02:00
|
|
|
if zephyr_class:
|
|
|
|
zephyr_class = zephyr_class[0]
|
2012-09-07 20:14:13 +02:00
|
|
|
recipient = Recipient.objects.get(type_id=zephyr_class.id,
|
|
|
|
type=Recipient.CLASS)
|
2012-08-30 20:00:04 +02:00
|
|
|
else:
|
2012-09-19 18:54:57 +02:00
|
|
|
(_, recipient) = ZephyrClass.create(sub_name, user_profile.realm)
|
2012-08-30 20:00:04 +02:00
|
|
|
|
2012-09-05 21:55:40 +02:00
|
|
|
subscription = Subscription.objects.filter(userprofile=user_profile,
|
|
|
|
recipient=recipient)
|
2012-08-30 20:00:04 +02:00
|
|
|
if subscription:
|
|
|
|
subscription = subscription[0]
|
2012-09-18 16:30:25 +02:00
|
|
|
if not subscription.active:
|
|
|
|
# Activating old subscription.
|
|
|
|
subscription.active = True
|
|
|
|
subscription.save()
|
|
|
|
actually_new_subs.append(sub_name)
|
2012-08-30 20:00:04 +02:00
|
|
|
else:
|
2012-09-05 21:55:40 +02:00
|
|
|
new_subscription = Subscription(userprofile=user_profile,
|
|
|
|
recipient=recipient)
|
2012-08-30 20:00:04 +02:00
|
|
|
new_subscription.save()
|
2012-09-18 16:30:25 +02:00
|
|
|
actually_new_subs.append(sub_name)
|
|
|
|
return json_success({"data": actually_new_subs})
|
2012-09-05 23:38:20 +02:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
def class_exists(request, zephyr_class):
|
|
|
|
return HttpResponse(bool(ZephyrClass.objects.filter(name=zephyr_class)))
|