Example #1
0
def event_new(request):
        AddEventForm = get_add_event_form(request.user)
        if request.method == 'POST':
                form = AddEventForm(request.POST)
                if form.is_valid():
                        fd = form.cleaned_data
                        if not request.user.is_related_with(fd['owner']):
                                raise PermissionDenied
                        e = subscr_Es.Event({
                                'date': date_to_dt(fd['date']),
                                'owner': _id(fd['owner']),
                                'description': fd['description'],
                                'mailBody': fd['mailBody'],
                                'humanName': fd['humanName'],
                                'createdBy': request.user._id,
                                'name': fd['name'],
                                'cost': str(fd['cost']),
                                'is_open': True})
                        e.save()
                        return HttpResponseRedirect(reverse('event-detail',
                                                args=(e.name,)))
        else:
                form = AddEventForm()
        ctx = {'form': form}
	return render_to_response('subscriptions/event_new.html', ctx,
			context_instance=RequestContext(request))
Example #2
0
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))
Example #3
0
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)
Example #4
0
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))
Example #5
0
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)
Example #6
0
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))