Cloud Platform Programming Project
Cloud Platform Programming Project
5. User Flow
User can:
User can view, edit, or delete their posted items from the dashboard.
Step 7: Logout
7. Summary of Functionalities
Functionality Description
Post Item Report a lost or found item with details and image.
AWS Rekognition Automatically detect labels and extract text from images.
Profile
Edit profile details and change password.
Management
Creating a full-fledged web application like whops.ie involves multiple steps, from setting up the
project to deploying it. Below is a step-by-step guide with code snippets for each step. Follow these
steps sequentially to build your application.
1. Install Python:
bash
Copy
python --version
2. Install Django:
bash
Copy
bash
Copy
bash
Copy
cd whops
bash
Copy
python
Copy
INSTALLED_APPS = [
...
'lf_box',
]
Step 3: Set Up the Database
1. Define Models:
In lf_box/models.py:
python
Copy
class Item(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
location = models.CharField(max_length=100)
date = models.DateField()
image = models.ImageField(upload_to='item_images/')
def __str__(self):
return self.title
2. Run Migrations:
bash
Copy
1. Create an S3 Bucket:
python
Copy
AWS_ACCESS_KEY_ID = 'your-access-key'
AWS_SECRET_ACCESS_KEY = 'your-secret-key'
AWS_STORAGE_BUCKET_NAME = 'your-bucket-name'
AWS_S3_REGION_NAME = 'your-region'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
1. Create Views:
In lf_box/views.py:
python
Copy
def home(request):
items = Item.objects.all()
def post_item(request):
if request.method == 'POST':
if form.is_valid():
item = form.save(commit=False)
item.user = request.user
image_bytes = item.image.read()
labels = detect_labels(image_bytes)
item.labels = ", ".join([label['Name'] for label in labels])
item.save()
return redirect('home')
else:
form = ItemForm()
2. Create Forms:
In lf_box/forms.py:
python
Copy
class ItemForm(forms.ModelForm):
class Meta:
model = Item
3. Create Templates:
o lf_box/templates/lf_box/home.html:
html
Copy
<h1>whops.ie</h1>
<div>
</div>
{% endfor %}
Run HTML
o lf_box/templates/lf_box/post_item.html:
html
Copy
<h1>Post an Item</h1>
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
Run HTML
python
Copy
import boto3
def detect_labels(image_bytes):
rekognition = boto3.client(
'rekognition',
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
region_name=settings.AWS_REGION
response = rekognition.detect_labels(
Image={'Bytes': image_bytes},
MaxLabels=10,
MinConfidence=70
return response['Labels']
1. Update lf_box/urls.py:
python
Copy
urlpatterns = [
python
Copy
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('lf_box.urls')),
bash
Copy
python manage.py runserver
bash
Copy
bash
Copy
3. Create an Environment:
bash
Copy
eb create whops-env
bash
Copy
eb deploy
1. User Authentication:
2. Search Functionality:
3. Notifications:
QnA
When a use uploads an image, Django saves that file in upload to “DESTINATION_PATH”, and saves
the path of the image to database.
This links each item to a specific user who posted it. Creates a relationship between the Item model
and User model. And if the user is deleted, the items associated with the user will be deleted.
And then we run python manage.py migrate, so python can apply these changes to database.
Item: The model representing a lost or found item (imported from models.py).
detect_labels: A utility function for detecting labels in an image using AWS Rekognition (imported
from utils.py).
def home(request):
items = Item.objects.all()
return render(request, 'lf_box/home.html', {'items' : items})
This is home function for listing al the objects present on home page. Render specifies the template
as home.html file. And passess items (list of all objects) to items in the home.html file.
In home.html, we have a for loop which prints info for each item.
<li>
</li>
{% endfor %}
Need to properly understand how the media files are being shown on the
home page in this process. Which parts of urls.py are and settings,py are
responsible. And how media is referencing the media directory inside the
whops folder in the the whole process.