def event_detail(request, name): event = subscr_Es.event_by_name(name) if event is None: raise Http404 subscription = event.get_subscription_of(request.user) if subscription is not None: if subscription.debit > 0: request.user.push_message(( "Je bent al aangemeld, maar moet nog wel %s"+ " euro betalen.") % subscription.debit) else: request.user.push_message("Je bent aangemeld!") elif request.method == 'POST' and event.is_open: notes = request.POST['notes'] subscription = subscr_Es.Subscription({ 'event': event._id, 'user': request.user._id, 'userNotes': notes, 'date': datetime.datetime.now(), 'debit': event.cost}) subscription.save() full_owner_address = '%s <%s>' % ( event.owner.humanName, event.owner.canonical_email) email = EmailMessage( "Aanmelding %s" % event.humanName, event.mailBody % { 'firstName': request.user.first_name, 'eventName': event.humanName, 'notes': notes}, 'Karpe Noktem Activiteiten <*****@*****.**>', [request.user.canonical_email], [event.owner.canonical_email], headers={ 'Cc': full_owner_address, 'Reply-To': full_owner_address}) email.send() if event.cost > 0: request.user.push_message( "Je bent aangemeld en moet "+\ "nu %s euro betalen" % event.cost) else: request.user.push_message( "Je bent aangemeld") ctx = {'object': event, 'user': request.user, 'subscription': subscription, 'has_debit_access': event.has_debit_access(request.user), 'has_read_access': event.has_read_access(request.user), 'has_write_access': event.has_write_access(request.user)} if event.has_read_access(request.user) or \ event.has_debit_access(request.user): subscrlist = tuple(event.get_subscriptions()) ctx.update({ 'subscrlist': subscrlist, 'subscrcount_debit': len([s for s in subscrlist if s.debit != 0]), 'subscrlist_count': len(subscrlist)}) return render_to_response('subscriptions/event_detail.html', ctx, context_instance=RequestContext(request))
def event_new_or_edit(request, edit=None): superuser = '******' in request.user.cached_groups_names if edit is not None: e = subscr_Es.event_by_name(edit) if e is None: raise Http404 if not superuser and not request.user.is_related_with(e.owner) and \ not _id(e.owner) == request.user.id: raise PermissionDenied AddEventForm = get_add_event_form(request.user, superuser) if request.method == 'POST': form = AddEventForm(request.POST) if form.is_valid(): fd = form.cleaned_data if not superuser and not request.user.is_related_with( fd['owner']) and not fd['owner'] == request.user.id: raise PermissionDenied name = fd['name'] # If not secretariaat, then prefix name with the username prefix = str(request.user.name) + '-' if not superuser and not name.startswith(prefix): name = prefix + name d = { 'date': date_to_dt(fd['date']), 'owner': _id(fd['owner']), 'description': fd['description'], 'mailBody': fd['mailBody'], 'humanName': fd['humanName'], 'createdBy': request.user._id, 'name': name, 'cost': str(fd['cost']), 'is_open': True} if edit is None: e = subscr_Es.Event(d) else: e._data.update(d) e.save() act = 'bewerkt' if edit else 'aangemaakt' EmailMessage( "Activiteit %s %s door %s" % (fd['humanName'], act, unicode(request.user.humanName)), "%s heeft een activiteit %s:\n\n"\ " http://karpenoktem.nl%s" % (unicode(request.user.humanName), act, reverse('event-detail', args=(e.name,))), 'Karpe Noktem Activiteiten <*****@*****.**>', ['*****@*****.**']).send() return HttpResponseRedirect(reverse('event-detail', args=(e.name,))) elif edit is None: form = AddEventForm() else: d = e._data form = AddEventForm(d) ctx = {'form': form} return render_to_response('subscriptions/event_new_or_edit.html', ctx, context_instance=RequestContext(request))
def event_detail(request, name): # First, find the event. event = subscr_Es.event_by_name(name) if event is None: raise Http404 # Has the user already subscribed? subscription = event.get_subscription(request.user) # What are our permissions? has_read_access = event.has_read_access(request.user) has_write_access = event.has_write_access(request.user) if request.method == 'POST' and 'subscribe' in request.POST: if not event.is_open: raise PermissionDenied if subscription is not None and subscription.subscribed: messages.error(request, "Je bent al aangemeld") else: notes = request.POST['notes'] subscription = event.subscribe(request.user, notes) return HttpResponseRedirect(reverse('event-detail', args=(event.name,))) elif request.method == 'POST' and 'invite' in request.POST: if not event.is_open: raise PermissionDenied # Find the other user user = Es.by_id(request.POST['who']) if not user or not user.is_user: raise Http404 # Is the other already subscribed? if event.get_subscription(user) is not None: messages.error(request, "%s is al aangemeld" % user.full_name) else: notes = request.POST['notes'] other_subscription = event.invite(user, notes, request.user) return HttpResponseRedirect(reverse('event-detail', args=(event.name,))) users = filter(lambda u: event.get_subscription(u) is None and \ u != request.user, Es.by_name('leden').get_members()) users.sort(key=lambda u: unicode(u.humanName)) subscriptions = event.subscriptions subscriptions.sort(key=lambda s: s.date) invitations = event.invitations invitations.sort(key=lambda i: i.date) ctx = {'object': event, 'user': request.user, 'users': users, 'subscription': subscription, 'subscriptions': subscriptions, 'invitations': invitations, 'has_read_access': has_read_access, 'has_write_access': has_write_access} return render_to_response('subscriptions/event_detail.html', ctx, context_instance=RequestContext(request))
def event_detail(request, name): # First, find the event. event = subscr_Es.event_by_name(name) if event is None: raise Http404 # Has the user already subscribed? subscription = event.get_subscription(request.user) # What are our permissions? has_read_access = event.has_read_access(request.user) has_write_access = event.has_write_access(request.user) if request.method == 'POST' and 'subscribe' in request.POST: if not event.can_subscribe: raise PermissionDenied if subscription is not None and subscription.subscribed: messages.error(request, _("Je bent al aangemeld")) else: notes = request.POST['notes'] subscription = event.subscribe(request.user, notes) return HttpResponseRedirect(reverse('event-detail', args=(event.name,))) elif request.method == 'POST' and 'unsubscribe' in request.POST: if not event.can_unsubscribe: raise PermissionDenied if not subscription.subscribed: messages.error(request, _("Je bent al afgemeld")) else: notes = request.POST['notes'] subscription = event.unsubscribe(request.user, notes) return HttpResponseRedirect(reverse('event-detail', args=(event.name,))) elif request.method == 'POST' and 'invite' in request.POST: if not event.is_open: raise PermissionDenied # Find the other user user = Es.by_id(request.POST['who']) if not user or not user.is_user: raise Http404 # Is the other already subscribed? if event.get_subscription(user) is not None: messages.error(request, _("%s is al aangemeld") % user.full_name) else: notes = request.POST['notes'] event.invite(user, notes, request.user) return HttpResponseRedirect(reverse('event-detail', args=(event.name,))) users = list(filter( lambda u: event.get_subscription(u) is None and u != request.user, Es.by_name('leden').get_members() )) users.sort(key=lambda u: six.text_type(u.humanName)) listSubscribed = sorted(event.listSubscribed, key=lambda s: s.date) listUnsubscribed = sorted(event.listUnsubscribed, key=lambda s: s.date) listInvited = sorted(event.listInvited, key=lambda s: s.date) ctx = {'object': event, 'user': request.user, 'users': users, 'subscription': subscription, 'listSubscribed': listSubscribed, 'listUnsubscribed': listUnsubscribed, 'listInvited': listInvited, 'has_read_access': has_read_access, 'has_write_access': has_write_access} return render(request, 'subscriptions/event_detail.html', ctx)
def event_new_or_edit(request, edit=None): superuser = subscr_Es.is_superuser(request.user) if edit is not None: e = subscr_Es.event_by_name(edit) if e is None: raise Http404 if not superuser and not request.user.is_related_with(e.owner) and \ not _id(e.owner) == request.user._id: raise PermissionDenied AddEventForm = get_add_event_form(request.user, superuser, bool(edit)) if request.method == 'POST': form = AddEventForm(request.POST) if form.is_valid(): fd = form.cleaned_data # The superuser may do everything, and when you yourself are the # owner that's always okay too. if not superuser and fd['owner'] != request.user.id: # Check some more constraints. owner = Es.by_id(fd['owner']) if not request.user.is_related_with(owner): raise PermissionDenied( _('Gebruiker niet verwant met eigenaar') ) if not subscr_Es.may_set_owner(request.user, owner): raise PermissionDenied(_('Mag deze eigenaar niet kiezen')) d = { 'date': date_to_dt(fd['date']), 'owner': _id(fd['owner']), 'description': fd['description'], 'description_html': kn.utils.markdown.parser.convert( fd['description']), 'has_public_subscriptions': fd['has_public_subscriptions'], 'may_unsubscribe': fd['may_unsubscribe'], 'humanName': fd['humanName'], 'createdBy': request.user._id, 'cost': str(fd['cost']), 'max_subscriptions': fd['max_subscriptions'], 'is_official': superuser} if edit is None: name = fd['name'] # If not secretariaat, then prefix name with the username if fd['owner'] == request.user.id: prefix = str(request.user.name) + '-' else: prefix = str(Es.by_id(fd['owner']).name) + '-' if (not superuser and not name.startswith(prefix) and ( edit is None or e.name != name)): name = prefix + name d['name'] = name d['is_open'] = True # default for new events e = subscr_Es.Event(d) else: e.update(d, request.user, save=False) e.save() render_then_email( 'subscriptions/' + ('event-edited' if edit else 'new-event') + '.mail.html', Es.by_name('secretariaat').canonical_full_email, { 'event': e, 'user': request.user }, headers={ 'In-Reply-To': e.messageId, 'References': e.messageId, }, ) return HttpResponseRedirect( reverse('event-detail', args=(e.name,))) elif edit is None: form = AddEventForm() else: d = e._data form = AddEventForm(d) ctx = {'form': form, 'edit': edit} return render(request, 'subscriptions/event_new_or_edit.html', ctx)
def event_detail(request, name): # First, find the event. event = subscr_Es.event_by_name(name) if event is None: raise Http404 # Has the user already subscribed? subscription = event.get_subscription_of(request.user) # What are our permissions? has_read_access = event.has_read_access(request.user) has_write_access = event.has_write_access(request.user) may_subscribe_others = (has_write_access or event.everyone_can_subscribe_others) # Are we subscribing someone else? if (request.method == 'POST' and event.is_open and 'who' in request.POST and request.POST['who'] != str(request.user.id)): other_subscription = event.get_subscription_of(request.POST['who']) # Are we allowed to subscribe others? if not may_subscribe_others: raise PermissionDenied # Is the other already subscribed if other_subscription is not None: request.user.push_message("%s is al aangemeld" % ( Es.by_id(request.POST['who']).full_name)) else: # Find the user to subscribe user = Es.by_id(request.POST['who']) if not user or not user.is_user: raise Http404 notes = request.POST['notes'] other_subscription = subscr_Es.Subscription({ 'event': event._id, 'user': _id(user), 'date': datetime.datetime.now(), 'debit': str(event.cost), 'subscribedBy_notes': notes, 'confirmed': False, 'subscribedBy': _id(request.user)}) other_subscription.save() email = EmailMessage( "Bevestig je aanmelding voor %s" % event.humanName, event.subscribedByOtherMailBody % { 'firstName': user.first_name, 'by_firstName': request.user.first_name, 'by_notes': notes, 'eventName': event.humanName, 'confirmationLink': ("http://karpenoktem.nl%s" % reverse('event-detail', args=(event.name,))), 'owner': event.owner.humanName}, 'Karpe Noktem Activiteiten <*****@*****.**>', [user.canonical_full_email], [event.owner.canonical_full_email, request.user.canonical_full_email], headers={ 'Cc': '%s, %s' % (event.owner.canonical_full_email, request.user.canonical_full_email), 'Reply-To': event.owner.canonical_full_email}) email.send() if (subscription is None and request.method == 'POST' and event.is_open and ('who' not in request.POST or request.POST['who'] == str(request.user.id))): notes = request.POST['notes'] subscription = subscr_Es.Subscription({ 'event': event._id, 'user': request.user._id, 'userNotes': notes, 'date': datetime.datetime.now(), 'debit': str(event.cost)}) subscription.save() email = EmailMessage( "Aanmelding %s" % event.humanName, event.mailBody % { 'firstName': request.user.first_name, 'eventName': event.humanName, 'owner': event.owner.humanName, 'notes': notes}, 'Karpe Noktem Activiteiten <*****@*****.**>', [request.user.canonical_full_email], [event.owner.canonical_full_email], headers={ 'Cc': event.owner.canonical_full_email, 'Reply-To': event.owner.canonical_full_email}) email.send() subscrlist = tuple(event.get_subscriptions()) ctx = {'object': event, 'user': request.user, 'subscription': subscription, 'subscrlist': subscrlist, 'subscrcount_debit': len([s for s in subscrlist if s.debit != 0]), 'subscrlist_count': len(subscrlist), 'has_debit_access': event.has_debit_access(request.user), 'may_subscribe_others': may_subscribe_others, 'has_read_access': has_read_access, 'has_write_access': has_write_access} if may_subscribe_others: ctx['users'] = sorted(Es.by_name('leden').get_members(), lambda x,y: cmp(unicode(x.humanName), unicode(y.humanName))) return render_to_response('subscriptions/event_detail.html', ctx, context_instance=RequestContext(request))
def event_new_or_edit(request, edit=None): superuser = '******' in request.user.cached_groups_names if edit is not None: e = subscr_Es.event_by_name(edit) if e is None: raise Http404 if not superuser and not request.user.is_related_with(e.owner) and \ not _id(e.owner) == request.user._id: raise PermissionDenied AddEventForm = get_add_event_form(request.user, superuser) if request.method == 'POST': form = AddEventForm(request.POST) if form.is_valid(): fd = form.cleaned_data if not superuser and not request.user.is_related_with( fd['owner']) and not fd['owner'] == request.user.id: raise PermissionDenied name = fd['name'] # If not secretariaat, then prefix name with the username if fd['owner'] == request.user.id: prefix = str(request.user.name) + '-' else: prefix = str(Es.by_id(fd['owner']).name) + '-' if (not superuser and not name.startswith(prefix) and ( edit is None or e.name != name)): name = prefix + name d = { 'date': date_to_dt(fd['date']), 'owner': _id(fd['owner']), 'description': fd['description'], 'description_html': kn.utils.markdown.parser.convert( fd['description']), 'mailBody': fd['mailBody'], 'subscribedByOtherMailBody': fd['subscribedByOtherMailBody'], 'confirmationMailBody': fd['confirmationMailBody'], 'everyone_can_subscribe_others': fd['everyone_can_subscribe_others'], 'has_public_subscriptions': fd['has_public_subscriptions'], 'humanName': fd['humanName'], 'createdBy': request.user._id, 'name': name, 'cost': str(fd['cost']), 'is_open': True, 'is_official': superuser} if edit is None: e = subscr_Es.Event(d) else: e._data.update(d) e.save() render_then_email('subscriptions/' + ('event-edited' if edit else 'new-event') + '.mail.txt', Es.by_name('secretariaat').canonical_full_email, { 'event': e, 'user': request.user}) return HttpResponseRedirect(reverse('event-detail', args=(e.name,))) elif edit is None: form = AddEventForm() else: d = e._data form = AddEventForm(d) ctx = {'form': form, 'edit': edit} return render_to_response('subscriptions/event_new_or_edit.html', ctx, context_instance=RequestContext(request))
def validate_event_name(name): if subscr_Es.event_by_name(name): raise forms.ValidationError(_('Naam voor computers bestaat al'))
def event_detail(request, name): # First, find the event. event = subscr_Es.event_by_name(name) if event is None: raise Http404 # Has the user already subscribed? subscription = event.get_subscription(request.user) # What are our permissions? has_read_access = event.has_read_access(request.user) has_write_access = event.has_write_access(request.user) if request.method == 'POST' and 'subscribe' in request.POST: if not event.can_subscribe: raise PermissionDenied if subscription is not None and subscription.subscribed: messages.error(request, _("Je bent al aangemeld")) else: notes = request.POST['notes'] subscription = event.subscribe(request.user, notes) return HttpResponseRedirect( reverse('event-detail', args=(event.name, ))) elif request.method == 'POST' and 'unsubscribe' in request.POST: if not event.can_unsubscribe: raise PermissionDenied if not subscription.subscribed: messages.error(request, _("Je bent al afgemeld")) else: notes = request.POST['notes'] subscription = event.unsubscribe(request.user, notes) return HttpResponseRedirect( reverse('event-detail', args=(event.name, ))) elif request.method == 'POST' and 'invite' in request.POST: if not event.is_open: raise PermissionDenied # Find the other user user = Es.by_id(request.POST['who']) if not user or not user.is_user: raise Http404 # Is the other already subscribed? if event.get_subscription(user) is not None: messages.error(request, _("%s is al aangemeld") % user.full_name) else: notes = request.POST['notes'] event.invite(user, notes, request.user) return HttpResponseRedirect( reverse('event-detail', args=(event.name, ))) users = list( filter( lambda u: event.get_subscription(u) is None and u != request.user, Es.by_name('leden').get_members())) users.sort(key=lambda u: six.text_type(u.humanName)) listSubscribed = sorted(event.listSubscribed, key=lambda s: s.date) listUnsubscribed = sorted(event.listUnsubscribed, key=lambda s: s.date) listInvited = sorted(event.listInvited, key=lambda s: s.date) ctx = { 'object': event, 'user': request.user, 'users': users, 'subscription': subscription, 'listSubscribed': listSubscribed, 'listUnsubscribed': listUnsubscribed, 'listInvited': listInvited, 'has_read_access': has_read_access, 'has_write_access': has_write_access } return render(request, 'subscriptions/event_detail.html', ctx)
def event_new_or_edit(request, edit=None): superuser = subscr_Es.is_superuser(request.user) if edit is not None: e = subscr_Es.event_by_name(edit) if e is None: raise Http404 if not superuser and not request.user.is_related_with(e.owner) and \ not _id(e.owner) == request.user._id: raise PermissionDenied AddEventForm = get_add_event_form(request.user, superuser, bool(edit)) if request.method == 'POST': form = AddEventForm(request.POST) if form.is_valid(): fd = form.cleaned_data # The superuser may do everything, and when you yourself are the # owner that's always okay too. if not superuser and fd['owner'] != request.user.id: # Check some more constraints. owner = Es.by_id(fd['owner']) if not request.user.is_related_with(owner): raise PermissionDenied( _('Gebruiker niet verwant met eigenaar')) if not subscr_Es.may_set_owner(request.user, owner): raise PermissionDenied(_('Mag deze eigenaar niet kiezen')) d = { 'date': date_to_dt(fd['date']), 'owner': _id(fd['owner']), 'description': fd['description'], 'description_html': kn.utils.markdown.parser.convert(fd['description']), 'has_public_subscriptions': fd['has_public_subscriptions'], 'may_unsubscribe': fd['may_unsubscribe'], 'humanName': fd['humanName'], 'createdBy': request.user._id, 'cost': str(fd['cost']), 'max_subscriptions': fd['max_subscriptions'], 'is_official': superuser } if edit is None: name = fd['name'] # If not secretariaat, then prefix name with the username if fd['owner'] == request.user.id: prefix = str(request.user.name) + '-' else: prefix = str(Es.by_id(fd['owner']).name) + '-' if (not superuser and not name.startswith(prefix) and (edit is None or e.name != name)): name = prefix + name d['name'] = name d['is_open'] = True # default for new events e = subscr_Es.Event(d) else: e.update(d, request.user, save=False) e.save() render_then_email( 'subscriptions/' + ('event-edited' if edit else 'new-event') + '.mail.html', Es.by_name('secretariaat').canonical_full_email, { 'event': e, 'user': request.user }, headers={ 'In-Reply-To': e.messageId, 'References': e.messageId, }, ) return HttpResponseRedirect( reverse('event-detail', args=(e.name, ))) elif edit is None: form = AddEventForm() else: d = e._data form = AddEventForm(d) ctx = {'form': form, 'edit': edit} return render(request, 'subscriptions/event_new_or_edit.html', ctx)
def event_detail(request, name): # First, find the event. event = subscr_Es.event_by_name(name) if event is None: raise Http404 # Has the user already subscribed? subscription = event.get_subscription_of(request.user) # What are our permissions? has_read_access = event.has_read_access(request.user) has_write_access = event.has_write_access(request.user) may_subscribe_others = (has_write_access or event.everyone_can_subscribe_others) # Are we subscribing someone else? if (request.method == 'POST' and event.is_open and 'who' in request.POST and request.POST['who'] != str(request.user.id)): other_subscription = event.get_subscription_of(request.POST['who']) # Are we allowed to subscribe others? if not may_subscribe_others: raise PermissionDenied # Is the other already subscribed if other_subscription is not None: request.user.push_message( "%s is al aangemeld" % (Es.by_id(request.POST['who']).full_name)) else: # Find the user to subscribe user = Es.by_id(request.POST['who']) if not user or not user.is_user: raise Http404 notes = request.POST['notes'] other_subscription = subscr_Es.Subscription({ 'event': event._id, 'user': _id(user), 'date': datetime.datetime.now(), 'debit': str(event.cost), 'subscribedBy_notes': notes, 'confirmed': False, 'subscribedBy': _id(request.user) }) other_subscription.save() email = EmailMessage( "Bevestig je aanmelding voor %s" % event.humanName, event.subscribedByOtherMailBody % { 'firstName': user.first_name, 'by_firstName': request.user.first_name, 'by_notes': notes, 'eventName': event.humanName, 'confirmationLink': ("http://karpenoktem.nl%s" % reverse('event-detail', args=(event.name, ))), 'owner': event.owner.humanName }, 'Karpe Noktem Activiteiten <*****@*****.**>', [user.canonical_full_email], [ event.owner.canonical_full_email, request.user.canonical_full_email ], headers={ 'Cc': '%s, %s' % (event.owner.canonical_full_email, request.user.canonical_full_email), 'Reply-To': event.owner.canonical_full_email }) email.send() if (subscription is None and request.method == 'POST' and event.is_open and ('who' not in request.POST or request.POST['who'] == str(request.user.id))): notes = request.POST['notes'] subscription = subscr_Es.Subscription({ 'event': event._id, 'user': request.user._id, 'userNotes': notes, 'date': datetime.datetime.now(), 'debit': str(event.cost) }) subscription.save() email = EmailMessage("Aanmelding %s" % event.humanName, event.mailBody % { 'firstName': request.user.first_name, 'eventName': event.humanName, 'owner': event.owner.humanName, 'notes': notes }, 'Karpe Noktem Activiteiten <*****@*****.**>', [request.user.canonical_full_email], [event.owner.canonical_full_email], headers={ 'Cc': event.owner.canonical_full_email, 'Reply-To': event.owner.canonical_full_email }) email.send() subscrlist = tuple(event.get_subscriptions()) ctx = { 'object': event, 'user': request.user, 'subscription': subscription, 'subscrlist': subscrlist, 'subscrcount_debit': len([s for s in subscrlist if s.debit != 0]), 'subscrlist_count': len(subscrlist), 'has_debit_access': event.has_debit_access(request.user), 'may_subscribe_others': may_subscribe_others, 'has_read_access': has_read_access, 'has_write_access': has_write_access } if may_subscribe_others: ctx['users'] = sorted( Es.by_name('leden').get_members(), lambda x, y: cmp(unicode(x.humanName), unicode(y.humanName))) return render_to_response('subscriptions/event_detail.html', ctx, context_instance=RequestContext(request))
def event_new_or_edit(request, edit=None): superuser = '******' in request.user.cached_groups_names if edit is not None: e = subscr_Es.event_by_name(edit) if e is None: raise Http404 if not superuser and not request.user.is_related_with(e.owner) and \ not _id(e.owner) == request.user._id: raise PermissionDenied AddEventForm = get_add_event_form(request.user, superuser) if request.method == 'POST': form = AddEventForm(request.POST) if form.is_valid(): fd = form.cleaned_data if not superuser and not request.user.is_related_with( fd['owner']) and not fd['owner'] == request.user.id: raise PermissionDenied name = fd['name'] # If not secretariaat, then prefix name with the username if fd['owner'] == request.user.id: prefix = str(request.user.name) + '-' else: prefix = str(Es.by_id(fd['owner']).name) + '-' if (not superuser and not name.startswith(prefix) and (edit is None or e.name != name)): name = prefix + name d = { 'date': date_to_dt(fd['date']), 'owner': _id(fd['owner']), 'description': fd['description'], 'description_html': kn.utils.markdown.parser.convert(fd['description']), 'mailBody': fd['mailBody'], 'subscribedByOtherMailBody': fd['subscribedByOtherMailBody'], 'confirmationMailBody': fd['confirmationMailBody'], 'everyone_can_subscribe_others': fd['everyone_can_subscribe_others'], 'has_public_subscriptions': fd['has_public_subscriptions'], 'humanName': fd['humanName'], 'createdBy': request.user._id, 'name': name, 'cost': str(fd['cost']), 'is_open': True, 'is_official': superuser } if edit is None: e = subscr_Es.Event(d) else: e._data.update(d) e.save() render_then_email( 'subscriptions/' + ('event-edited' if edit else 'new-event') + '.mail.txt', Es.by_name('secretariaat').canonical_full_email, { 'event': e, 'user': request.user }) return HttpResponseRedirect( reverse('event-detail', args=(e.name, ))) elif edit is None: form = AddEventForm() else: d = e._data form = AddEventForm(d) ctx = {'form': form, 'edit': edit} return render_to_response('subscriptions/event_new_or_edit.html', ctx, context_instance=RequestContext(request))