예제 #1
0
def subscribe_qna(request):
  'subscribe to a given QnA'
  user = request.user
  employer_id = request.POST.get('employer_id')
  emp = Employer.objects.get(id=employer_id)
  _sub, _created = Subscription.objects.get_or_create(user=user, type=SUBSCRIPTIONS.QNA, employer=emp)
  _sub.is_active = True
  _sub.save()
  action_factory.employer_question_subscribe(user, emp)
  return ajax_response(True)
예제 #2
0
def _toggle_subscription(request, toggle_to):
  # common logic used by resubscribe() and unsubscribe()
  user = request.user
  sid = request.POST.get('subscription_id')
  try:
    sub = Subscription.objects.get(id=sid)
  except ObjectDoesNotExist:
    return ajax_response(False, [('subscription', 'Given subscription does not exist.')])
  if sub.user != user:
    return ajax_response(False, [('subscription', 'Invalid permission.')])
  sub.is_active = toggle_to
  sub.save()
  emp = sub.employer
  if toggle_to:
    action_factory.employer_question_subscribe(user, emp)
  else:
    action_factory.employer_question_unsubscribe(user, emp)
  return ajax_response(True)