Skip to content

Commit 31c9a7d

Browse files
committed
Successfully created a second form for text submission, including a new model and table for text submission(only redirects to a different page with submitted text).
1 parent 144127a commit 31c9a7d

File tree

7 files changed

+105
-26
lines changed

7 files changed

+105
-26
lines changed

db.sqlite3

4 KB
Binary file not shown.

nobiasapp/forms.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from django import forms
2-
from .models import Link
2+
from .models import Link, Text
33

44
class SubmitLinkForm(forms.ModelForm):
55
class Meta:
66
model = Link
77
fields = ['link']
88
widgets = {
99
'link': forms.URLInput(attrs={'style': 'width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box;'}),
10+
}
11+
class SubmitTextBoxForm(forms.ModelForm):
12+
class Meta:
13+
model = Text
14+
fields = ['text']
15+
widgets = {
16+
'text': forms.TextInput(attrs={'style': 'width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box;'}),
1017
}

nobiasapp/migrations/0003_text.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 5.0 on 2024-04-10 03:28
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('nobiasapp', '0002_rename_submittedlink_link'),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name='Text',
15+
fields=[
16+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
17+
('text', models.CharField(max_length=1000)),
18+
],
19+
),
20+
]

nobiasapp/models.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Create your models here.
44
class Link(models.Model):
55
link = models.URLField()
6-
76
def __str__(self):
8-
return self.link
7+
return self.link
8+
class Text(models.Model):
9+
text = models.CharField(max_length=1000)
10+
def __str__(self):
11+
return self.text

nobiasapp/templates/newPage.html

+43-14
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,30 @@
186186
margin-top: 20px;
187187
color: #777; /
188188
}
189+
.submitBox{
190+
background-color: #007bff;
191+
color: #fff;
192+
width: 100%;
193+
padding: 10px;
194+
margin-bottom: 10px;
195+
border: 1px solid #ccc;
196+
border-radius: 5px;
197+
box-sizing: border-box;
198+
}
189199
</style>
200+
<script>
201+
function toggleForm() {
202+
var linkForm = document.getElementById("link-form");
203+
var textBoxForm = document.getElementById("text-box-form");
204+
if (linkForm.style.display === "none") {
205+
linkForm.style.display = "block";
206+
textBoxForm.style.display = "none";
207+
} else {
208+
linkForm.style.display = "none";
209+
textBoxForm.style.display = "block";
210+
}
211+
}
212+
</script>
190213
</head>
191214

192215
<body>
@@ -228,20 +251,26 @@ <h1>NoBias</h1>
228251
<p>NoBias is a program that will detect bias in a news article. We will detect bias by analyzing the tone,
229252
sentiment, and diction of a news article.</p>
230253
</div>
231-
<form method="post" action="{% url 'home' %}" onsubmit="showLoader()"
232-
style="display: flex; flex-direction: column; align-items: center; padding: 20px; margin-top: 70px;">
233-
234-
{% csrf_token %}
235-
<div class="linkbox" style="display: flex; flex-direction: column; width: 70%; align-items: center; ">
236-
{{ form.link }}
237-
<button type="submit"
238-
style="width: 100%; padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer;"><i class="fas fa-search"></i>Submit</button>
239-
</div>
240-
</form>
241-
<!-- <div class="search-bar">
242-
<input type="text" placeholder="Search...">
243-
<button type="submit"><i class="fas fa-search"></i></button>
244-
</div> -->
254+
<button onclick="toggleForm()">Toggle Submit Box</button>
255+
256+
<div id="link-form">
257+
<form method="post">
258+
{% csrf_token %}
259+
{{ link_form }}
260+
<button type="submit" class="submitBox">Submit Link</button>
261+
</form>
262+
</div>
263+
264+
<div id="text-box-form" style="display: none;">
265+
<form method="post">
266+
{% csrf_token %}
267+
{{ text_form }}
268+
<button type="submit" class="submitBox">Submit Text</button>
269+
</form>
270+
</div>
271+
272+
273+
245274
<div class="feature">
246275
<div class="feature-item">
247276
<h3>Detect and Measure Bias</h3>

nobiasapp/templates/textPage.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1> {{ thisVar }}</h1>
11+
</body>
12+
</html>

nobiasapp/views.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.shortcuts import render
22
from nlpFiles.getTextFromWeb import polarityRating, highRatedSent, getTitle, webScrape
3-
from .forms import SubmitLinkForm
3+
from .forms import SubmitLinkForm, SubmitTextBoxForm
44

55
# def submitLink(request):
66
# if request.method == 'POST':
@@ -23,21 +23,29 @@ def aboutus(request):
2323
return render(request, 'aboutus.html')
2424
def tech(request):
2525
return render(request, 'tech.html')
26+
2627
def home(request):
2728
if request.method == 'POST':
28-
form = SubmitLinkForm(request.POST)
29-
if form.is_valid():
30-
link_object = form.save() # This saves the link to the database
31-
weblink = link_object.link # Access the link and store it in thisVar
32-
# You can now use thisVar for other Python code
29+
link_form = SubmitLinkForm(request.POST)
30+
text_form = SubmitTextBoxForm(request.POST)
31+
32+
if link_form.is_valid():
33+
link_object = link_form.save()
34+
weblink = link_object.link
3335
paragraph = []
3436
pageSource = webScrape(weblink)
3537
title = getTitle(pageSource)
3638
polarityRating(paragraph, pageSource)
3739
highValuedList = highRatedSent(paragraph)
38-
# Redirect or render a success page
3940
return render(request, 'successPage.html', {'thisVar': paragraph, "highValuedList": highValuedList, 'title': title})
41+
42+
elif text_form.is_valid():
43+
text_object = text_form.save()
44+
# Do something with the text form submission
45+
return render(request, 'textPage.html', {'thisVar': text_object}) # Render a success page for text form submission
46+
4047
else:
41-
form = SubmitLinkForm()
48+
link_form = SubmitLinkForm()
49+
text_form = SubmitTextBoxForm()
4250

43-
return render(request, './newPage.html', {'form': form})
51+
return render(request, './newPage.html', {'link_form': link_form, 'text_form': text_form})

0 commit comments

Comments
 (0)