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
loginedisTrue, fetches the user’s albums and favorite albums. - Context dictionary is used to pass data (like
albums,fav) to theindex.htmltemplate.
- 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 theSignupFormand 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_urlfor post-login redirection. - Validates login form and checks user credentials (
emailandpassword). - 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
loginedcookie. - 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
uuidfor each album. - Saves the album details and creates a directory for media uploads.
- Uses
os.makedirsto create a folder for storing album photos.
- Purpose: Logs out the user.
- Details:
- Redirects to the homepage and deletes the
loginedcookie.
- Redirects to the homepage and deletes the
- Purpose: Displays the contents of a specific album.
- Details:
- Fetches the album by its
codeusingget_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.htmlincluding ownership status and favorited status.
- Fetches the album by its
- Purpose: Handles photo uploads to a specific album.
- Details:
- Uses
ImagesFormto 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.rmtreeto 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
idand 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
FavAlbumsaccordingly. - 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: ACharFieldusingPasswordInputto mask input.- Attributes include
classfor CSS styling,placeholderfor input hints, andrequiredto enforce input.
- Attributes include
email: AnEmailFieldwith similar attributes.
- Meta:
- Specifies the
Customersmodel and includesemailandpasswordas fields. - Automatically links form validation to the
Customersmodel.
- Specifies the
- Purpose: Manages new user registration.
- Fields:
name: ACharFieldfor the user’s name.
- Meta:
- Uses the
Customersmodel and includes all fields (__all__).
- Uses the
- Method:
clean_email()- Custom validation to check if the email already exists in the database.
- Raises a
ValidationErrorif the email is already registered.
- Purpose: Handles album creation input.
- Meta:
- Uses the
Albumsmodel. - Specifies
nameandshareas fields to manage album details.
- Uses the
- Purpose: Manages image uploads to albums.
- Fields:
images: UsesFileFieldto allow users to upload image files.- Uses
ClearableFileInputwidget to allow users to manage uploaded files. - Set as
required=Falseto 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!