Skip to content

Commit d6c4f1c

Browse files
committed
added compiler
1 parent 277712b commit d6c4f1c

19 files changed

+69
-55
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
codeara/*/__pycache__/
2-
core/*/__pycache__/
3-
42
db.sqlite3
53
/media
64
.vscode/
102 Bytes
Binary file not shown.
27 Bytes
Binary file not shown.

codeara/settings.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'django.contrib.contenttypes',
2020
'django.contrib.sessions',
2121
'django.contrib.messages',
22+
'django.contrib.sites',
2223
'django.contrib.staticfiles',
2324
'codeara',
2425
'user',
@@ -84,6 +85,7 @@
8485
},
8586
]
8687

88+
SITE_ID = 1
8789

8890
# Internationalization
8991
# https://docs.djangoproject.com/en/1.11/topics/i18n/
@@ -109,6 +111,9 @@
109111
'allauth.account.auth_backends.AuthenticationBackend',
110112
)
111113

114+
Client_id = config('Client_id')
115+
Client_secret = config('Client_secret')
116+
112117
ERROR_MESSAGE = "Something went wrong please try again"
113118
CORECT_SUBMISSION_MESSAGE = "Correct!!"
114119
INCORECT_SUBMISSION_MESSAGE = "Wrong Answer. How about changing few more lines in the code"

codeara/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
urlpatterns = [
55
path('admin/', admin.site.urls),
6-
path('compiler/', include('compiler.urls')),
6+
path('compiler/', include('compiler.urls', namespace="compiler")),
77
path('', include('user.urls')),
88
]
16 Bytes
Binary file not shown.
20 Bytes
Binary file not shown.

compiler/static/compiler/css/theme.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ body {
77
background-repeat: no-repeat;
88
background-size: cover;
99
}
10-
#editor{
11-
font-family: 'Quicksand', sans-serif !important;
12-
font-size: 24;
10+
.ace_editor, .ace_editor div{
11+
font-family:monospace;
12+
font-size: 14;
1313
}
1414
body * {
1515
font-family: 'Quicksand', sans-serif;

compiler/templates/base.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
</div>
3333
<div id="navbar" class="collapse navbar-collapse">
3434
<ul class="nav navbar-nav">
35-
<li><a href="{% url 'compiler' %}">Compiler</a></li>
35+
<li><a href="{% url 'compiler:compiler' %}">Compiler</a></li>
3636
</ul>
3737
<ul class="nav navbar-nav navbar-right">
3838
{% if user.is_authenticated %}
3939
<li class="dropdown">
4040
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ user.username}} <span class="caret"></span></a>
4141
<ul class="dropdown-menu">
42-
<li><a href="{% url 'profile' %}">Profile</a></li>
43-
<li><a href="{% url 'account_logout' %}">Logout</a></li>
42+
4443
</ul>
4544
</li>
4645
{% else %}

compiler/templates/code_editor_content.html

+15-8
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ <h4 class="language-text">Select your language:</h4>
2525
</div>
2626
<div id="outer" class="col-sm-5" style="padding-top: 3px;">
2727
<select id="language" data-placeholder="Choose a Language..." class="" tabindex="1">
28-
<option value="4">C</option>
29-
<option value="34">Python</option>
30-
<option value="27">Java</option>
31-
<option value="10">C++</option>
28+
<option value="1">c</option>
29+
<option value="3">python3</option>
30+
<option value="3">java</option>
31+
<option value="3">cpp14</option>
32+
<option value="3">go</option>
33+
<option value="3">sql</option>
34+
<option value="3">csharp</option>
35+
<option value="3">dart</option>
36+
<option value="3">nodejs</option>
37+
<option value="2">kotlin</option>
38+
<option value="0">brainfuck</option>
3239
</select>
3340
</div>
3441
<div class="col-sm-4"></div>
@@ -69,6 +76,7 @@ <h5>Output:</h5>
6976
editor.setTheme("ace/theme/monokai");
7077
editor.getSession().setMode("ace/mode/c_cpp");
7178
editor.setShowPrintMargin(false);
79+
editor.setFontSize("14px");
7280
$('select').select2();
7381

7482
$("#language").change(function () {
@@ -99,7 +107,7 @@ <h5>Output:</h5>
99107
$.ajax(
100108
{
101109
type: "POST",
102-
url : "{% url 'result' %}",
110+
url : "{% url 'compiler:result' %}",
103111
data: {
104112

105113
script: editor.getValue(),
@@ -113,9 +121,8 @@ <h5>Output:</h5>
113121
success: function (output) {
114122
// enables submit btn
115123
$("#btn").prop('disabled', false)
116-
var str = JSON.parse(output);
117-
//var str = (output.output).toString();
118-
//str=decodeURIComponent(escape(str));
124+
var str = (output.output).toString();
125+
str=decodeURIComponent(escape(str));
119126
$("#output").html(str);
120127
},
121128

compiler/templates/result.html

-4
This file was deleted.

compiler/urls.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from django.urls import path, include
22
from . import views
33

4+
app_name = 'compiler'
5+
46
urlpatterns = [
5-
path('',views.code_editor, name="compiler"),
6-
path('result/', views.result, name="result"),
7+
path('', views.code_editor, name = "compiler"),
8+
path('result/', views.result, name = "result"),
79
]

compiler/views.py

+16-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
client_id = "aa3c5e94ced8d771cb0a961ce09643e1"
1010
client_secret = "30ed01aa75f848fe6388516339bea7944295cfa0bb8f5983f7302e556c87b9bb"
1111

12-
LANG_CODE = { 'c': 1, 'java': 3, 'cpp14': 3, 'python3': 3}
12+
LANG_CODE = { 'c': 1, 'java': 3, 'cpp14': 3, 'python3': 3,'go': 3,
13+
'sql': 3,'csharp': 3,'dart': 3,'nodejs': 3,'kotlin': 2,'brainfuck': 0,}
1314

1415
def code_editor(request):
1516
return render(request,'code_editor.html')
@@ -18,44 +19,39 @@ def result(request):
1819
if request.method == "POST":
1920
source = request.POST.get("script")
2021
lang = request.POST.get("lang")
21-
stdin = [request.POST.get("stdin")]
22-
#print(source)
22+
stdin = request.POST.get("stdin")
23+
2324
data = {'clientId':client_id,
2425
'clientSecret':client_secret,
2526
'script':source,
26-
'language':"c",
27-
'versionIndex':"3",
27+
'stdin':stdin,
28+
'language':lang,
29+
'versionIndex':LANG_CODE[lang],
2830
}
29-
#if 'stdin' in code:
30-
#data['stdin'] = stdin
31+
#if stdin:
32+
#data.update({'stdin':stdin})
3133
try:
3234
headers = {'Content-type': 'application/json'}
3335
r = requests.post(url = API_ENDPOINT, data = json.dumps(data), headers = headers)
3436
json_data = r.json()
37+
print(json_data)
3538
status_code = r.status_code
36-
time = json_data['cpuTime']
37-
memory = json_data['memory']
39+
#output = Robject(r.json())
3840
output = json_data['output']
39-
print(output)
40-
print(time)
41-
print(memory)
4241
if not output:
4342
output = message.replace("\n","<br>")
4443
except Exception as e:
45-
for i in range(10):
46-
print(e)
44+
print(e)
4745
output = settings.ERROR_MESSAGE
48-
#return HttpResponse(json.dumps({'output': output}), content_type="application/json")
49-
return HttpResponse(json_data)
46+
print(output)
47+
return HttpResponse(json.dumps({'output': json_data['output']}), content_type="application/json")
5048
else:
5149
return render(request,'code_editor.html',locals())
52-
5350
'''
54-
class Result():
51+
class Robject():
5552
def __init__(self, result):
5653
self.output = result['output']
5754
self.memory = result['memory']
5855
self.time = result['cpuTime']
5956
60-
61-
'''
57+
'''

db.sqlite3

12 KB
Binary file not shown.

user/__pycache__/urls.cpython-37.pyc

22 Bytes
Binary file not shown.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 2.1.7 on 2019-12-25 05:01
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('user', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='user',
15+
name='person',
16+
),
17+
migrations.DeleteModel(
18+
name='user',
19+
),
20+
]
Binary file not shown.

user/templates/home.html

-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
11
{% extends 'base.html' %}
22

3-
{% block content %}
4-
{% if live_contests or upcoming_contests %}
5-
{% include 'contests_content.html' %}
6-
<div class="container"><a href="{% url 'contests' %}">Know more</a></div>
7-
{% endif %}
8-
{% if track %}
9-
{% include 'all_tracks.html' %}
10-
<div class="container"><a href="{% url 'alltracks' %}">Know more</a></div>
11-
{% endif %}
12-
{% endblock %}

user/urls.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.urls import path, include
22
from . import views
33

4-
urlpatterns = [
5-
path('',views.home,name='home'),
4+
app_name = 'user'
65

6+
urlpatterns = [
7+
path('', views.home, name = 'home'),
78
]

0 commit comments

Comments
 (0)