-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Updated settings, URLs, and views in Trevon project, adding compiler…
…, problem, and container APIs"
- Loading branch information
1 parent
b9ebbc2
commit 79ed938
Showing
18 changed files
with
265 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,57 @@ | ||
**Trevon Project** | ||
**Welcome to [Platform Name]** | ||
================ | ||
|
||
**Overview** | ||
----------- | ||
[Platform Name] is a coding platform that allows users to write, run, and debug code in a variety of programming languages. The platform provides a range of features, including: | ||
|
||
This project is a Django-based application that utilizes MongoDB as its database. The project involves multiple apps, including `accounts` and `yasha`, which contain models, views, and templates for user authentication and profiling. | ||
* Code editing and debugging tools | ||
* Support for multiple programming languages | ||
* Integration with API services for compiler, problem, and container management | ||
|
||
**Changes** | ||
---------- | ||
**Getting Started** | ||
--------------- | ||
|
||
### User Model Refactoring | ||
To get started with [Platform Name], simply create an account and start coding! You can choose from a range of templates and examples to get started, or start from scratch. | ||
|
||
The `User` model in `accounts/models.py` has been refactored to inherit from `AbstractBaseUser` and `PermissionsMixin`, allowing for more flexibility in customizing the user model. A new `UserManager` class has been added to handle user creation and superuser creation. | ||
**Features** | ||
--------- | ||
|
||
### MongoDB Connection Updates | ||
* **Code Editing**: Write and edit code in a range of programming languages, including Python, Java, and C++. | ||
* **Debugging**: Debug your code using our built-in debugging tools, including syntax highlighting and error reporting. | ||
* **API Integration**: Integrate your code with our API services for compiler, problem, and container management. | ||
* **Templates and Examples**: Get started quickly with our range of templates and examples. | ||
|
||
The `con.py` file has been updated to use the `mongodb+srv` protocol and enable TLS connections for secure communication with the MongoDB database. | ||
**API Services** | ||
------------- | ||
|
||
### Profile Model Addition | ||
* **Compiler API**: Compile and run your code using our compiler API. | ||
* **Problem API**: Access a range of programming problems and challenges using our problem API. | ||
* **Container API**: Create and manage containers for your code using our container API. | ||
|
||
A new `Profile` model has been added to `yasha/models.py`, which has a one-to-one relationship with the `AUTH_USER_MODEL`. | ||
**Settings** | ||
--------- | ||
|
||
**Installation** | ||
-------------- | ||
* **COMPILER_API_URL**: The URL of the compiler API service. | ||
* **COMPILER_API_KEY**: The API key for the compiler API service. | ||
* **PROBLEM_API_URL**: The URL of the problem API service. | ||
* **PROBLEM_API_KEY**: The API key for the problem API service. | ||
* **CONTAINER_API_URL**: The URL of the container API service. | ||
* **CONTAINER_API_KEY**: The API key for the container API service. | ||
|
||
To install the project, follow these steps: | ||
**Views** | ||
------ | ||
|
||
1. Clone the repository: `git clone https://github.com/[username]/trevon.git` | ||
2. Install the required packages: `pip install -r requirements.txt` | ||
3. Configure the `settings.py` file to point to your MongoDB database | ||
4. Run the migrations: `python manage.py migrate` | ||
5. Start the development server: `python manage.py runserver` | ||
* **Compile View**: Compile and run your code using our compile view. | ||
* **Problems View**: Access a range of programming problems and challenges using our problems view. | ||
* **Problem Detail View**: View detailed information about a specific problem using our problem detail view. | ||
* **Create Container View**: Create a new container for your code using our create container view. | ||
* **Container Detail View**: View detailed information about a specific container using our container detail view. | ||
|
||
**Contributing** | ||
-------------- | ||
** Contributing** | ||
------------ | ||
|
||
If you'd like to contribute to the project, please fork the repository and submit a pull request with your changes. | ||
If you'd like to contribute to [Platform Name], please fork the repository and submit a pull request with your changes. | ||
|
||
**License** | ||
--------- | ||
------- | ||
|
||
This project is licensed under the MIT License. See `LICENSE` for details. | ||
[Platform Name] is licensed under the MIT License. See LICENSE for details. |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# services/compiler_api.py | ||
|
||
import requests | ||
from django.conf import settings | ||
|
||
def compile_code(source_code, language): | ||
url = settings.COMPILER_API_URL | ||
headers = { | ||
'Authorization': f'Bearer {settings.COMPILER_API_KEY}', | ||
'Content-Type': 'application/json' | ||
} | ||
payload = { | ||
'source_code': source_code, | ||
'language': language | ||
} | ||
response = requests.post(url, json=payload, headers=headers) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# services/container_api.py | ||
|
||
import requests | ||
from django.conf import settings | ||
|
||
def create_container(image): | ||
url = settings.CONTAINER_API_URL | ||
headers = { | ||
'Authorization': f'Bearer {settings.CONTAINER_API_KEY}', | ||
'Content-Type': 'application/json' | ||
} | ||
payload = { | ||
'image': image | ||
} | ||
response = requests.post(url, json=payload, headers=headers) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
response.raise_for_status() | ||
|
||
def get_container(container_id): | ||
url = f"{settings.CONTAINER_API_URL}/{container_id}" | ||
headers = { | ||
'Authorization': f'Bearer {settings.CONTAINER_API_KEY}', | ||
} | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# services/problem_api.py | ||
|
||
import requests | ||
from django.conf import settings | ||
|
||
def get_problems(): | ||
url = settings.PROBLEM_API_URL | ||
headers = { | ||
'Authorization': f'Bearer {settings.PROBLEM_API_KEY}', | ||
} | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
response.raise_for_status() | ||
|
||
def get_problem(problem_id): | ||
url = f"{settings.PROBLEM_API_URL}/{problem_id}" | ||
headers = { | ||
'Authorization': f'Bearer {settings.PROBLEM_API_KEY}', | ||
} | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- templates/compile.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Compile Code</title> | ||
</head> | ||
<body> | ||
<h1>Compile Code</h1> | ||
<form method="post" action=""> | ||
{% csrf_token %} | ||
<label for="source_code">Source Code:</label><br> | ||
<textarea name="source_code" rows="10" cols="50"></textarea><br> | ||
<label for="language">Language:</label><br> | ||
<select name="language"> | ||
<option value="python">Python</option> | ||
<option value="javascript">JavaScript</option> | ||
<!-- Add more languages as needed --> | ||
</select><br> | ||
<button type="submit">Compile</button> | ||
</form> | ||
<div id="result"> | ||
{% if result %} | ||
<h2>Result:</h2> | ||
<pre>{{ result }}</pre> | ||
{% endif %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!-- templates/container_detail.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Container {{ container.id }}</title> | ||
</head> | ||
<body> | ||
<h1>Container {{ container.id }}</h1> | ||
<p>Status: {{ container.status }}</p> | ||
<p>Image: {{ container.image }}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- templates/create_container.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Create Container</title> | ||
</head> | ||
<body> | ||
<h1>Create Container</h1> | ||
<form method="post" action=""> | ||
{% csrf_token %} | ||
<label for="image">Image:</label><br> | ||
<input type="text" name="image"><br> | ||
<button type="submit">Create Container</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- templates/problem_detail.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{ problem.title }}</title> | ||
</head> | ||
<body> | ||
<h1>{{ problem.title }}</h1> | ||
<p>{{ problem.description }}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!-- templates/problems.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Problems</title> | ||
</head> | ||
<body> | ||
<h1>Problems</h1> | ||
<ul> | ||
{% for problem in problems %} | ||
<li><a href="{% url 'problem_detail' problem.id %}">{{ problem.title }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,50 @@ | ||
# core/views.py | ||
from django import db | ||
from django.contrib.auth import login, authenticate | ||
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm | ||
# views.py | ||
|
||
from django.shortcuts import render, redirect | ||
import subprocess | ||
from django.http import JsonResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
import json | ||
|
||
from .services.compiler_api import compile_code | ||
from .services.problem_api import get_problems, get_problem | ||
from .services.container_api import create_container, get_container | ||
|
||
@csrf_exempt | ||
def run_code(request): | ||
def compile_view(request): | ||
if request.method == 'POST': | ||
data = json.loads(request.body) | ||
code = data.get('code', '') | ||
source_code = request.POST.get('source_code') | ||
language = request.POST.get('language') | ||
try: | ||
result = subprocess.run(['python3', '-c', code], capture_output=True, text=True, timeout=5) | ||
return JsonResponse({'output': result.stdout or result.stderr}) | ||
except subprocess.TimeoutExpired: | ||
return JsonResponse({'output': 'Code execution timed out'}) | ||
return JsonResponse({'output': 'Invalid request'}) | ||
|
||
def editor(request): | ||
return render(request, 'yasha/editor.html') | ||
|
||
# views.py | ||
|
||
|
||
def index(request): | ||
# Example: Read data from Firebase Realtime Database | ||
ref = db.reference('/') | ||
data = ref.get() | ||
|
||
return render(request, 'index.html', {'data': data}) | ||
result = compile_code(source_code, language) | ||
return JsonResponse(result) | ||
except Exception as e: | ||
return JsonResponse({'error': str(e)}, status=500) | ||
return render(request, 'compile.html') | ||
|
||
def problems_view(request): | ||
try: | ||
problems = get_problems() | ||
return render(request, 'problems.html', {'problems': problems}) | ||
except Exception as e: | ||
return JsonResponse({'error': str(e)}, status=500) | ||
|
||
def problem_detail_view(request, problem_id): | ||
try: | ||
problem = get_problem(problem_id) | ||
return render(request, 'problem_detail.html', {'problem': problem}) | ||
except Exception as e: | ||
return JsonResponse({'error': str(e)}, status=500) | ||
|
||
def create_container_view(request): | ||
if request.method == 'POST': | ||
image = request.POST.get('image') | ||
try: | ||
container = create_container(image) | ||
return JsonResponse(container) | ||
except Exception as e: | ||
return JsonResponse({'error': str(e)}, status=500) | ||
return render(request, 'create_container.html') | ||
|
||
def container_detail_view(request, container_id): | ||
try: | ||
container = get_container(container_id) | ||
return render(request, 'container_detail.html', {'container': container}) | ||
except Exception as e: | ||
return JsonResponse({'error': str(e)}, status=500) | ||
|