Spaces:
Sleeping
Sleeping
File size: 8,843 Bytes
443a7c7 1de8298 50c7a9a 9ad8f09 8be671e 443a7c7 50c7a9a 9ad8f09 443a7c7 9ad8f09 33e35b1 9ad8f09 8be671e 9ad8f09 8edb4d6 443a7c7 8be671e 32c9d19 dbcfea9 4c237dc e71469b 4c237dc 26cc895 4c237dc dbcfea9 4c237dc dbcfea9 4c237dc dbcfea9 4c237dc dbcfea9 4c237dc e71469b dbcfea9 4c237dc dbcfea9 4c237dc dbcfea9 4c237dc dbcfea9 4c237dc dbcfea9 4c237dc e71469b c455c0a 4c237dc e71469b c455c0a 32c9d19 c455c0a 32c9d19 4c237dc dbcfea9 4c237dc dbcfea9 8bed360 dbcfea9 4c237dc 32c9d19 4c237dc 32c9d19 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
from fastapi import FastAPI,Request,HTTPException,Response
from typing import Optional
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from components.dbconnection import provideClient
from fastapi.responses import HTMLResponse
origins=["*"]
app=FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
client = provideClient()
db = client["pahalgam_pd"]
coll = db["ponyworkers"]
class PPD(BaseModel):
name:str
registration_number:str
phone_number:str
address:str
aadhar:str
parentage:str
total_ponies:str
stand:str
license:bool
renewal:bool
@app.post("/dataingestion")
async def Ingest(request:PPD):
payload={
"name":request.name,
"registration_number":request.registration_number,
"phone_number":request.phone_number,
"address":request.address,
"aadhar":request.aadhar,
"parentage":request.parentage,
"total_ponies":request.total_ponies,
"stand":request.stand,
"license":request.license,
"renewal":request.renewal
}
result = coll.insert_one(payload)
print(f"Inserted ID: {result.inserted_id}")
return {"success":True}
@app.get("/", response_class=HTMLResponse)
async def static_page():
return """
<!DOCTYPE html5>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pony Registration - Official Form</title>
<style>
/* */
:root {
--primary-blue: #003366; /* Navy Blue */
--secondary-red: #d22027; /* Accent Red */
--bg-gray: #f0f0f0;
--border-gray: #5b616b;
--text-dark: #1b1b1b;
}
body {
font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;
background: var(--bg-gray);
display: flex;
justify-content: center;
padding: 40px 20px;
color: var(--text-dark);
line-height: 1.5;
}
.form-container {
background: white;
padding: 40px;
border-top: 8px solid var(--primary-blue);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
width: 100%;
max-width: 650px;
height:100%;
}
.header-section {
border-bottom: 2px solid #efefef;
margin-bottom: 25px;
padding-bottom: 15px;
}
h2 {
color: var(--primary-blue);
margin: 0;
font-size: 28px;
text-transform: uppercase;
letter-spacing: 1px;
}
.instruction-text {
font-size: 14px;
color: #555;
margin-top: 5px;
}
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.field { margin-bottom: 20px; }
.full { grid-column: span 2; }
label {
display: block;
font-size: 14px;
font-weight: 700;
margin-bottom: 8px;
color: var(--text-dark);
}
input[type="text"],
input[type="number"] {
width: 100%;
padding: 12px;
border: 1px solid var(--border-gray);
border-radius: 0; /* Govt forms often use sharp corners */
box-sizing: border-box;
font-size: 16px;
}
input:focus {
outline: 3px solid #2491ff;
outline-offset: 0;
}
/* Checkbox styling */
.checkbox-group {
display: flex;
align-items: center;
gap: 10px;
cursor: pointer;
}
input[type="checkbox"] {
width: 20px;
height: 20px;
cursor: pointer;
}
/* Buttons */
.button-row {
display: flex;
gap: 15px;
margin-top: 30px;
border-top: 1px solid #ddd;
padding-top: 20px;
}
button {
flex: 2;
padding: 15px;
font-size: 16px;
font-weight: bold;
border: none;
cursor: pointer;
transition: background 0.2s;
}
.btn-submit {
background: var(--primary-blue);
color: white;
}
.btn-submit:hover { background: #002244; }
.btn-clear {
flex: 1;
background: #e1e1e1;
color: #333;
border: 1px solid #ccc;
}
.btn-clear:hover { background: #d0d0d0; }
.required-star { color: var(--secondary-red); }
</style>
</head>
<body>
<div class="form-container">
<div class="header-section">
<h2>Pony Registration</h2>
<div class="instruction-text">Official Registration Form for Domesticated Equines. Please complete all required fields.</div>
</div>
<form id="registrationForm" onsubmit="submitData(event)">
<div class="grid">
<div class="field full">
<label for="name">Full Legal Name <span class="required-star">*</span></label>
<input id="name" name="name" type="text" placeholder="e.g. John Doe" required>
</div>
<div class="field">
<label for="registration_number">Registration Number</label>
<input id="registration_number" name="registration_number" type="text" required>
</div>
<div class="field">
<label for="phone_number">Phone Number</label>
<input id="phone_number" name="phone_number" type="text" placeholder="(555) 000-0000" required>
</div>
<div class="field full">
<label for="address">Address</label>
<input id="address" name="address" type="text" required>
</div>
<div class="field">
<label for="aadhar">Aadhar / ID Number</label>
<input id="aadhar" name="aadhar" type="text" required>
</div>
<div class="field">
<label for="parentage">Parentage / Lineage</label>
<input id="parentage" name="parentage" type="text" required>
</div>
<div class="field">
<label for="total_ponies">Total Quantity of Ponies</label>
<input type="number" id="total_ponies" name="total_ponies" required>
</div>
<div class="field">
<label for="stand">Assigned Stand</label>
<input id="stand" name="stand" type="text" required>
</div>
<div class="field">
<label for="license">License Held</label>
<input type="checkbox" id="license" name="license">
</div>
<div class="field">
<label for="renewal">Applied for Renewal</label>
<input type="checkbox" id="renewal" name="renewal">
</div>
</div>
<div class="button-row">
<button type="button" class="btn-clear" onclick="clearForm()">Clear Form</button>
<button type="submit" class="btn-submit">Submit Application</button>
</div>
</form>
</div>
<script>
async function submitData(e) {
e.preventDefault()
const form = document.getElementById('registrationForm');
const formData = new FormData(form);
const payload = Object.fromEntries(formData.entries());
try {
const res = await fetch('/dataingestion', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
});
const result = await res.json();
if(result.success === true){
alert("Submission Successful: Data has been transmitted.");
} else {
alert("Error: The server could not process your application.");
}
} catch (error) {
console.error("Transmission error:", error);
alert("Network Error: Could not connect to official servers.");
}
}
function clearForm() {
if(confirm("Are you sure you want to clear all entered data?")) {
document.getElementById("registrationForm").reset();
}
}
</script>
</body>
</html>
"""
|