diff --git a/README.md b/README.md index 0a18731..61dbca3 100755 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +[Platform Name] is licensed under the MIT License. See LICENSE for details. \ No newline at end of file diff --git a/trevon/trevon/__pycache__/settings.cpython-312.pyc b/trevon/trevon/__pycache__/settings.cpython-312.pyc index cd1429f..a0d7382 100644 Binary files a/trevon/trevon/__pycache__/settings.cpython-312.pyc and b/trevon/trevon/__pycache__/settings.cpython-312.pyc differ diff --git a/trevon/trevon/__pycache__/urls.cpython-312.pyc b/trevon/trevon/__pycache__/urls.cpython-312.pyc index 9440d62..08eed62 100644 Binary files a/trevon/trevon/__pycache__/urls.cpython-312.pyc and b/trevon/trevon/__pycache__/urls.cpython-312.pyc differ diff --git a/trevon/trevon/settings.py b/trevon/trevon/settings.py index faa2501..d339a16 100644 --- a/trevon/trevon/settings.py +++ b/trevon/trevon/settings.py @@ -97,5 +97,17 @@ USE_L10N = True USE_TZ = True + +# settings.py + +COMPILER_API_URL = 'https://api.jdoodle.com/v1/execute' +COMPILER_API_KEY = '1a1caf708cc5cc29c28c156d88e482b0' + +PROBLEM_API_URL = 'https://28fa7403.problems.sphere-engine.com/api/v4' +PROBLEM_API_KEY = '4d22d7088552e3ff458f3706e345c533' + +CONTAINER_API_URL = 'https://28fa7403.containers.sphere-engine.com/api/v1' +CONTAINER_API_KEY = '8fbf6b64e8674edcafbf8484c629ac45' + # Static files (CSS, JavaScript, Images) STATIC_URL = '/static/' diff --git a/trevon/trevon/urls.py b/trevon/trevon/urls.py index 8db8ebf..f577997 100644 --- a/trevon/trevon/urls.py +++ b/trevon/trevon/urls.py @@ -3,13 +3,22 @@ from django.urls import include, path from yasha import views from accounts.views import * +from yasha.views import ( + compile_view, + problems_view, + problem_detail_view, + create_container_view, + container_detail_view, +) urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('accounts.urls')), - # path('', views.home, name='home'), - path('run_code/', views.run_code, name='run_code'), - path('editor/', views.editor, name='editor'), + path('compile/', compile_view, name='compile'), + path('problems/', problems_view, name='problems'), + path('problems//', problem_detail_view, name='problem_detail'), + path('containers/create/', create_container_view, name='create_container'), + path('containers//', container_detail_view, name='container_detail'), ] diff --git a/trevon/yasha/__pycache__/views.cpython-312.pyc b/trevon/yasha/__pycache__/views.cpython-312.pyc index 626f3a6..2a55855 100644 Binary files a/trevon/yasha/__pycache__/views.cpython-312.pyc and b/trevon/yasha/__pycache__/views.cpython-312.pyc differ diff --git a/trevon/yasha/services/__pycache__/compiler_api.cpython-312.pyc b/trevon/yasha/services/__pycache__/compiler_api.cpython-312.pyc new file mode 100644 index 0000000..298b681 Binary files /dev/null and b/trevon/yasha/services/__pycache__/compiler_api.cpython-312.pyc differ diff --git a/trevon/yasha/services/__pycache__/container_api.cpython-312.pyc b/trevon/yasha/services/__pycache__/container_api.cpython-312.pyc new file mode 100644 index 0000000..366fa54 Binary files /dev/null and b/trevon/yasha/services/__pycache__/container_api.cpython-312.pyc differ diff --git a/trevon/yasha/services/__pycache__/problem_api.cpython-312.pyc b/trevon/yasha/services/__pycache__/problem_api.cpython-312.pyc new file mode 100644 index 0000000..9ea44aa Binary files /dev/null and b/trevon/yasha/services/__pycache__/problem_api.cpython-312.pyc differ diff --git a/trevon/yasha/services/compiler_api.py b/trevon/yasha/services/compiler_api.py new file mode 100644 index 0000000..b23cb1a --- /dev/null +++ b/trevon/yasha/services/compiler_api.py @@ -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() diff --git a/trevon/yasha/services/container_api.py b/trevon/yasha/services/container_api.py new file mode 100644 index 0000000..a1d0df4 --- /dev/null +++ b/trevon/yasha/services/container_api.py @@ -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() diff --git a/trevon/yasha/services/problem_api.py b/trevon/yasha/services/problem_api.py new file mode 100644 index 0000000..b025cff --- /dev/null +++ b/trevon/yasha/services/problem_api.py @@ -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() diff --git a/trevon/yasha/templates/compile.html b/trevon/yasha/templates/compile.html new file mode 100644 index 0000000..af672b3 --- /dev/null +++ b/trevon/yasha/templates/compile.html @@ -0,0 +1,28 @@ + + + + + Compile Code + + +

Compile Code

+
+ {% csrf_token %} +
+
+
+
+ +
+
+ {% if result %} +

Result:

+
{{ result }}
+ {% endif %} +
+ + diff --git a/trevon/yasha/templates/container_detail.html b/trevon/yasha/templates/container_detail.html new file mode 100644 index 0000000..003d6fd --- /dev/null +++ b/trevon/yasha/templates/container_detail.html @@ -0,0 +1,12 @@ + + + + + Container {{ container.id }} + + +

Container {{ container.id }}

+

Status: {{ container.status }}

+

Image: {{ container.image }}

+ + diff --git a/trevon/yasha/templates/create_container.html b/trevon/yasha/templates/create_container.html new file mode 100644 index 0000000..713f4b7 --- /dev/null +++ b/trevon/yasha/templates/create_container.html @@ -0,0 +1,16 @@ + + + + + Create Container + + +

Create Container

+
+ {% csrf_token %} +
+
+ +
+ + diff --git a/trevon/yasha/templates/problem_details.html b/trevon/yasha/templates/problem_details.html new file mode 100644 index 0000000..71ec46d --- /dev/null +++ b/trevon/yasha/templates/problem_details.html @@ -0,0 +1,11 @@ + + + + + {{ problem.title }} + + +

{{ problem.title }}

+

{{ problem.description }}

+ + diff --git a/trevon/yasha/templates/problems.html b/trevon/yasha/templates/problems.html new file mode 100644 index 0000000..2c76061 --- /dev/null +++ b/trevon/yasha/templates/problems.html @@ -0,0 +1,15 @@ + + + + + Problems + + +

Problems

+ + + diff --git a/trevon/yasha/views.py b/trevon/yasha/views.py index 56c7330..f83a09a 100644 --- a/trevon/yasha/views.py +++ b/trevon/yasha/views.py @@ -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)