okcashpro/okshop

View on GitHub
shop/templates/shop/editkeys.html

Summary

Maintainability
Test Coverage
{% extends "shop/base.html" %}
{% block title %}Manage keys and files{% endblock %}
{% block body %}
<div class="row">
    <div class="col-sm-8">
        <h1 style="margin-top: 0">Keys and files: "{{ product }}"</h1>
    </div>
    <div class="col-sm-4">
        <a href="{% url 'shop:viewproduct' product.id %}" class="btn btn-default">View product</a>
        <a href="{% url 'shop:editproduct' product.id %}" class="btn btn-default">Edit product</a>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <h4>Files</h4>
    </div>
    <div class="panel-body">
        <p>You can upload files up to 50MB in size for your buyers to download.</p>

        <button data-toggle="modal" data-target="#newfile" type="button" class="btn btn-block btn-primary">Upload file</button>

        {% if product.digitalfile_set.all %}
        <h4>Your files</h4>
        {% for file in product.digitalfile_set.all %}
        <div class="row list-with-lines">
            <div class="col-sm-10">
                <a href="{% url 'shop:download' file.id %}">{{ file.name }}</a> <em>{{ file.file.size|filesizeformat }}</em>
            </div>
            <div class="col-sm-2">
                <button class="btn btn-default" data-toggle="modal" data-target="#modal-{{file.id}}"><i class="fa fa-trash"></i> Delete</button>
            </div>
        </div>
        {% endfor %}
        {% endif %}
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <h4>Keys</h4>
    </div>
    <div class="panel-body">
        <p>You can use this to distribute a different key to each person</p>
        {% if product.digitalkeyset_set %}
        <div class="row">
            <div class="col-sm-10"><strong>Keyset name</strong></div>
            <div class="col-sm-2"><strong>Keys remaining</strong></div>
        </div>
        {% for keyset in product.digitalkeyset_set.all %}
        <div class="row">
            <div class="col-sm-10"><a href="{% url 'shop:managekey' product.id keyset.id %}">{{ keyset.name }}</a></div>
            <div class="col-sm-2">{{ keyset.get_stock }}</div>
        </div>
        {% endfor %}
        {% else %}
        <p>There are no key sets!</p>
        {% endif %}
        <a href="{% url 'shop:managekey' product.id %}" class="btn btn-block btn-primary">Create keyset</a>
    </div>
</div>
{% endblock %}
{% block modals %}
{% for file in product.digitalfile_set.all %}
<div class="modal fade" id="modal-{{file.id}}" aria-labelledby="modal-{{file.id}}-label" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="modal-{{file.id}}-label">Confirm deletion</h4>
            </div>
            <div class="modal-body">
                <strong>Are you sure you want to delete {{ file.name }}?</strong>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a href="{% url 'shop:deletefile' file.id %}" class="btn btn-danger">Delete</a>
            </div>
        </div>
    </div>
</div>
{% endfor %}
<div class="modal fade" id="newfile" aria-labelledby="modal-newfile-label" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="modal-newfile-label">Upload file</h4>
            </div>
            <form method="POST" action="{% url 'shop:uploadfilenoapi' product.id %}" enctype="multipart/form-data">
                {% csrf_token %}
                <div class="modal-body">
                        <p>Upload a file up to 50MB for your buyers to download</p>
                        <div class="form-group">
                            <label for="name" class="control-label">Name</label>
                            <input type="text" name="name" class="form-control" id="name" placeholder="Name">
                        </div>
                        <div class="form-group">
                            <label for="description" class="control-label">Description (optional)</label>
                            <textarea name="description" id="description" class="form-control vresize" placeholder="Description"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="file" class="control-label">File</label>
                            <input type="file" name="file" id="file">
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary">Upload</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}