Example #1
0
def archived_forms(request):
    """ Returns a page that includes a list of archived forms """
    template_settings = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings.settings_dict()
    forms = Form.objects.all().distinct("form_id")
    forms = [{
        "id":
        f.form_id,
        "name":
        f.name,
        "description":
        f.description,
        "url":
        reverse('constellation_forms:view_form', args=[f.form_id]),
        "edit":
        reverse('constellation_forms:manage_create_form', args=[f.form_id])
    } for f in forms
             if (request.user.has_perm("constellation_forms.form_owned_by", f)
                 and f.archived)]

    forms = [{"name": "Archived Forms", "list_items": forms}]

    return render(
        request, 'constellation_forms/list.html', {
            'template_settings': template_settings,
            'list_type': 'Archived Forms',
            'lists': forms,
        })
Example #2
0
def view_ticket(request, ticket_id):
    """Return the base template that will call the API to display the
    ticket with all replies"""
    # check permissions by user and group
    ticket = Ticket.objects.get(pk=ticket_id)
    box = ticket.box
    box_perms = get_perms(request.user, box)

    if ((ticket.owner == request.user) or ('action_read_box' in box_perms)):

        template_settings_object = GlobalTemplateSettings(
            allowBackground=False)
        template_settings = template_settings_object.settings_dict()
        replyForm = ReplyForm()
        ticketForm = TicketForm(instance=ticket)

        return render(
            request, 'constellation_ticketbox/ticket.html', {
                'form': replyForm,
                'status_form': ticketForm,
                'id': ticket_id,
                'template_settings': template_settings,
                'ticket': ticket,
                'box': box
            })
    else:
        return HttpResponseNotFound("You do not have permissions"
                                    " for this ticket.")
Example #3
0
    def get(self, request, form_id=None):
        """ Returns a page that allows for the creation of new forms """
        # We can't use a method decorator here, because we need to check
        # different conditions depending on whether or not a form_id is given
        # Someone with add_form can add a new form or edit an existing form,
        # and form owners can edit existing forms that they own
        if not Form.can_edit(request.user, form_id):
            return redirect("%s?next=%s" % (settings.LOGIN_URL, request.path))

        template_settings = GlobalTemplateSettings(allowBackground=False)
        template_settings = template_settings.settings_dict()
        groups = [(g.name, g.pk) for g in Group.objects.all()]

        form = None
        form_data = None

        if form_id is not None:
            form = Form.objects.filter(form_id=form_id).first()
            form_data = serializers.serialize(
                "json",
                Form.objects.filter(form_id=form_id),
            )

        return render(
            request, "constellation_forms/create-form.html", {
                "form": form,
                "form_data": form_data,
                "visible_groups": groups,
                "template_settings": template_settings,
            })
Example #4
0
def manage_stages(request):
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    stageForm = StageForm()
    return render(request, "constellation_orderboard/manage-stages.html", {
        'form': stageForm,
        'template_settings': template_settings,
    })
Example #5
0
def view_boxes(request):
    """Return the base template that will call the API to display
    a list of boxes"""
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()

    return render(request, 'constellation_ticketbox/view-list.html',
                  {'template_settings': template_settings})
Example #6
0
def view_list(request):
    '''Return the base template that will call the API to display
    a list of boards'''
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()

    return render(request, 'constellation_orderboard/view-list.html', {
        'template_settings': template_settings,
    })
Example #7
0
def view_board_archive(request, board_id):
    '''Return the base template that will call the API to display the
    board's archived cards'''
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()

    return render(request, 'constellation_orderboard/archive.html', {
        'id': board_id,
        'template_settings': template_settings,
    })
Example #8
0
def manage_boxes(request):
    """Return a template that will allow users to manage all boxes"""
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    boxForm = BoxForm()
    groups = [(g.name, g.pk) for g in Group.objects.all()]
    return render(request, 'constellation_ticketbox/manage-boxes.html', {
        'form': boxForm,
        'template_settings': template_settings,
        'groups': groups
    })
Example #9
0
def manage_boards(request):
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    boardForm = BoardForm()
    groups = [(g.name, g.pk) for g in Group.objects.all()]

    return render(
        request, 'constellation_orderboard/manage-boards.html', {
            'form': boardForm,
            'template_settings': template_settings,
            'groups': groups,
        })
Example #10
0
def list_forms(request):
    """ Returns a page that includes a list of available forms """
    template_settings = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings.settings_dict()
    forms = Form.objects.all().distinct("form_id")
    owned_forms = [
        {
            "id":
            f.form_id,
            "name":
            f.name,
            "description":
            f.description,
            "url":
            reverse('constellation_forms:view_form', args=[f.form_id]),
            "edit":
            reverse('constellation_forms:manage_create_form', args=[f.form_id])
        } for f in forms
        if request.user.has_perm("constellation_forms.form_owned_by", f)
        and not f.archived
    ]

    available_forms = [
        {
            "id": f.form_id,
            "name": f.name,
            "description": f.description,
            "url": reverse('constellation_forms:view_form', args=[f.form_id]),
        } for f in forms
        if request.user.has_perm("constellation_forms.form_visible", f)
        and f.id not in [a['id'] for a in owned_forms] and not f.archived
    ]

    archived = any(
        request.user.has_perm("constellation_forms.form_owned_by", f)
        and f.archived for f in forms)

    forms = [{
        "name": "Owned Forms",
        "list_items": owned_forms
    }, {
        "name": "Available Forms",
        "list_items": available_forms
    }]

    return render(
        request, 'constellation_forms/list.html', {
            'template_settings': template_settings,
            'list_type': 'Forms',
            'archived': archived,
            'lists': forms,
        })
Example #11
0
def view_show_user(request):
    '''Return the base template that will call the API to display
    the '''
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    form = DeviceForm(initial={"owner": request.user})
    username = request.user.username

    return render(request, 'constellation_devicemanager/view-list.html', {
        'template_settings': template_settings,
        'form': form,
        'username': username,
    })
Example #12
0
def view_box_archive(request, box_id):
    """Return the base template that will call the API to display the
    box with all visible archived tickets for a box"""
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    box = Box.objects.get(pk=box_id)

    return render(
        request, 'constellation_ticketbox/box-archive.html', {
            'id': box_id,
            'template_settings': template_settings,
            'box': box,
            'user_id': request.user.id
        })
Example #13
0
def manage_board_edit(request, board_id):
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    board = Board.objects.get(pk=board_id)
    boardForm = BoardForm(instance=board)
    groups = board.get_board_permissions()

    return render(
        request, 'constellation_orderboard/edit-board.html', {
            'form': boardForm,
            'board_id': board_id,
            'template_settings': template_settings,
            'groups': groups,
        })
Example #14
0
def manage_box_edit(request, box_id):
    """Return a template that will allow users to edit a box"""
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    box = Box.objects.get(pk=box_id)
    boxForm = BoxForm(instance=box)
    groups = box.get_box_permissions()
    return render(
        request, 'constellation_ticketbox/edit-box.html', {
            'form': boxForm,
            'box_id': box_id,
            'template_settings': template_settings,
            'groups': groups
        })
Example #15
0
def view_board(request, board_id):
    '''Return the base template that will call the API to display the
    entire board with all the cards'''
    template_settings_object = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings_object.settings_dict()
    newForm = CardForm()
    editForm = CardForm(prefix="edit")
    board = Board.objects.get(pk=board_id)

    return render(
        request, 'constellation_orderboard/board.html', {
            'form': newForm,
            'editForm': editForm,
            'id': board_id,
            'template_settings': template_settings,
            'board': board,
        })
Example #16
0
    def get(self, request, form_submission_id):
        """ Returns a page that displays a specific form submission instance"""
        if not FormSubmission.can_view(request.user, form_submission_id):
            return redirect("%s?next=%s" % (settings.LOGIN_URL, request.path))
        template_settings = GlobalTemplateSettings(allowBackground=False)
        template_settings = template_settings.settings_dict()
        submission = FormSubmission.objects.get(pk=form_submission_id)
        log_entries = Log.objects.filter(submission=submission)
        submission_data = []
        for index, value in enumerate(submission.submission):
            element = {}
            for tag in ('title', 'description', 'type', 'steps'):
                if tag not in submission.form.elements[index]:
                    continue
                element[tag] = submission.form.elements[index][tag]
            element['value'] = value
            submission_data.append(element)

        return render(
            request, 'constellation_forms/view-submission.html', {
                'can_approve':
                FormSubmission.can_approve(request.user, form_submission_id),
                'template_settings':
                template_settings,
                'name':
                submission.form.name,
                'description':
                submission.form.description,
                'state':
                submission.state,
                'id':
                form_submission_id,
                'widgets':
                submission_data,
                'form_id':
                submission.form.form_id,
                'version':
                submission.form.version,
                'log_entries':
                log_entries,
            })
Example #17
0
    def get(self, request, form_id, submission_id=None):
        """ Returns a page that allows for the submittion of a created form """
        template_settings = GlobalTemplateSettings(allowBackground=False)
        template_settings = template_settings.settings_dict()
        form = Form.objects.filter(form_id=form_id).first()
        submission = None
        if submission_id:
            submission = get_object_or_404(FormSubmission,
                                           form__form_id=form_id,
                                           id=submission_id,
                                           owner=request.user,
                                           state__lt=3)
            for i, _ in enumerate(form.elements):
                form.elements[i]["value"] = submission.submission[i]

        return render(
            request, 'constellation_forms/submit-form.html', {
                'form': form,
                'template_settings': template_settings,
                'submission': submission
            })
Example #18
0
def list_submissions(request):
    """ Returns a page that includes a list of submitted forms """
    template_settings = GlobalTemplateSettings(allowBackground=False)
    template_settings = template_settings.settings_dict()
    submissions = FormSubmission.objects.all()

    staff = request.user.has_perm("constellation_forms.form_create")
    filter_query = {}
    if "username" in request.GET and len(request.GET['username']) > 0:
        r_username = request.GET['username']
        if User.objects.filter(username=r_username).exists():
            temp_user = User.objects.get(username=r_username)
            filter_query["owner"] = temp_user
    if "form" in request.GET and len(request.GET['form']) > 0:
        r_form = request.GET['form']
        if Form.objects.filter(form_id=r_form).exists():
            temp_form = list(Form.objects.filter(form_id=r_form))
            filter_query["form__in"] = temp_form

    if staff and len(filter_query) > 0:
        submissions = FormSubmission.objects.filter(**filter_query)
    else:
        submissions = FormSubmission.objects.all()

    forms = [{
        "name": "Pending Submissions",
        "list_items": []
    }, {
        "name": "Incoming Submissions",
        "list_items": []
    }, {
        "name": "Done Submissions",
        "list_items": []
    }]

    forms[0]["list_items"] = [{
        "name":
        f.form.name,
        "description":
        f.modified,
        "state":
        f.state,
        "pk":
        f.pk,
        "url":
        reverse('constellation_forms:view_form_submission', args=[f.pk]),
        "edit":
        reverse('constellation_forms:view_form', args=[f.form.form_id, f.pk])
    } for f in submissions if request.user == f.owner and f.state <= 2]

    forms[1]["list_items"] = [
        {
            "name":
            f.form.name,
            "owner":
            f.owner.username,
            "description":
            f.modified,
            "state":
            f.state,
            "pk":
            f.pk,
            "url":
            reverse('constellation_forms:view_form_submission', args=[f.pk]),
        } for f in submissions
        if (request.user.has_perm("constellation_forms.form_owned_by", f.form)
            and (f.state <= 1))
    ]

    forms[2]["list_items"] = [
        {
            "name":
            f.form.name,
            "owner":
            f.owner.username,
            "description":
            f.modified,
            "state":
            f.state,
            "pk":
            f.pk,
            "url":
            reverse('constellation_forms:view_form_submission', args=[f.pk]),
        } for f in submissions
        if (request.user.has_perm("constellation_forms.form_owned_by", f.form)
            or request.user == f.owner) and (f.state > 2)
    ]

    num_users = len(
        set([f["owner"] for f in forms[1]["list_items"]])
        | set([f["owner"] for f in forms[2]["list_items"]]))

    if num_users > 1:
        num_users = True
    else:
        num_users = False

    return render(
        request, 'constellation_forms/list.html', {
            'template_settings': template_settings,
            'list_type': 'Form Submissions',
            'lists': forms,
            'forms': Form.objects.all().distinct('form_id'),
            'show_username_filter': num_users,
        })