def view_events_serialise(request, country, region): """ AJAX return list of events for given country and region if user is registered, than provide information about favorite and RSVP state """ if request.method == "GET": if request.GET.has_key("format") and request.GET["format"] == "csv": r = None c = None if country != u"all": c = Country.get_by_key_name(country.strip()) if c is None: return HttpResponse("") if region != u"all": r = Region.get_by_key_name(region.strip()) if r is None: return HttpResponse("") # if r defined, then c has to be defined as well assert not r or (r and c) q = Event.all() if c: q.filter("country =", c) if r: q.filter("region =", r) in_iframe = request.GET.has_key("in_iframe") return HttpResponse(serialise_events_for_query(q, request.user, in_iframe, True, True)) return HttpResponseNotFound()
def view_subscribe(request): # login is required here # if not ( request.user and request.user.is_authenticated() ): # return HttpResponseRedirect() if request.user.subscription_set.count() >= Subscription._MAX_SUBSCRIPTIONS_PER_USER: Message( user=request.user, message=ugettext("You've reached maximum number of subscriptions. Delete some and try again."), ).put() elif request.method == "GET": search_form = AdvancedEventFilterForm(request.GET) if search_form.is_valid(): country = Country.get_by_key_name(search_form.cleaned_data["country"]) region = Region.get_by_key_name(search_form.cleaned_data["region"]) free = search_form.cleaned_data["forfree"] if search_form.cleaned_data["forwho"] == "custom": event_types = 0 for t in search_form.cleaned_data["typelist"]: event_types += 1 << int(t) elif search_form.cleaned_data["forwho"] == "everyone": event_types = Event.OPEN_EVENTS_MASK else: # assert(search_form.cleaned_data['forwho'] == 'members') event_types = Event.MEMBERS_EVENTS_MASK s = Subscription(user=request.user, country=country, region=region, event_types=event_types, free=free) s.put() Message(user=request.user, message=ugettext("Subscription created")).put() return HttpResponseRedirect( reverse("events.views.view_event_list", kwargs={"subscription_id": s.key().id()}) ) return HttpResponseRedirect(reverse("events.views.view_event_list"))