Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hrutuja/frontend api data #63

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4fde818
setting up app for our project, updating gitignore
kabirlohana Jan 16, 2025
9249c41
updating settings and models to store front covers
kabirlohana Jan 17, 2025
b67db4d
updating to store multiple issue numbers
kabirlohana Jan 17, 2025
52dcb96
building with updated packages
kabirlohana Jan 17, 2025
32c12c9
updating needed libraries and schema metadata
kabirlohana Jan 18, 2025
53de55a
adding frontend code
kabirlohana Jan 18, 2025
62b0588
Added new changes
Jan 19, 2025
3e64e7b
Added new changes for the search page UI
Jan 19, 2025
905f3b7
Added new changes for the Ui
Jan 19, 2025
a0ed8f7
Added new changes for the search page
Jan 19, 2025
44ddc66
Merge pull request #1 from JavascriptFreak/Aishwarya-frontendcode
kabirlohana Jan 19, 2025
0cb4fec
added new the changes for styling of UI
Jan 19, 2025
904cca3
Merge pull request #2 from JavascriptFreak/Aishwarya-frontendcode-des…
kabirlohana Jan 19, 2025
b889997
setting up frontend container
kabirlohana Jan 19, 2025
0b52e71
new changes
s0595769 Jan 19, 2025
7c5839a
new changes for yrs
s0595769 Jan 19, 2025
af855ab
new changes for ui
s0595769 Jan 19, 2025
9df77be
new changes for ui
s0595769 Jan 19, 2025
f87f62c
new ui changes
s0595769 Jan 19, 2025
d66fc85
new ui changes
s0595769 Jan 19, 2025
3d6809b
Merge pull request #3 from s0595769/Hrutuja
kabirlohana Jan 19, 2025
ce1a2e7
added new changes for filters
Jan 19, 2025
aaf0bab
added new changes for filters
Jan 19, 2025
eb9a62e
Merge pull request #4 from JavascriptFreak/aishwarya-frontend
kabirlohana Jan 20, 2025
e717273
setting up APIs
kabirlohana Jan 20, 2025
a0c8a2c
setting up serializers
kabirlohana Jan 20, 2025
74f457f
setting up api paths
kabirlohana Jan 21, 2025
c9e8910
reworking main magazine issues api and adding api for getting decades
kabirlohana Jan 21, 2025
68bb95a
Delete app/catalog/migrations/0001_initial.py
kabirlohana Jan 22, 2025
1622b57
finalised search api
kabirlohana Jan 22, 2025
4421d31
setting up cors heards for dev
kabirlohana Jan 23, 2025
c811252
fixing package name
kabirlohana Jan 23, 2025
241d5ac
Added new changes for the api integration
s0595769 Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
139 changes: 139 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,145 @@
app/media/
*.pyc
__pycache
.DS_Store
.env.dev
.env.prod
.env.prod.db
# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
media

# Backup files #
*.bak

# If you are using PyCharm #
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# File-based project format
*.iws

# IntelliJ
out/

# JIRA plugin
atlassian-ide-plugin.xml

# Python #
*.py[cod]
*$py.class

# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.whl
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery
celerybeat-schedule.*

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Sublime Text #
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files Package
Control.last-run
Control.ca-list
Control.ca-bundle
Control.system-ca-bundle
GitHub.sublime-settings

# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
2 changes: 2 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ENV PYTHONUNBUFFERED 1
# install system dependencies
RUN apt-get update && apt-get install -y netcat

RUN apt-get install -qq tesseract-ocr libtesseract-dev libleptonica-dev python3-distutils poppler-utils

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
Expand Down
Empty file added app/catalog/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions app/catalog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions app/catalog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CatalogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'catalog'
Empty file.
57 changes: 57 additions & 0 deletions app/catalog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os

from django.core.files.storage import FileSystemStorage
from django.db import models
from django.contrib.postgres.fields import ArrayField
from django.conf import settings

#COVERS_STORAGE = FileSystemStorage(location="/media/covers")
COVERS_STORAGE = FileSystemStorage(location=settings.MEDIA_ROOT)

class MagazineIssue(models.Model):
publication_date = models.DateField()
issue_number = ArrayField(models.IntegerField(), blank=True, default=list)
front_cover = models.ImageField(storage=COVERS_STORAGE)

class Meta:
ordering = ['issue_number']

def get_publication_date(self):
return self.publication_date.strftime("%B/%Y")

def __str__(self):
issues = list(map(lambda x: str(x), self.issue_number))
return f"Issue: {','.join(issues)} - Publication_Date: {self.get_publication_date()}"


class MagazineArticle(models.Model):
issue = models.ForeignKey('MagazineIssue', on_delete=models.CASCADE)
publication_year = models.DateField()
articles = models.ManyToManyField('Author', through='AuthorArticle')
tags = models.ManyToManyField('Tag', through='ArticleTag')


class Author(models.Model):
name = models.CharField(max_length=50)
articles = models.ManyToManyField('MagazineArticle', through='AuthorArticle')

class AuthorArticle(models.Model):
author = models.ForeignKey('Author', on_delete=models.CASCADE)
article = models.ForeignKey('MagazineArticle', on_delete=models.CASCADE)

def __str__(self):
return f"{self.author.__str__()} - {self.article.__str__()}"


class ArticleTag(models.Model):
tag = models.ForeignKey('Tag', on_delete=models.CASCADE)
article = models.ForeignKey('MagazineArticle', on_delete=models.CASCADE)

def __str__(self):
return f"{self.tag.__str__()} - {self.article.__str__()}"


class Tag(models.Model):
name = models.CharField(max_length=30)


11 changes: 11 additions & 0 deletions app/catalog/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from catalog.models import MagazineIssue
from rest_framework import serializers

class MagazineIssueSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = MagazineIssue
fields = '__all__'
def to_representation(self, instance):
representation = super(MagazineIssueSerializer, self).to_representation(instance)
representation["publication_date"] = instance.get_publication_date()
return representation
3 changes: 3 additions & 0 deletions app/catalog/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
97 changes: 97 additions & 0 deletions app/catalog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from catalog.models import MagazineIssue
from rest_framework.viewsets import ModelViewSet
from rest_framework.response import Response
from rest_framework.decorators import action
from collections import defaultdict
from django.db.models import Q

from catalog.serializers import MagazineIssueSerializer

def format_into_datetime(datetime_str):
from datetime import datetime
return datetime.strptime(datetime_str, '%B-%Y')

def parse_issue_id(issue_id_str):
return {
"issue_number": int(issue_id_str.split("-")[0]),
"issue_year": int(issue_id_str.split("-")[1]),
}

def get_q_object_for_issue_range(issue_range, parsed_issue_param):
return Q(issue_number__contained_by=issue_range,
publication_date__year=parsed_issue_param["issue_year"])


class MagazineIssueViewSet(ModelViewSet):
queryset = MagazineIssue.objects.all()
serializer_class = MagazineIssueSerializer

def list(self, request):
queryset = self.filter_queryset(self.get_queryset())
serializer_output = self.serializer_class(queryset, many=True, context={'request': request}).data

d=defaultdict(list)
for instance in serializer_output:
pub_year = instance['publication_date'].split('/')[1]
d[pub_year].append(instance)

return Response(d)

@action(detail=False, methods=['get'])
def decades(self, request):
data = self.list(request).data

d=defaultdict(list)
years = data.keys()
for year in years:
year=int(year)
d[int(year - (year%10))].append(year)

return Response(d)

@action(detail=False, methods=['get'])
def search(self, request):
date_begin = request.query_params.get('date_begin', None)
date_end = request.query_params.get('date_end', None)

issue_begin = request.query_params.get('issue_begin', None)
issue_end = request.query_params.get('issue_end', None)

if date_begin:
date_begin = format_into_datetime(date_begin)

if date_end:
date_end = format_into_datetime(date_end)
filter_query = Q(publication_date__range=(date_begin, date_end))
else:
filter_query=Q(publication_date=date_begin)

queryset = self.get_queryset().filter(filter_query)

if issue_begin:
parsed_issue_param = parse_issue_id(issue_begin)

if issue_end:
issue_begin_range = list(range(parsed_issue_param["issue_number"], 5))
filter_query_begin = get_q_object_for_issue_range(issue_begin_range,
parsed_issue_param)

parsed_issue_param_end = parse_issue_id(issue_end)
issue_end_range = list(range(1, parsed_issue_param_end["issue_number"]+1))
filter_query_end = get_q_object_for_issue_range(issue_end_range,
parsed_issue_param_end)

queryset_begin = self.get_queryset().filter(filter_query_begin)
queryset_end = self.get_queryset().filter(filter_query_end)
queryset = queryset_begin.union(queryset_end)

else:
filter_query=get_q_object_for_issue_range([parsed_issue_param["issue_number"]],
parsed_issue_param)
queryset = self.get_queryset().filter(filter_query)

queryset = queryset.order_by('publication_date')

serializer_output = self.serializer_class(queryset, many=True, context={'request': request}).data

return Response(serializer_output)
2 changes: 1 addition & 1 deletion app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ then
echo "PostgreSQL started"
fi

python manage.py flush --no-input
#python manage.py flush --no-input
python manage.py migrate

exec "$@"
19 changes: 14 additions & 5 deletions app/hello_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each.
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]'
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
ALLOWED_HOSTS = ['localhost'] #os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")

CSRF_TRUSTED_ORIGINS = ["http://localhost:1337"]

Expand All @@ -39,8 +39,10 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",

"upload",
"catalog.apps.CatalogConfig",
"django_extensions",
"rest_framework",
'corsheaders'
]

MIDDLEWARE = [
Expand All @@ -51,8 +53,12 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware'
]

CORS_ALLOW_ALL_ORIGINS = True

ROOT_URLCONF = "hello_django.urls"

TEMPLATES = [
Expand Down Expand Up @@ -126,8 +132,11 @@
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"

MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "mediafiles"
#MEDIA_URL = "/media/"
#MEDIA_ROOT = BASE_DIR / "mediafiles"

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = 'media/'


# Default primary key field type
Expand Down
Loading