Example #1
0
def backstage_fee_form(request, project, fee):
    project = get_project(request, project, 'is_manager')
    fee = get_object_or_404(Fee, pk=fee)

    if request.POST:
        if request.POST.get('delete'):
            message_object_deleted(request, fee)
            fee.delete()
            return redirect('bs-fee-list', project=project.pk)

        form = FeeForm(request.POST, instance=fee)
        if form.is_valid():
            form.save()
            message_object_updated(request, fee)
            return redirect('bs-fee-list', project=project.pk)
    else:
        form = FeeForm(instance=fee)

    c = {
        'project': project,
        'view_title': Fee.objects.model._meta.verbose_name_plural,
        'view_url_list': 'bs-fee-list',
        'form': form,
        'object': fee
    }

    return render(request, 'project/form.html',
                  get_context_backstage_project(request, project, 'bs-fee-form', c))
Example #2
0
def backstage_event_form(request, project, event):
    project = get_project(request, project, 'manage_dates')
    event = get_object_or_404(Event, pk=event, project=project)

    if request.POST:
        if request.POST.get('delete'):
            message_object_deleted(request, event)
            event.delete()
            return redirect('bs-event-list', project=project.pk)

        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            message_object_updated(request, event)
            return redirect('bs-event-list', project=project.pk)
    else:
        form = EventForm(instance=event)

    c = {
        'project': project,
        'view_title': Event.objects.model._meta.verbose_name_plural,
        'view_url_list': 'bs-event-list',
        'form': form,
        'object': event
    }

    return render(request, 'project/form.html',
                  get_context_backstage_project(request, project, 'bs-event-form', c))
Example #3
0
def page_edit(request, page_slug):
    try:
        page = Page.objects.get_by_write(page_slug, request)
    except PermissionDenied:
        return redirect('wiki-page', page_slug=page_slug)
    except Page.DoesNotExist:
        page = None

    form_page = None

    if request.POST:
        form = RevisionForm(request.POST)
        if form.is_valid():
            # adding new page
            if page is None:
                form_page = PageAddForm(request.POST, user=request.user)
                if form_page.is_valid():
                    page = form_page.save()
                    if Page.objects.count() == 1:
                        # first wiki page created
                        configuration = Configuration.objects.current()
                        configuration.wiki_homepage = page
                        configuration.save()
                        messages.info(request, _(u'Diese Wiki-Seite wurde nun als Startseite des Wikis eingerichtet. '
                                                 u'Du kannst das in der Konfiguration ändern.'))

            if page:
                revision = form.save(commit=False)
                revision.user = request.user.actor
                revision.page = page
                revision.save()
                message_object_updated(request, page)
                return redirect(page)
        else:
            form_page = PageAddForm(request.POST, user=request.user, initial={'title': page_slug.capitalize})
    else:
        if page is None:
            form = RevisionForm()
            form_page = PageAddForm(user=request.user, initial={'title': page_slug.capitalize})
        else:
            revision = page.get_current()
            revision.summary = ''
            form = RevisionForm(instance=revision)

    if page is not None:
        is_owner = page.is_owner(request.user.actor)
    else:
        is_owner = None

    return render(request, 'wiki/page-edit.html', get_context_wiki(request, 'wiki-page-edit',
                                                                   {'form': form, 'page': page,
                                                                    'form_page': form_page,
                                                                    'tpl__is_owner': is_owner}))
Example #4
0
def backstage_content_form(request, project):
    project = get_project(request, project, 'manage_content')

    if request.POST:
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
            message_object_updated(request, project)
    else:
        form = ProjectForm(instance=project)

    return render(request, 'project/content-form.html',
                  get_context_backstage_project(request, project, 'bs-content',
                                                {'project': project, 'form': form}))
Example #5
0
def board_member_form(request, actor_pk):
    a = get_object_or_404(Actor, pk=actor_pk)

    if request.POST:
        form_actor = BoardActorForm(request.POST, instance=a)
        form_user = BoardUserForm(request.POST, instance=a.user)
        if form_actor.is_valid() and form_actor.is_valid():
            form_actor.save()
            form_user.save()
            message_object_updated(request, a)
    else:
        form_actor = BoardActorForm(instance=a)
        form_user = BoardUserForm(instance=a.user)

    forms = (form_actor, form_user)

    return render(request, 'backstage/board-member-form.html', get_context_backstage(request, 'bs-board-member-form',
                                                                                     {'actor': a, 'forms': forms}))
Example #6
0
def page_form(request, page_slug):
    try:
        page = Page.objects.get_by_owner(page_slug, request)
    except PermissionDenied:
        return redirect(Page.objects.get(slug=page_slug))
    except Page.DoesNotExist:
        return redirect('wiki-page', page_slug=page_slug)

    if request.POST:
        form = PageForm(request.POST, instance=page)
        if form.is_valid():
            form.save()
            message_object_updated(request, page)
            return redirect(page)
    else:
        form = PageForm(instance=page)

    return render(request, 'wiki/page-form.html',
                  get_context_wiki(request, 'wiki-page-form', {'form': form, 'page': page}))
Example #7
0
def item_edit(request, item_pk):
    item = get_object_or_404(Item, pk=item_pk)

    if request.POST.get('delete'):
        if item.is_container and item.containing():
            messages.error(request, _(
                u'Der Gegenstand %s ist ein Container und enthält andere Gegenstände. Daher kann dieser Gegenstand nicht gelöscht werden.' % item))
            return redirect(item)
        else:
            if item.container:
                target = item.container
            else:
                target = None
            message_object_deleted(request, item)
            item.delete()
            if target:
                return redirect(target)
            else:
                return redirect('inventory-homepage')

    if request.POST:
        form = ItemForm(request.POST, instance=item)
        form.fields.pop('multiply')
        if form.is_valid():
            item = form.save()
            message_object_updated(request, item)
            item.add_journal(request, _('Gegenstand wurde bearbeitet.'))
            return redirect(item)
    else:
        form = ItemForm(instance=item)
        form.fields.pop('multiply')

    c = {
        'object': item,
        'form': form
    }

    return render(request, 'inventory/item-edit.html', get_context_inventory(request, 'inventory-item-edit', c))
Example #8
0
def backstage_role_form(request, project, role):
    project = get_project(request, project, 'manage_roles')
    role = get_object_or_404(Role, pk=role, project=project)

    if request.POST:
        if request.POST.get('delete'):
            message_object_deleted(request, role)
            role.delete()
            message_object_deleted(request, role)
            return redirect('bs-role-list', project=project.pk)

        form_role = RoleForm(request.POST, instance=role)
        form_picture = RolePictureForm(request.POST, request.FILES, instance=role.picture)
        if form_role.is_valid():
            role = form_role.save(commit=False)

            if form_picture.is_valid():
                picture = form_picture.save(commit=False)
                if role.actor:
                    picture.title = _(u'%s als %s' % (role.actor, role.name))
                else:
                    picture.title = role.name
                picture.save()
                role.picture = picture

            role.save()
            message_object_updated(request, role)
            return redirect('bs-role-list', project=project.pk)

    else:
        form_role = RoleForm(instance=role)
        form_picture = RolePictureForm(instance=role.picture)

    return render(request, 'project/role-form.html',
                  get_context_backstage_project(request, project, 'bs-role-form',
                                                {'project': project, 'role': role, 'form_role': form_role,
                                                 'form_picture': form_picture}))
Example #9
0
def sepa_mandates(request):
    auto_open_modal = False
    if request.POST.get('delete', False):
        sepa_mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('delete'))
        if sepa_mandate.state is sepa_mandate.STATE_PENDING or sepa_mandate.keep_until() < datetime.now().date:
            message_object_deleted(request, sepa_mandate)
            sepa_mandate.delete()

    if request.POST.get('cancel', False):
        sepa_mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('cancel'))
        sepa_mandate.state = sepa_mandate.STATE_CANCELED
        sepa_mandate.save()
        message_object_updated(request, sepa_mandate)

    if 'sepa_activation' in request.POST:
        sepa_mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('sepa_activation'),
                                         state=SEPAMandate.STATE_PENDING)
        sepa_activate_form = SEPAMandateActivateForm(request.POST, instance=sepa_mandate)
        if sepa_activate_form.is_valid():
            obj = sepa_activate_form.save()
            message_object_updated(request, obj)
        else:
            auto_open_modal = True
    else:
        sepa_activate_form = SEPAMandateActivateForm()

    sepa_mandate_all = SEPAMandate.objects.all()

    c = {
        'view_title': SEPAMandate.objects.model._meta.verbose_name_plural,
        'sepa_activate_form': sepa_activate_form,
        'objects': sepa_mandate_all,
        'auto_open_modal': auto_open_modal
    }

    return render(request, 'funds/sepa-mandate-list.html', get_context_funds(request, 'funds-sepa-mandates-list', c))
Example #10
0
    def view_form(self, request, instance_pk):
        obj = get_object_or_404(self.model, pk=instance_pk)

        if request.POST:
            if request.POST.get('delete'):
                if not self.action_delete:
                    raise SuspiciousOperation

                message_object_deleted(request, obj)
                obj.delete()
                if self.parent:
                    return redirect(self.url_list, self.parent.pk)
                else:
                    return redirect(self.url_list)

            form = self.form(request.POST, instance=obj)
            if form.is_valid():
                form.save()
                message_object_updated(request, obj)

                if self.parent:
                    return redirect(self.url_list, self.parent.pk)
                else:
                    return redirect(self.url_list)

        else:
            form = self.form(instance=obj)

        c = {
            'form': form,
            'object': obj
        }

        c.update(self.context)

        return render(request, self.template_form, self.context_handler(request, self.url_form, c))
Example #11
0
def index(request, file_pk=None, directory_pk=None):
    # Neither file nor directory, show root directories
    if not file_pk and not directory_pk:
        directories = Directory.objects.get_root_directories(request.user.actor)
        directory = None
        current_file = None
        url_to_post = reverse('fs-index')
    else:
        # directory is given
        if directory_pk:
            current_file = None
            directory = get_object_or_404(Directory, pk=directory_pk)
            url_to_post = directory.get_absolute_url
        # or file?
        else:
            current_file = get_object_or_404(File, pk=file_pk)
            url_to_post = current_file.get_absolute_url
            directory = current_file.directory
        directories = directory.get_directories(request.user.actor)

    if directory:
        new_directory_form = NewDirectoryForm(user=request.user, initial={
            'parent': directory,
            'owner': directory.owner.pk,
            'restrict_read_to': directory.restrict_read_to.all(),
            'restrict_write_to': directory.restrict_write_to.all(),
        })
        edit_directory_form = EditDirectoryForm(instance=directory, user=request.user)
        new_file_form = NewFileForm(initial={
            'directory': directory
        })
        files = directory.get_files()
        is_owner = directory.is_owner(request.user.actor)
        can_write = directory.can_write(request.user.actor)
    else:
        new_directory_form = NewDirectoryForm(user=request.user)
        edit_directory_form = None
        new_file_form = None
        files = None
        is_owner = request.user.is_superuser
        can_write = request.user.is_superuser

    if directory and not directory.can_read(request.user.actor):
        messages.error(request, _(u'Dir fehlen die erforderlichen Leserechte für dieses Verzeichnis.'))
        raise PermissionDenied

    # maybe a post
    if 'action' in request.POST:
        # check for sufficient rights
        if directory and not directory.can_write(request.user.actor):
            messages.error(request, _(u'Du hast für das Verzeichnis nicht die erforderlichen Schreibrechte.'))
            raise PermissionDenied
        elif not directory and not request.user.is_superuser:
            messages.error(request, _(u'Du musst Administrator sein, um hier Verzeichnisse anzulegen.'))
            raise PermissionDenied

        # what's the action?
        # create file
        if request.POST['action'] == 'create_file':
            if directory and can_write:
                new_file_form = NewFileForm(request.POST, request.FILES)
                if new_file_form.is_valid():
                    new_file = new_file_form.save(commit=False)
                    new_file.uploader = request.user.actor
                    new_file.filename = request.FILES['file'].name
                    new_file.save()
                    message_object_created(request, new_file)
                    return redirect(new_file)

        # delete file
        if request.POST['action'] == 'delete_file':
            if current_file and current_file.can_write(request.user.actor):
                message_object_deleted(request, current_file)
                target = current_file.directory
                current_file.delete()
                return redirect(target)

        # create directory
        if request.POST['action'] == 'create_directory':
            if can_write:
                new_directory_form = NewDirectoryForm(request.POST, user=request.user)
                if new_directory_form.is_valid():
                    new_directory = new_directory_form.save()
                    message_object_created(request, new_directory)
                    return redirect(new_directory)

        # modify directory settings
        if request.POST['action'] == 'edit_directory' and directory:
            if is_owner:
                edit_directory_form = EditDirectoryForm(request.POST, instance=directory, user=request.user)
                if edit_directory_form.is_valid():
                    edit_directory = edit_directory_form.save()
                    message_object_updated(request, edit_directory)
                    return redirect(edit_directory)

        # delete directory
        if request.POST['action'] == 'delete_directory':
            if is_owner:
                if directory.parent_id:
                    target = directory.parent
                else:
                    target = 'fs-index'
                message_object_deleted(request, directory)
                directory.delete()
                return redirect(target)

        # download a file
        if request.POST['action'] == 'download':
            response = HttpResponse(current_file.file.read(),
                                    content_type=current_file.content_type or 'application/force-download')
            response['Content-Length'] = current_file.size
            response['Content-Disposition'] = 'attachment; filename="%s"' % current_file.filename
            return response

    c = {
        'directory': directory,
        'directories': directories,
        'files': files,
        'file': current_file,
        'new_directory_form': new_directory_form,
        'new_file_form': new_file_form,
        'edit_directory_form': edit_directory_form,
        'current_item': current_file or directory,
        'url_to_post': url_to_post,
        'can_write': can_write,
        'is_owner': is_owner
    }

    return render(request, 'filestorage/index.html', get_context_filestorage(request, 'fs-index', c))
Example #12
0
def actor_finance(request):
    actor = request.user.actor

    # First: collect membership fee status
    periods = Period.objects.all()[:5]
    status = {}
    if len(periods) > 0:
        for period in periods:
            status.update({period.pk: {'paid': False, 'amount': 0}})
            status[period.pk] = actor.get_membership_fee_paid(period)
        actor.fee_status = status

    # Second: prepare and execute refund data form
    if request.POST and 'refund_obligee' in request.POST and 'refund_iban' in request.POST and 'refund_swift_bic' in request.POST:
        actor_refund_data_form = ActorRefundDataForm(request.POST, instance=actor)
        if actor_refund_data_form.is_valid():
            messages.success(request, _(u'Deine Konto-Informationen für Erstattungen wurden aktualisiert.'))
            actor_refund_data_form.save()
    else:
        actor_refund_data_form = ActorRefundDataForm(instance=actor)

    # Third: prepare sepa mandate form

    if 'new_sepa' == request.POST.get('form', False):
        actor_sepa_mandate_form = SEPAMandateCreateForm(request.POST)
        actor_sepa_mandate_form.instance.actor = request.user.actor
        if actor_sepa_mandate_form.is_valid():
            sepa_mandate = actor_sepa_mandate_form.save()
            message_object_created(request, sepa_mandate)
    else:
        actor_sepa_mandate_form = SEPAMandateCreateForm()

    if request.POST.get('delete', False):
        mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('delete'), actor=actor)
        if mandate.state is SEPAMandate.STATE_PENDING or not mandate.keep_until() or mandate.keep_until() < datetime.now().date():
            message_object_deleted(request, mandate)
            mandate.delete()

    if request.POST.get('revoke', False):
        mandate = get_object_or_404(SEPAMandate, pk=request.POST.get('delete'), actor=actor)
        message_object_updated(request, mandate)
        mandate.state = mandate.STATE_REVOKED
        mandate.save()

    active_mandate = SEPAMandate.objects.get_active(actor=actor)
    pending_mandate = SEPAMandate.objects.get_pending(actor=actor)
    other_mandates = SEPAMandate.objects.get_other(actor=actor)

    # Fourth: creditor accounts

    creditor_accounts = Account.objects.filter(is_creditor=True)

    try:
        current_period = periods[0]
    except ValueError:
        current_period = None

    return render(request, 'backstage/actor-finance.html', get_context_backstage(request, 'actor-finance', {
        'actor': actor, 'periods': periods, 'actor_refund_data_form': actor_refund_data_form, 'actor_sepa_mandate_form':
        actor_sepa_mandate_form, 'active_mandate': active_mandate, 'pending_mandate': pending_mandate,
        'other_mandates': other_mandates, 'creditor_accounts': creditor_accounts, 'current_period': current_period}))