diff options
author | Jayaram R Pai | 2014-07-31 13:20:29 +0530 |
---|---|---|
committer | Jayaram R Pai | 2014-07-31 13:20:29 +0530 |
commit | 4473cee7e1be996dccb31c12243e543ed8e0ca39 (patch) | |
tree | 1d26380ad4860ccda9b844aa658959127cfae300 | |
parent | 4fc8de24f4e26719ddb043f4779cdbc9914475bb (diff) | |
download | scilab-on-cloud-4473cee7e1be996dccb31c12243e543ed8e0ca39.tar.gz scilab-on-cloud-4473cee7e1be996dccb31c12243e543ed8e0ca39.tar.bz2 scilab-on-cloud-4473cee7e1be996dccb31c12243e543ed8e0ca39.zip |
added example file models, requirements.txt
-rw-r--r-- | .gitignore | 0 | ||||
-rw-r--r-- | requirements.txt | 5 | ||||
-rw-r--r-- | static/tmp/a.sci | 2 | ||||
-rw-r--r-- | static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci | 3 | ||||
-rw-r--r-- | static/tmp/out.txt | 74 | ||||
-rw-r--r-- | static/website/js/cloud.js | 14 | ||||
-rw-r--r-- | website/helpers.py | 17 | ||||
-rw-r--r-- | website/models.py | 35 | ||||
-rw-r--r-- | website/urls.py | 1 | ||||
-rw-r--r-- | website/views.py | 24 |
10 files changed, 87 insertions, 88 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.gitignore diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..387c763 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +Django==1.5 +MySQL-python==1.2.4 +argparse==1.2.1 +distribute==0.7.3 +wsgiref==0.1.2 diff --git a/static/tmp/a.sci b/static/tmp/a.sci deleted file mode 100644 index ac1be22..0000000 --- a/static/tmp/a.sci +++ /dev/null @@ -1,2 +0,0 @@ -exec('/home/cheese/cloud/soc/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci') -quit diff --git a/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci b/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci deleted file mode 100644 index 2d35505..0000000 --- a/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci +++ /dev/null @@ -1,3 +0,0 @@ -mode(2); - -quit();
\ No newline at end of file diff --git a/static/tmp/out.txt b/static/tmp/out.txt deleted file mode 100644 index 26c869c..0000000 --- a/static/tmp/out.txt +++ /dev/null @@ -1,74 +0,0 @@ - - - --->lines(0) - - --->disp("Example 2.1") - - Example 2.1 - --->printf("\n") - - --->printf("Given") -Given --->disp("Resistance used is 4 ohm") - - Resistance used is 4 ohm - --->disp("Current flow is i=2.5*sin(w*t)") - - Current flow is i=2.5*sin(w*t) - --->disp("Angular frequency(w)=500 rad/s") - - Angular frequency(w)=500 rad/s - - --->R=4; - --->iamp=2.5;w=500; - --->t=0:0.001:0.012566 - t = - - 0. 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01 0.011 0.012 - --->i=2.5*sin(w*t) - i = - - 0. 1.1985638 2.1036775 2.4937375 2.2732436 1.4961804 0.3528000 - 0.8769581 - 1.8920062 - 2.4438253 - 2.3973107 - 1.7638508 - 0.6985387 - - - --->Vamp=iamp*R; - --->printf("v=%d*sin(%d*t)(V)\n",Vamp,w) -v=10*sin(500*t)(V) - - --->pamp=iamp*iamp*R; - --->printf("p=%d(sin(%d*t))^2(W)\n",pamp,w) -p=25(sin(500*t))^2(W) - --->p=pamp*sin(w*t)^2; - - --->//On integrating p with respect to t - --->W=25*(t/2-sin(2*w*t)/(4*w)) - W = - - 0. 0.0019816 0.0136338 0.035736 0.0594600 0.0744866 0.0784927 0.0792877 0.0876330 0.1073485 0.1318003 0.1499999 0.1567072 - - --->funcion p=f(t),p=pamp*sin(w*t)^2,endfunction -funcion p=f(t),p=pamp*sin(w*t)^2,endfunction - !--error 4 -Undefined variable: funcion -at line 26 of exec file called by : -exec('/home/cheese/cloud/soc/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci') - - diff --git a/static/website/js/cloud.js b/static/website/js/cloud.js index 644d7fd..6b56606 100644 --- a/static/website/js/cloud.js +++ b/static/website/js/cloud.js @@ -84,6 +84,20 @@ $(document).ready(function() { }); }); + $(document).on("change", "#examples", function(){ + $.ajax({ + url: "/ajax-code/", + type: "POST", + data: { + example_id: $("#examples").val() + }, + dataType: "html", + success: function(data) { + editor.setValue(data); + } + }); + }); + /* Execute the code */ $("#execute").click(function() { var csrfmiddlewaretoken = $("[name='csrfmiddlewaretoken']").val(); diff --git a/website/helpers.py b/website/helpers.py index c5aad51..eac7720 100644 --- a/website/helpers.py +++ b/website/helpers.py @@ -5,10 +5,17 @@ import subprocess from soc.settings import PROJECT_DIR -def scilab_run(code, token): +def scilab_run(code, token): + #Check for system commands + system_commands = re.compile( + 'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|unix_x\(.*\)|unix_s\(.*\)' + ) + if system_commands.search(code): + return "System Commands not allowed" + #Remove all clear; - code = code.replace('clear','') - code = code.replace(r'clear.*all','') + code = re.sub(r'clear.*all|clear|clc\(\)|clc', '', code) + plot_exists = False #Finding the plot and appending xs2jpg function @@ -43,7 +50,7 @@ def scilab_run(code, token): #traps even syntax errors eg: endfunton f = open(file_path, "w") f.write('mode(2);\n') - f.write(code) + f.write(unicode(code)) f.write('\nquit();') f.close() @@ -64,4 +71,6 @@ def scilab_run(code, token): def trim(output): #for future use + output = re.sub(r'\n \n \n', '\n', output) + #print repr(output) return output diff --git a/website/models.py b/website/models.py index 76d07b7..5c7bb48 100644 --- a/website/models.py +++ b/website/models.py @@ -1,6 +1,5 @@ from django.db import models - """ Models from Scilab Database created using inspectdb Use it with the "scilab" database eg:using("scilab") @@ -68,3 +67,37 @@ class TextbookCompanionExample(models.Model): class Meta: db_table = 'textbook_companion_example' +class TextbookCompanionExampleFiles(models.Model): + id = models.IntegerField(primary_key=True) + example_id = models.IntegerField() + filename = models.CharField(max_length=255L) + filepath = models.CharField(max_length=500L) + filemime = models.CharField(max_length=255L) + filesize = models.IntegerField() + filetype = models.CharField(max_length=1L) + caption = models.CharField(max_length=100L) + timestamp = models.IntegerField() + class Meta: + db_table = 'textbook_companion_example_files' + +class TextbookCompanionExampleDependency(models.Model): + id = models.IntegerField(primary_key=True) + example_id = models.IntegerField() + dependency_id = models.IntegerField() + approval_status = models.IntegerField() + timestamp = models.IntegerField() + class Meta: + db_table = 'textbook_companion_example_dependency' + +class TextbookCompanionDependencyFiles(models.Model): + id = models.IntegerField(primary_key=True) + preference_id = models.IntegerField() + filename = models.CharField(max_length=255L) + filepath = models.CharField(max_length=500L) + filemime = models.CharField(max_length=255L) + filesize = models.IntegerField() + caption = models.CharField(max_length=100L) + description = models.TextField() + timestamp = models.IntegerField() + class Meta: + db_table = 'textbook_companion_dependency_files' diff --git a/website/urls.py b/website/urls.py index 8f6b630..b4d782a 100644 --- a/website/urls.py +++ b/website/urls.py @@ -7,5 +7,6 @@ urlpatterns = patterns('', url(r'^ajax-books/$', 'website.views.ajax_books', name='ajax_books'), url(r'^ajax-chapters/$', 'website.views.ajax_chapters', name='ajax_chapters'), url(r'^ajax-examples/$', 'website.views.ajax_examples', name='ajax_examples'), + url(r'^ajax-code/$', 'website.views.ajax_code', name='ajax_code'), url(r'^ajax-execute/$', 'website.views.ajax_execute', name='ajax_execute'), ) diff --git a/website/views.py b/website/views.py index a26ae91..aba54a2 100644 --- a/website/views.py +++ b/website/views.py @@ -7,7 +7,8 @@ from django.db.models import Q from website.helpers import scilab_run from website.models import TextbookCompanionPreference,\ TextbookCompanionProposal, TextbookCompanionChapter,\ - TextbookCompanionExample + TextbookCompanionExample, TextbookCompanionExampleFiles,\ + TextbookCompanionExampleDependency, TextbookCompanionDependencyFiles def index(request): context = {} @@ -22,11 +23,11 @@ def ajax_books(request): if category_id: ids = TextbookCompanionProposal.objects.using('scilab')\ .filter(proposal_status=3).values('id') - + books = TextbookCompanionPreference.objects.using('scilab')\ .filter(category=category_id).filter(approval_status=1)\ .filter(proposal_id__in=ids).order_by('book') - + context = { 'books': books } @@ -54,12 +55,27 @@ def ajax_examples(request): if chapter_id: examples = TextbookCompanionExample.objects.using('scilab')\ .filter(chapter_id=chapter_id).order_by('number') - + context = { 'examples': examples } return render(request, 'website/templates/ajax-examples.html', context) +@csrf_exempt +def ajax_code(request): + if request.method == "POST": + example_id = request.POST['example_id'] + example = TextbookCompanionExampleFiles.objects.using('scilab')\ + .get(id=example_id) + + example_path = '/var/www/scilab_in/uploads/' + example.filepath + f = open(example_path) + code = f.readlines() + f.close() + + print code + return HttpResponse(code) + def ajax_execute(request): if request.method == "POST": code = request.POST['code'] |