Skip to content

Commit d2ef459

Browse files
committed
Added code for python generator
1 parent 0d4515e commit d2ef459

9 files changed

Lines changed: 85 additions & 19 deletions

File tree

Aug21/Django/hello-project/app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""This module is for learning
2+
3+
This module has basic functions to work with numbers
4+
5+
"""
6+
7+
8+
def is_even(number: int) -> bool:
9+
"""
10+
This method will find if the number passed is even or not
11+
:param number : a number
12+
:return: True if even False otherwise
13+
"""
14+
if number <= 0:
15+
return False
16+
return number % 2 == 0
17+
18+
print(__name__)
19+
20+
if __name__ == '__main__':
21+
# if someone is executing the code directly by calling python app.py then this block will be executed
22+
print(is_even(5))
23+
print(is_even(10))

Aug21/Django/hello-project/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import app

Aug21/Django/hello_django/sample/sample/templates/sample/home.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

Aug21/Django/password_generator/generator/templates/generator/home.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@
55
<title>I Hub</title>
66
</head>
77
<body>
8-
<h1>Welcome to Django</h1>
9-
<h2>From IHub</h2>
8+
<h1>Welcome to Password Generator From IHub</h1>
109

10+
<form action="{% url 'password' %}">
11+
<select name="length">
12+
<option value="6">6</option>
13+
<option value="7">7</option>
14+
<option value="8">8</option>
15+
<option value="9">9</option>
16+
<option value="10">10</option>
17+
<option value="11" selected="selected">11</option>
18+
<option value="12">12</option>
19+
<option value="13">13</option>
20+
<option value="14">14</option>
21+
</select>
22+
<br/>
23+
<input type="checkbox" name="uppercase"> Upper Case
24+
<br/>
25+
<input type="checkbox" name="numbers"> Numbers
26+
<br/>
27+
<input type="checkbox" name="special"> Special Characters
28+
<br/>
29+
<input type="submit" value="Generate Password"></input>
30+
</form>
1131
</body>
1232
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Password</title>
6+
</head>
7+
<body>
8+
<h1> Your geneerated password is :</h1>
9+
<h2>{{ password }}</h2>
10+
11+
<a href="{% url 'home' %}">home</a>
12+
</body>
13+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
from django.shortcuts import render
22
from django.http import HttpResponse
3+
import random
34

45

56
# Create your views here.
67
def home(request):
8+
"""
9+
This is the home page request
10+
"""
711
return render(request, 'generator/home.html')
812

913

1014
def about(request):
1115
return render(request, 'generator/about.html')
16+
17+
18+
def password(request):
19+
generated_password = ''
20+
characters = list('abcdefghijklmnopqrstuvwxyz')
21+
# Get the length from query string
22+
length = int(request.GET.get('length'))
23+
24+
if request.GET.get('uppercase'):
25+
characters.extend(list('ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
26+
if request.GET.get('special'):
27+
characters.extend(list('*&%#@'))
28+
if request.GET.get('numbers'):
29+
characters.extend(list('0123456789'))
30+
for index in range(length):
31+
generated_password += random.choice(characters)
32+
return render(request, 'generator/password.html', {'password': generated_password})

Aug21/Django/password_generator/password_generator/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from generator import views
1919

2020
urlpatterns = [
21-
path('', views.home),
22-
path('about', views.about)
21+
path('', views.home, name='home'),
22+
path('password/', views.password, name='password'),
23+
path('about', views.about, name='about')
2324
]

July21/EffectivePython/inventory/inventory.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ def get_inventory_index(inventory_dict, id):
3333
count += 1
3434
raise KeyError("Id not found")
3535

36-
37-
38-
39-
4036
def is_inventory_available():
4137
"""
4238
Returns:

July21/EffectivePython/inventory_withsqlite/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def update_product(products, ids):
5353
if id not in ids:
5454
print("Invalid Id entered")
5555
else:
56-
selected_product: models.Product = [product for product in products if product.id == id][0]
56+
selected_product: models.Product = list(filter(lambda product: product.id == id),products)[0]
57+
#selected_product: models.Product = [product for product in products if product.id == id][0]
5758
result = accept_change_from_user('name', selected_product.name)
5859
is_updated = False
5960
if result:

0 commit comments

Comments
 (0)