diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 1f807fa..6238565 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 6867ddf..b1607bd 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/templates/base.html b/core/templates/base.html index 788576e..29d8d2a 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -1,11 +1,30 @@ +{% load static %} - + - {% block title %}Knowledge Base{% endblock %} - {% block head %}{% endblock %} - - - {% block content %}{% endblock %} - - + + {{ page_title|default:"Unit Converter" }} + + + + + + + + + + + + + + + +
+ {% block content %}{% endblock %} +
+ + + + + \ No newline at end of file diff --git a/core/templates/core/index.html b/core/templates/core/index.html index 0a3f404..e8849db 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -1,154 +1,65 @@ {% extends "base.html" %} - -{% block title %}{{ project_name }}{% endblock %} - -{% block head %} -{% if project_description %} - - - -{% endif %} -{% if project_image_url %} - - -{% endif %} - - - - -{% endblock %} - {% block content %} -
-
-

Analyzing your requirements and generating your app…

-
- Loading… +
+
+

Unit Converter

+

A modern, fast, and free engineering unit converter.

-

AppWizzy AI is collecting your requirements and applying the first changes.

-

This page will refresh automatically as the plan is implemented.

-

- Runtime: Django {{ django_version }} · Python {{ python_version }} - — UTC {{ current_time|date:"Y-m-d H:i:s" }} -

-
-
- -{% endblock %} \ No newline at end of file + +
+ {% csrf_token %} +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+ +
+ +
+
+ + {% if result is not None %} +
+ {{ result }} +
+ {% endif %} + + {% if error %} +
+ {{ error }} +
+ {% endif %} + + +{% endblock %} diff --git a/core/urls.py b/core/urls.py index 6299e3d..5f9bb72 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,7 +1,6 @@ from django.urls import path - -from .views import home +from .views import IndexView urlpatterns = [ - path("", home, name="home"), -] + path('', IndexView.as_view(), name='index'), +] \ No newline at end of file diff --git a/core/views.py b/core/views.py index c9aed12..ccbf5d8 100644 --- a/core/views.py +++ b/core/views.py @@ -1,25 +1,75 @@ -import os -import platform - -from django import get_version as django_version from django.shortcuts import render -from django.utils import timezone +from django.views import View +class IndexView(View): + def get(self, request, *args, **kwargs): + # For now, units are hardcoded. This will be moved to the database later. + units = { + 'Length': ['meters', 'feet', 'inches'], + 'Mass': ['kilograms', 'pounds', 'ounces'], + 'Temperature': ['Celsius', 'Fahrenheit', 'Kelvin'] + } + context = { + 'units': units, + 'page_title': 'Engineering Unit Converter', + } + return render(request, 'core/index.html', context) -def home(request): - """Render the landing screen with loader and environment details.""" - host_name = request.get_host().lower() - agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic" - now = timezone.now() + def post(self, request, *args, **kwargs): + # Hardcoded units and conversion factors for the first iteration + units = { + 'Length': ['meters', 'feet', 'inches'], + 'Mass': ['kilograms', 'pounds', 'ounces'], + 'Temperature': ['Celsius', 'Fahrenheit', 'Kelvin'] + } + + value_in = request.POST.get('value_in') + unit_in = request.POST.get('unit_in') + unit_out = request.POST.get('unit_out') + + result = None + error = None - context = { - "project_name": "New Style", - "agent_brand": agent_brand, - "django_version": django_version(), - "python_version": platform.python_version(), - "current_time": now, - "host_name": host_name, - "project_description": os.getenv("PROJECT_DESCRIPTION", ""), - "project_image_url": os.getenv("PROJECT_IMAGE_URL", ""), - } - return render(request, "core/index.html", context) + try: + value_in_float = float(value_in) + + # Basic, non-comprehensive conversion logic + # This should be replaced with a more robust library or model-driven approach + + # Length + if unit_in == 'meters' and unit_out == 'feet': + result = value_in_float * 3.28084 + elif unit_in == 'feet' and unit_out == 'meters': + result = value_in_float / 3.28084 + + # Mass + elif unit_in == 'kilograms' and unit_out == 'pounds': + result = value_in_float * 2.20462 + elif unit_in == 'pounds' and unit_out == 'kilograms': + result = value_in_float / 2.20462 + + # Temperature + elif unit_in == 'Celsius' and unit_out == 'Fahrenheit': + result = (value_in_float * 9/5) + 32 + elif unit_in == 'Fahrenheit' and unit_out == 'Celsius': + result = (value_in_float - 32) * 5/9 + + elif unit_in == unit_out: + result = value_in_float + else: + # Placeholder for conversions not yet implemented + error = f"Conversion from {unit_in} to {unit_out} is not yet supported." + + except (ValueError, TypeError): + error = "Invalid input value. Please enter a number." + + context = { + 'units': units, + 'result': round(result, 4) if result is not None else None, + 'error': error, + 'value_in': value_in, + 'unit_in': unit_in, + 'unit_out': unit_out, + 'page_title': 'Engineering Unit Converter', + } + return render(request, 'core/index.html', context) \ No newline at end of file diff --git a/static/css/custom.css b/static/css/custom.css new file mode 100644 index 0000000..e10eda2 --- /dev/null +++ b/static/css/custom.css @@ -0,0 +1,98 @@ +/* +Engineering Unit Converter - Custom Stylesheet +*/ + +:root { + --background-color: #1a1a2e; + --primary-text-color: #ffffff; + --secondary-text-color: #dcdcdc; + --accent-color-1: #e94560; + --accent-color-2: #0f3460; + --card-background: #16213e; + --border-color: #0f3460; +} + +body { + background-color: var(--background-color); + color: var(--secondary-text-color); + font-family: 'Roboto', sans-serif; + display: flex; + justify-content: center; + align-items: center; + min-height: 100vh; + padding: 2rem; +} + +h1, h2, h3, h4, h5, h6 { + font-family: 'Poppins', sans-serif; + color: var(--primary-text-color); + font-weight: 600; +} + +.converter-wrapper { + max-width: 600px; + width: 100%; + background-color: var(--card-background); + padding: 2.5rem; + border-radius: 15px; + border: 1px solid var(--border-color); + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); +} + +.form-control, .form-select { + background-color: var(--accent-color-2); + color: var(--primary-text-color); + border: 1px solid var(--border-color); + padding: 0.75rem 1rem; + font-size: 1rem; +} + +.form-control::placeholder { + color: #a0a0c0; +} + +.form-control:focus, .form-select:focus { + background-color: var(--accent-color-2); + color: var(--primary-text-color); + border-color: var(--accent-color-1); + box-shadow: 0 0 0 0.25rem rgba(233, 69, 96, 0.25); +} + +.form-label { + font-family: 'Poppins', sans-serif; + font-weight: 500; + color: var(--primary-text-color); +} + +.btn-convert { + background-color: var(--accent-color-1); + color: var(--primary-text-color); + border: none; + padding: 0.75rem 1.5rem; + font-weight: 600; + font-family: 'Poppins', sans-serif; + transition: background-color 0.3s ease; +} + +.btn-convert:hover { + background-color: #d43d51; + color: var(--primary-text-color); +} + +.result-box { + background-color: var(--accent-color-2); + color: var(--primary-text-color); + padding: 1.5rem; + border-radius: 10px; + margin-top: 1.5rem; + text-align: center; + font-size: 1.5rem; + font-weight: 700; + font-family: 'Poppins', sans-serif; +} + +.error-box { + color: var(--accent-color-1); + font-weight: 500; + margin-top: 1rem; +}