Pixora is a Django-based photo-sharing web application that allows users to create, manage, and share photo albums. It includes user authentication, album management, and features like marking albums as favorites.
- User Authentication: Signup, login, and logout functionalities.
- Album Management: Create, edit, delete albums.
- Photo Upload: Upload photos to specific albums.
- Favorite Albums: Users can mark albums as favorites for quick access.
- Clone the repository:
git clone https://github.com/AaronShenny/pixora.git
- Install dependencies:
pip install -r requirements.txt
- Run migrations:
python manage.py migrate
- Start the development server:
python manage.py runserver
- Visit
http://127.0.0.1:8000/
to access the app. - Sign up and create new albums.
- Upload photos to your albums.
- Share albums using a unique code or link.
Contributions are welcome! Please fork the repository and create a pull request.
This project is licensed under the MIT License.
- Purpose: Renders the home page and displays user albums if they are logged in.
- Details:
verifyLogin(request)
: Verifies if a user is logged in.- If
logined
isTrue
, fetches the user’s albums and favorite albums. - Context dictionary is used to pass data (like
albums
,fav
) to theindex.html
template.
- Purpose: Displays the user dashboard with their albums and favorited albums.
- Details:
- Uses
verifyLogin()
to check login status. - Fetches user-specific albums and favorites, then renders
dashboard.html
. - Redirects to the login page if not logged in.
- Uses
- Purpose: Handles new user registration.
- Details:
- On
POST
, validates theSignupForm
and creates a new user. - Uses
set_password()
to hash the password before saving. - Redirects users to the login page upon successful signup.
- On
- Purpose: Manages user login.
- Details:
- Retrieves
next_url
for post-login redirection. - Validates login form and checks user credentials (
email
andpassword
). - Sets a cookie with login status (
logined
) upon successful login. - Provides user feedback using Django messages for incorrect credentials.
- Retrieves
- Purpose: Checks if a user is logged in using cookies.
- Details:
- Extracts and evaluates the
logined
cookie. - Returns a tuple (
logined
,email
). - Handles cases where the cookie is not set.
- Extracts and evaluates the
- Purpose: Allows logged-in users to create a new album.
- Details:
- Validates the form for album creation.
- Generates a unique
uuid
for each album. - Saves the album details and creates a directory for media uploads.
- Uses
os.makedirs
to create a folder for storing album photos.
- Purpose: Logs out the user.
- Details:
- Redirects to the homepage and deletes the
logined
cookie.
- Redirects to the homepage and deletes the
- Purpose: Displays the contents of a specific album.
- Details:
- Fetches the album by its
code
usingget_object_or_404
. - Retrieves all photos associated with the album.
- Uses
check_ownership()
to determine if the current user is the album owner. - Passes data to
albumview.html
including ownership status and favorited status.
- Fetches the album by its
- Purpose: Handles photo uploads to a specific album.
- Details:
- Uses
ImagesForm
to accept image uploads. - Processes uploaded images in a loop and associates them with the specified album.
- Redirects back to the album view after uploading.
- Uses
- Purpose: Deletes a specific album and its associated media.
- Details:
- Verifies login status and user ownership of the album.
- Uses
shutil.rmtree
to delete the album folder from the filesystem. - Displays success or error messages and redirects to the dashboard.
- Purpose: Removes a specific photo from an album.
- Details:
- Retrieves the photo by its
id
and deletes it from the album. - Deletes the physical image file from the server using
os.remove
.
- Retrieves the photo by its
- Purpose: Allows batch upload of images to an album.
- Details:
- Iterates over uploaded images and saves them to the specified album.
- Redirects to the album view page after completion.
- Purpose: Toggles the favorite status of an album for a user.
- Details:
- Checks if the album is already favorited by the user.
- Adds or removes the album from
FavAlbums
accordingly. - Redirects back to the album view.
- Purpose: Edits the details of an existing album.
- Details:
- Allows changing the album’s name and share status.
- Saves the updated details and redirects back to the album view.
ModelForm
: A Django form class that automatically connects a form to a model, making it easier to create and update database entries.Customers
,Albums
,Photo
: Models from your app, used for form validation and input handling.forms
: Provides various form fields likeCharField
,EmailField
, andFileField
.ValidationError
: Used to raise custom validation errors for input.
- Purpose: Handles user login.
- Fields:
password
: ACharField
usingPasswordInput
to mask input.- Attributes include
class
for CSS styling,placeholder
for input hints, andrequired
to enforce input.
- Attributes include
email
: AnEmailField
with similar attributes.
- Meta:
- Specifies the
Customers
model and includesemail
andpassword
as fields. - Automatically links form validation to the
Customers
model.
- Specifies the
- Purpose: Manages new user registration.
- Fields:
name
: ACharField
for the user’s name.
- Meta:
- Uses the
Customers
model and includes all fields (__all__
).
- Uses the
- Method:
clean_email()
- Custom validation to check if the email already exists in the database.
- Raises a
ValidationError
if the email is already registered.
- Purpose: Handles album creation input.
- Meta:
- Uses the
Albums
model. - Specifies
name
andshare
as fields to manage album details.
- Uses the
- Purpose: Manages image uploads to albums.
- Fields:
images
: UsesFileField
to allow users to upload image files.- Uses
ClearableFileInput
widget to allow users to manage uploaded files. - Set as
required=False
to make image uploads optional.
These forms streamline user interactions by handling input validation, displaying form fields, and connecting user inputs to the database models. If you need a deeper dive into any part of this file, let me know!