def invite_participant(request): form = forms.InviteParticipantForm(request.POST) if not form.is_valid(): raise http.Http404 appointment = form.cleaned_data['id'] user = plauth.models.User.get_signed_in(request) if not user or appointment.initiator != user: raise http.Http404 iuser = plauth.models.User.get_or_create(form.cleaned_data['email']) invitee = models.Invitee.get_or_create(iuser, appointment) invitee.name = form.cleaned_data['name'] invitee.save() initiator = models.Invitee.objects.all().get(user=appointment.initiator, appointment=appointment) appointment.send_invitation(invitee, initiator, request) invitees_key = plapp.get_cache_key('invitees', appointment=appointment.id) invitees = cache.get(invitees_key) if invitees: cache.delete(invitees_key) addresses_key = plapp.get_cache_key('addresses', appointment=appointment.id) addresses = cache.get(addresses_key) if addresses: cache.delete(addresses_key) return http.HttpResponse()
def add_dates(request): appointment, user, invitee = _get_appointment_or_404(request) if (appointment.initiator != user and not appointment.propose_more): raise http.Http404 date = models.Date(appointment=appointment) date.date_time = datetime.datetime.strptime(request.POST['d'], '%Y-%m-%dT%H:%M:%S') date.invitee = invitee date.save() avail = models.Availability() avail.date = date avail.invitee = invitee avail.possible = 1 avail.save() # Remove dates from cache. Would be nicer to add the current date, but that would need re-ordering. dates_key = plapp.get_cache_key('dates', appointment=appointment.id) cache.set(dates_key, None) availability_key = plapp.get_cache_key('availability', appointment=appointment.id, invitee=invitee.id) availability = cache.get(availability_key) if availability: availability[date.id] = [1, ''] cache.set(availability_key, availability) return http.HttpResponse()
def add_invitees(request): appointment = models.Appointment.objects.all().get(id=int(request.POST["id"])) user = plauth.models.User.get_signed_in(request) if not user or not appointment or not appointment.visible or appointment.initiator != user: raise http.Http404 name, address = email.utils.getaddresses([request.POST["a"]])[0] iuser = plauth.models.User.get_or_create(address) inv = models.Invitee.get_or_create(iuser, appointment) inv.name = name inv.save() initiator = models.Invitee.objects.all().get(user=appointment.initiator, appointment=appointment) appointment.send_invitation(inv, initiator, request) invitees_key = plapp.get_cache_key("invitees", appointment=appointment.id) invitees = cache.get(invitees_key) if invitees: cache.delete(invitees_key) """ invitees.append({'name': inv.get_name(), 'id': inv.id}) cache.set(invitees_key, invitees) """ addresses_key = plapp.get_cache_key("addresses", appointment=appointment.id) addresses = cache.get(addresses_key) if addresses: cache.delete(addresses_key) """ addresses[inv.id] = inv.user.email cache.set(addresses_key, addresses) """ return http.HttpResponse()
def set_availability(request): appointment, user, invitee = _get_appointment_or_404(request) key = plapp.get_cache_key('availability', appointment=appointment.id, invitee=invitee.id) cached = cache.get(key) i = 0 for line in request.POST['a'].splitlines(): [datestring, possible, comment] = line.split(':', 2) date = models.Date.objects.all().get(id=int(datestring)) i += 1 try: avail = models.Availability.objects.all().get(date=date, invitee=invitee) except exceptions.ObjectDoesNotExist: avail = models.Availability(date=date, invitee=invitee) avail.possible = int(possible) avail.comment = comment avail.save() if cached: cached[date.id] = [int(possible), comment] if cached: cache.set(key, cached) return http.HttpResponse()
def add_dates(request): form = forms.ProposeDateForm(request.POST) if not form.is_valid(): raise http.Http404 appointment = form.cleaned_data['id'] user = plauth.models.User.get_signed_in(request) if (not user) or (appointment.initiator != user \ and not appointment.propose_more): raise http.Http404 invitee = models.Invitee.objects.all().get(user=user, appointment=appointment) date = models.Date(appointment=appointment) if form.cleaned_data['d']: date.date_time = form.cleaned_data['d'] elif form.cleaned_data['date'] and form.cleaned_data['time']: date.date_time = datetime.datetime.combine(form.cleaned_data['date'], form.cleaned_data['time']) else: raise http.Http404 date.invitee = invitee date.save() avail = models.Availability() avail.date = date avail.invitee = invitee avail.possible = 1 avail.save() # Remove dates from cache. Would be nicer to add the current date, but # that would need re-ordering. dates_key = plapp.get_cache_key('dates', appointment=appointment.id) cache.set(dates_key, None) availability_key = plapp.get_cache_key('availability', appointment=appointment.id, invitee=invitee.id) availability = cache.get(availability_key) if availability: availability[date.id] = [1, ''] cache.set(availability_key, availability) return http.HttpResponse()
def add_invitees(request): appointment = models.Appointment.objects.all().get(id=int(request.POST['id'])) user = plauth.models.User.get_signed_in(request) if (not user or not appointment or not appointment.visible or appointment.initiator != user): raise http.Http404 name, address = email.utils.getaddresses([request.POST['a']])[0] iuser = plauth.models.User.get_or_create(address) inv = models.Invitee.get_or_create(iuser, appointment) inv.name = name inv.save() initiator = models.Invitee.objects.all().get(user=appointment.initiator, appointment=appointment) appointment.send_invitation(inv, initiator, request) invitees_key = plapp.get_cache_key('invitees', appointment=appointment.id) invitees = cache.get(invitees_key) if invitees: cache.delete(invitees_key) """ invitees.append({'name': inv.get_name(), 'id': inv.id}) cache.set(invitees_key, invitees) """ addresses_key = plapp.get_cache_key('addresses', appointment=appointment.id) addresses = cache.get(addresses_key) if addresses: cache.delete(addresses_key) """ addresses[inv.id] = inv.user.email cache.set(addresses_key, addresses) """ return http.HttpResponse()
def appointment_data(request): appointment, user, invitee = _get_appointment_or_404(request) user_id = user.id invitee_id = invitee.id appt_id = appointment.id data = {'user': user_id, 'invitee': invitee_id} metadata_key = plapp.get_cache_key('metadata', appointment=appt_id) metadata = cache.get(metadata_key) if not metadata: appt = appointment metadata = appt.get_metadata() cache.set(metadata_key, metadata) data['meta'] = metadata invitees_key = plapp.get_cache_key('invitees', appointment=appt_id) invitees = cache.get(invitees_key) if not invitees: instances = appointment.invitee_set.all() invitees = [{'name': i.get_name(), 'id': i.id} for i in instances] cache.set(invitees_key, invitees) data['people'] = invitees if metadata['initiator'] == user_id: addresses_key = plapp.get_cache_key('addresses', appointment=appt_id) addresses = cache.get(addresses_key) if not addresses: instances = appointment.invitee_set.all() addresses = {} for i in instances: if i.user.id == user_id: continue addresses[i.id] = i.user.email cache.set(addresses_key, addresses) data['addresses'] = addresses dates_key = plapp.get_cache_key('dates', appointment=appt_id) dates = cache.get(dates_key) if not dates: def _local_short_date(date): return dateformat.format(date, _('D M d, G:i')) instances = appointment.date_set.order_by('date_time').all() dates = [] for d in instances: dates.append({'id': d.id, 's': _local_short_date(d.date_time), 'd': d.date_time.strftime('%Y-%m-%dT%H:%M:%S')}) cache.set(dates_key, dates) data['dates'] = dates availability = {} for invitee in invitees: avail_key = plapp.get_cache_key('availability', appointment=appt_id, invitee=invitee['id']) avail = cache.get(avail_key) if not avail: invitee_instance = plapp.models.Invitee.objects.all().get(id=int(invitee['id'])) instances = invitee_instance.availability_set.all() avail = {} for a in instances: avail[a.date.id] = [a.possible, a.comment] cache.set(avail_key, avail) availability[invitee['id']] = avail data['availability'] = availability s = simplejson.dumps(data, separators=(',', ':')) return http.HttpResponse(s, mimetype='application/javascript')
def appointment_data(request): appointment, user, invitee = _get_appointment_or_404(request) user_id = user.id invitee_id = invitee.id appt_id = appointment.id data = {"user": user_id, "invitee": invitee_id} metadata_key = plapp.get_cache_key("metadata", appointment=appt_id) metadata = cache.get(metadata_key) if not metadata: appt = appointment metadata = appt.get_metadata() cache.set(metadata_key, metadata) data["meta"] = metadata invitees_key = plapp.get_cache_key("invitees", appointment=appt_id) invitees = cache.get(invitees_key) if not invitees: instances = appointment.invitee_set.all() invitees = [{"name": i.get_name(), "id": i.id} for i in instances] cache.set(invitees_key, invitees) data["people"] = invitees if metadata["initiator"] == user_id: addresses_key = plapp.get_cache_key("addresses", appointment=appt_id) addresses = cache.get(addresses_key) if not addresses: instances = appointment.invitee_set.all() addresses = {} for i in instances: if i.user.id == user_id: continue addresses[i.id] = i.user.email cache.set(addresses_key, addresses) data["addresses"] = addresses dates_key = plapp.get_cache_key("dates", appointment=appt_id) dates = cache.get(dates_key) if not dates: def _local_short_date(date): return dateformat.format(date, _("D M d, G:i")) instances = appointment.date_set.order_by("date_time").all() dates = [] for d in instances: dates.append( {"id": d.id, "s": _local_short_date(d.date_time), "d": d.date_time.strftime("%Y-%m-%dT%H:%M:%S")} ) cache.set(dates_key, dates) data["dates"] = dates availability = {} for invitee in invitees: avail_key = plapp.get_cache_key("availability", appointment=appt_id, invitee=invitee["id"]) avail = cache.get(avail_key) if not avail: invitee_instance = plapp.models.Invitee.objects.all().get(id=int(invitee["id"])) instances = invitee_instance.availability_set.all() avail = {} for a in instances: avail[a.date.id] = [a.possible, a.comment] cache.set(avail_key, avail) availability[invitee["id"]] = avail data["availability"] = availability s = simplejson.dumps(data, separators=(",", ":")) return http.HttpResponse(s, mimetype="application/javascript")