# -*- coding: utf-8 -*- from models import Webinar from functions.custom_views import ExpoListView from django.http import HttpResponse import json class WebinarView(ExpoListView): model = Webinar template_name = 'event_catalog.html' def webinar_add_calendar(request, id): args = {'success': False} user = request.user if user.is_authenticated(): web = Webinar.objects.safe_get(id=id) if web: user.calendar.webinars.add(web) args['success'] = True else: args['not_authorized'] = True args['success'] = True return HttpResponse(json.dumps(args), content_type='application/json') def webinar_remove_calendar(request, id): args = {'success': False} if request.user: user = request.user web = Webinar.objects.safe_get(id=id) if web: user.calendar.webinars.remove(web) args['success'] = True else: args['not_authorized'] = True args['success'] = True return HttpResponse(json.dumps(args), content_type='application/json') def webinar_visit(request, id): args = {'success': False} user = request.user if user.is_authenticated(): web = Webinar.objects.safe_get(id=id) if web: web.users.add(user) args['success'] = True else: args['not_authorized'] = True args['success'] = True return HttpResponse(json.dumps(args), content_type='application/json') def webinar_unvisit(request, id): args = {'success': False} user = request.user if user.is_authenticated(): web = Webinar.objects.safe_get(id=id) if web: web.users.remove(user) else: args['not_authorized'] = True args['success'] = True return HttpResponse(json.dumps(args), content_type='application/json')