Skip to content
/ 328 Public

A minimal platform to let you buy and sell nfts, built with Django, PostgreSQL, and Heroku.

Notifications You must be signed in to change notification settings

Dhrumilcse/328

Repository files navigation

328

A minimal platform to let you buy and sell nfts, built with Django, PostgreSQL, and Heroku.

demo.mp4

Workflow

workflow

Features

  1. Authentication and authorization using Django's inbuilt system which uses PBKDF2 algorithm with a SHA256 hash to store passwords. In addition, extended authentication support for third-party, in this case Github, using OAuth 2.0
  2. Buy, Profile, Upload, and Delete pages won't let you in if you are not an authenticated user (access control)
  3. Using AWS S3 for directly and securely storing and retrieving user uploaded images (using Boto3), and using WhiteNoise to serve static files since it serves compressed content and compression can make dramatic reductions in the bandwidth required for your CSS and JS.
  4. A recommendation of other similar images (selecting random at the moment, a simple recommendation based on tags is WIP)
  5. Search for an image (based on title and/or tags)
  6. Payment was handled using secure Stripe Checkout API.


Test Cases

Working with images requires successful generation and deletion of the same, and that requires an authenticated user. Using a helper function to create a temporary test_image, setting up test user, and logging them in to test whether or not our model can upload a new image. Payments, Account, and Nft (main app): each application contains test cases in their respective tests.py files.

# 328/nft/tests.py

# Image upload test
class ImageUploadTest(TestCase):

    # Set-up test user since image uploads require authenticated user
    def setUp(self):
        self.user = User.objects.create_user(
            username='dhrumil',
            email='[email protected]',
            password='iloveshopify'
        )
        
        self.assertTrue(self.client.login(username='dhrumil', password='iloveshopify'))

    # Changing media_root to a temp dir to prevent filiing our media dir with garbage
    @override_settings(MEDIA_ROOT=tempfile.gettempdir())
    def test_image_upload(self):
        temp_file = tempfile.NamedTemporaryFile()
        test_image = get_temporary_image(temp_file)
        image = Nft.objects.create(image=test_image.name)
        self.assertEqual(len(Nft.objects.all()), 1)

Run locally

Working on containerizing the application for easier local runs. Until then, please follow instructions.

  1. Clone the repository
git clone https://github.com/Dhrumilcse/328.git
  1. Rename to maintin local settings
mv 328 shop
+-- 328_local
|   +-- shop
  1. Create and activate virtual environment
# Create
virtualenv venv --python=python3

# Activate
source venv/bin/activate (for mac)
venv\Scripts\activate (for win)
+-- 328_local
|   +-- shop
|   +-- venv
  1. Install dependencies
cd shop
pip install -r requirements.txt
  1. Migrate database
python manage.py makemigrations
python manage.py migrate
  1. Run server
python manage.py runserver

Visit 127.0.0.1:8000/ and you will see the app running.

Upcoming Features

  • Containerize application using Docker for easier local tests
  • Delete Image
  • Sort by New, Old, and Title
  • Upload Bulk Images

About

A minimal platform to let you buy and sell nfts, built with Django, PostgreSQL, and Heroku.

Topics

Resources

Stars

Watchers

Forks