Skip to content

Commit

Permalink
Initial template for adding new web resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius O committed Feb 25, 2016
1 parent b699c8f commit 21b188a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
51 changes: 50 additions & 1 deletion geokey_webresources/templates/wr_add_webresource.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,67 @@

<div class="container">
<div class="row">
<form role="form" class="col-md-8 col-md-offset-2" method="POST" action="{% url 'geokey_webresources:webresource_add' project.id %}" novalidate>
<form role="form" id="form" class="col-md-8 col-md-offset-2" method="POST" action="{% url 'geokey_webresources:webresource_add' project.id %}" enctype="multipart/form-data" novalidate>
{% csrf_token %}

<h3 class="header">
{% if project.islocked %}<span class="glyphicon glyphicon-lock text-warning" aria-hidden="true"></span>{% endif %}
<span>Add new web resource for {{ project.name }}</span>
</h3>

<div class="form-group">
<label for="name" class="control-label">Name (required)</label>
<input type="text" id="name" class="form-control input-lg" name="name" maxlength="100" required />
</div>

<div class="form-group">
<label for="description" class="control-label">Description</label>
<textarea id="description" class="form-control input-lg" rows="5" name="description"></textarea>
</div>

<div class="form-group">
<label for="data_format" class="control-label">Data format (required)</label>
<select id="data_format" class="form-control input-lg" name="data_format" required>
<option value="">Please select a value</option>
{% for key, value in data_formats %}
<option value="{{ key }}">{{ value }}</option>
{% endfor %}
</select>
</div>

<div class="form-group">
<label for="name" class="control-label">URL (required)</label>
<input type="url" id="url" class="form-control input-lg" name="url" maxlength="250" required />
</div>

<div class="form-group">
<label for="symbol" class="control-label">Symbol</label>
<input type="file" id="symbol" name="symbol" data-target="symbol" />
</div>

<div class="form-group">
<button type="submit" class="btn btn-primary">Save</button>
<a href="{% url 'geokey_webresources:all_webresources' project.id %}" class="btn btn-link" role="button">Cancel</a>
</div>
</form>
</div>
</div>
{% endblock %}

{% block libraries %}
<link rel="stylesheet" href="/static/lib/bootstrap-fileinput/css/bootstrap-fileinput.min.css">
<script src="/static/lib/bootstrap-fileinput/js/bootstrap-fileinput.min.js"></script>

<script src="/static/js/admin.ui.forms.validate.js"></script>
<script src="/static/js/admin.ui.fileinput.js"></script>

<script>
// Initialise file upload
$('input:file').each(function() {
Ui.FileInput.init($(this), {
showUpload: false,
showCancel: false
});
});
</script>
{% endblock %}
3 changes: 3 additions & 0 deletions geokey_webresources/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from .model_factories import WebResourceFactory
from ..helpers.context_helpers import does_not_exist_msg
from ..base import FORMAT
from ..models import WebResource
from ..views import (
IndexPage,
Expand Down Expand Up @@ -343,6 +344,7 @@ def test_get_with_admin(self):
'PLATFORM_NAME': get_current_site(self.request).name,
'user': self.request.user,
'messages': get_messages(self.request),
'data_formats': FORMAT,
'project': self.project
}
)
Expand Down Expand Up @@ -502,6 +504,7 @@ def test_get_with_admin(self):
'PLATFORM_NAME': get_current_site(self.request).name,
'user': self.request.user,
'messages': get_messages(self.request),
'data_formats': FORMAT,
'project': self.project,
'webresource': self.webresource
}
Expand Down
23 changes: 22 additions & 1 deletion geokey_webresources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from geokey.projects.views import ProjectContext

from .helpers.context_helpers import does_not_exist_msg
from .base import FORMAT
from .models import WebResource


Expand Down Expand Up @@ -50,6 +51,24 @@ class AddWebResourcePage(LoginRequiredMixin, ProjectContext, TemplateView):

template_name = 'wr_add_webresource.html'

def get_context_data(self, *args, **kwargs):
"""
GET method for the template.
Return the context to render the view. Overwrite the method by adding
available data formats to the context.
Returns
-------
dict
Context.
"""
return super(AddWebResourcePage, self).get_context_data(
data_formats=FORMAT,
*args,
**kwargs
)


class WebResourceContext(LoginRequiredMixin, ProjectContext, TemplateView):
"""Get web resource mixin."""
Expand All @@ -59,7 +78,7 @@ def get_context_data(self, project_id, webresource_id, *args, **kwargs):
GET method for the template.
Return the context to render the view. Overwrite the method by adding
a web resource to the context.
a web resource and available data formats to the context.
Returns
-------
Expand All @@ -72,6 +91,8 @@ def get_context_data(self, project_id, webresource_id, *args, **kwargs):
**kwargs
)

context['data_formats'] = FORMAT

try:
context['webresource'] = WebResource.objects.get(
pk=webresource_id,
Expand Down

0 comments on commit 21b188a

Please sign in to comment.