Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
download sample form
Browse files Browse the repository at this point in the history
  • Loading branch information
risufaj committed Nov 5, 2018
1 parent abdac1e commit a01784b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
19 changes: 17 additions & 2 deletions request/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unicodedata import normalize

from django.apps import apps
from django.http import HttpResponse, JsonResponse
from django.http import HttpResponse, JsonResponse,Http404
from django.conf import settings
from django.db.models import Prefetch
from django.core.mail import send_mail
Expand All @@ -27,7 +27,7 @@
)
from .models import Request, FileRequest
from .serializers import RequestSerializer, RequestFileSerializer

import os
User = get_user_model()
Library = apps.get_model('library', 'Library')
Sample = apps.get_model('sample', 'Sample')
Expand Down Expand Up @@ -385,6 +385,21 @@ def get_files_after_upload(self, request):
'data': data,
})


@action(methods=['get'],detail=False)
def download_RELACS_Pellets_Abs_form(self,request):
print(settings.FILES_PATH)
file_path = os.path.join(settings.FILES_PATH, 'RELACS_Pellets_Abs_form.xlsx')
print(file_path)

with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
return response




@action(methods=['get'], detail=True)
def download_deep_sequencing_request(self, request, pk=None): # pragma: no cover
""" Generate a deep sequencing request form in PDF. """
Expand Down
10 changes: 9 additions & 1 deletion static/main-hub/app/view/libraries/BatchAddWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ Ext.define('MainHub.view.libraries.BatchAddWindow', {
margin: '0 0 0 30px',
html: '<span id="edit-hint"><strong>Hint:</strong> To edit multiple cells at once (Excel-like), ' +
'please select a cell, press Esc, paste data</span>'
}
},
{
text: 'Download RELACS Pellets Abs form',
margin: '0 0 0 30px',
itemId: 'download-sample-form',
downloadUrl: 'api/requests/download_RELACS_Pellets_Abs_form',
iconCls: 'fa fa-download fa-lg',

},
],
hidden: true
},
Expand Down
19 changes: 19 additions & 0 deletions static/main-hub/app/view/libraries/BatchAddWindowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ Ext.define('MainHub.view.libraries.BatchAddWindowController', {

'#save-button': {
click: 'save'
},

'#download-sample-form':{
click: 'downloadSampleForm'
}
}
},



boxready: function (wnd) {
if (wnd.mode === 'edit') {
if (wnd.type === 'Library') {
Expand Down Expand Up @@ -78,10 +84,12 @@ Ext.define('MainHub.view.libraries.BatchAddWindowController', {
if (btn.itemId === 'library-card-button') {
wnd.recordType = 'Library';
wnd.setTitle('Add Libraries');
wnd.getComponent('create-empty-records').getComponent('download-sample-form').setVisible(false);
configuration = this.getLibraryGridConfiguration(wnd.mode);
} else {
wnd.recordType = 'Sample';
wnd.setTitle('Add Samples');
wnd.getComponent('create-empty-records').getComponent('download-sample-form').setVisible(true);
configuration = this.getSampleGridConfiguration(wnd.mode);
}

Expand Down Expand Up @@ -138,6 +146,17 @@ Ext.define('MainHub.view.libraries.BatchAddWindowController', {
}).showAt(e.getXY());
},

downloadSampleForm: function (btn) {
console.log(btn.downloadUrl)
var form = Ext.create('Ext.form.Panel', { standardSubmit: true });

form.submit({
url: btn.downloadUrl,
method: 'GET',

});
},

applyToAll: function (record, dataIndex) {
var store = record.store;

Expand Down
1 change: 1 addition & 0 deletions wui/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
FILES_PATH = os.path.join(BASE_DIR,MEDIA_ROOT,'files')

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
Expand Down

0 comments on commit a01784b

Please sign in to comment.