Skip to content

Commit

Permalink
Added project code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhumika-Kothwal committed Jan 21, 2022
1 parent 1e38ccf commit 9430c37
Show file tree
Hide file tree
Showing 206 changed files with 25,069 additions and 0 deletions.
Empty file added book_ex/__init__.py
Empty file.
Binary file added book_ex/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added book_ex/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added book_ex/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added book_ex/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added book_ex/__pycache__/views.cpython-38.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions book_ex/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.
5 changes: 5 additions & 0 deletions book_ex/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BookExConfig(AppConfig):
name = 'book_ex'
30 changes: 30 additions & 0 deletions book_ex/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.12 on 2021-12-28 14:39

import django.contrib.gis.db.models.fields
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Book_ex',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('location', django.contrib.gis.db.models.fields.PointField(srid=4326)),
('address', models.CharField(max_length=150)),
('city', models.CharField(max_length=50)),
('book', models.CharField(max_length=200)),
('author', models.CharField(max_length=100)),
('email', models.EmailField(max_length=254)),
('contact', models.CharField(max_length=20)),
('genre', models.CharField(max_length=120)),
],
),
]
Empty file added book_ex/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions book_ex/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib.gis.db import models

class Book_ex(models.Model):
name = models.CharField(max_length=100)
location = models.PointField()
address = models.CharField(max_length=150)
city = models.CharField(max_length=50)
book= models.CharField(max_length=200)
author = models.CharField(max_length=100)
email= models.EmailField(max_length = 254)
contact= models.CharField(max_length=20)
genre= models.CharField(max_length=120)
3 changes: 3 additions & 0 deletions book_ex/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.
12 changes: 12 additions & 0 deletions book_ex/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib import admin
from django.urls import path
from book_ex import views


app_name='book_ex'

urlpatterns = [
path('bookex_form/', views.bookex_form, name='bookex_form'),
path('near_book', views.near_book, name='near_book'),
path('map_near_book/', views.map_near_book, name='map_near_book'),
]
132 changes: 132 additions & 0 deletions book_ex/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from core.models import UserProfileInfo, Book, Author, Genre
from .models import Book_ex
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D
from django.contrib.gis.geos import fromstr
from django.contrib.gis.db.models.functions import Distance
import folium
from core.views import message


# CREATING NEW BOOK NODE
def createBookNode(Title, img_url, genre, author):
bookNode = Book(Title=Title, img_url=img_url, rating=0).save()

if not Author.nodes.get_or_none(name=author):
Author(name=author).save()
authorNode = Author.nodes.get(name=author)

genreNode = Genre.nodes.get(name=genre)

authorNode.wrote.connect(bookNode)
genreNode.bookGenre.connect(bookNode)


# BOOK EXCHANGE FORM
def bookex_form(request):
name=""
address=""
city=""
lat=0.0
long=0.0
book=""
img_url=""
author=""
email=""
contact=""
details=False

if request.method == 'POST' and details==False:
details=True
name = request.POST.get('name')
address= request.POST.get('address')
city= request.POST.get('city')
lat=request.POST.get('lat')
long=request.POST.get('long')
book= request.POST.get('book')
img_url=request.POST.get('img_url')
author=request.POST.get('author')
email=request.POST.get('email')
contact=request.POST.get('contact')
genre=request.POST.get('genre')

location = fromstr(f'POINT({long} {lat})', srid=4326)

bookNode = Book.nodes.get_or_none(Title=book)
if not bookNode:
createBookNode(Title=book, img_url=img_url, genre=genre, author=author)

s=Book_ex(name=name, location=location, address=address, city=city, book=book,author=author, email=email, contact=contact, genre=genre)
#print(type(s))
s.save()
return message(request,'Thank you for submitting your details!')

genreNodes = Genre.nodes.all()
return render(request,'book_ex/bookex_form.html', {"genres":genreNodes})


# finding the nearby users with book req by curr user
def near_book(request):
if request.POST.get('exchange'):
bookTitle = request.POST.get('exchange')
return render(request, 'book_ex/near_book.html', {"book":bookTitle})

else:
lat=0.0
long=0.0
dist=""
near=[]
dirn=[]

lat=request.POST.get('lat')
long=request.POST.get('long')
location = fromstr(f'POINT({long} {lat})', srid=4326)

dist=request.POST.get('dist')
print(location)
book=request.POST.get('book')
bookTitle=request.POST.get('book')
print(book)
if dist=="lt1":
near = Book_ex.objects.annotate(distance=Distance("location", location)/1000).filter(distance__lte=1, book=book).order_by("distance")
elif dist=="lt5":
near = Book_ex.objects.annotate(distance=Distance("location", location)/1000).filter(distance__lte=5, book=book).order_by("distance")
elif dist=="lt10":
near= Book_ex.objects.annotate(distance=Distance("location", location)/1000).filter(distance__lte=10, book=book).order_by("distance")
else:
near= Book_ex.objects.annotate(distance=Distance("location", location)/1000).filter(distance__lte=15, book=book).order_by("distance")

print(near)

m=folium.Map(location=[lat,long],zoom_start=12)

folium.Marker(
[lat,long],
popup='',
tooltip='Your Location!',
icon=folium.Icon(color='red')
).add_to(m),

if len(near)>0:
for book in near:
org_address=book.address.replace(' ','+')
link="https://www.google.com/maps/dir/?api=1&destination=" + org_address
dirn.append(link)
tooltip="Name:"+book.name+" , Email:"+book.email+" , Contact:"+book.contact
folium.Marker(
[book.location.y,book.location.x],
popup='<a href="' + link + '">GetDirection</a>',
tooltip=tooltip
).add_to(m)

m.save('templates/book_ex/map_near_book.html')

return render(request,'book_ex/near_book.html',{'near':near, 'dirn':dirn,'zip':zip(near,dirn),'book':bookTitle, 'submitted':True})


# Showing the user and result on map
def map_near_book(request):
return render(request,'book_ex/map_near_book.html')
Empty file added core/__init__.py
Empty file.
Binary file added core/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/views.cpython-38.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions core/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.
5 changes: 5 additions & 0 deletions core/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CoreConfig(AppConfig):
name = 'core'
48 changes: 48 additions & 0 deletions core/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django import forms
from .models import UserProfileInfo

class UserForm(forms.ModelForm):
first_name = forms.CharField(widget = forms.TextInput(attrs={
'class':'form-control',
'placeholder':'Enter First Name',
}),required=True)

last_name = forms.CharField(widget = forms.TextInput(attrs={
'class':'form-control',
'placeholder':'Enter Last Name',
}),required=True)

email = forms.CharField(widget = forms.EmailInput(attrs={
'class':'form-control',
'placeholder':'Enter Email',
}), required=True)

username = forms.CharField(widget = forms.TextInput(attrs={
'class':'form-control',
'placeholder':'Enter username',
}), required=True)

password = forms.CharField(widget = forms.PasswordInput(attrs={
'class':'form-control',
'placeholder':'Enter password',
}),required=True)

phone = forms.CharField(widget = forms.TextInput(attrs={
'class':'form-control',
'placeholder':'Enter phone number',
}),required=True)

address = forms.CharField(widget = forms.TextInput(attrs={
'class':'form-control',
'placeholder':'Enter address',
}), required=True)

pincode = forms.CharField(widget = forms.TextInput(attrs={
'class':'form-control',
'placeholder':'Enter pincode',
}),required=True)

class Meta():
model = UserProfileInfo
exclude = ['latitude','longitude']

Empty file added core/migrations/__init__.py
Empty file.
Binary file added core/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
44 changes: 44 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django_neomodel import DjangoNode
from neomodel import StructuredNode, RelationshipTo, RelationshipFrom, Relationship, StructuredRel
from neomodel.properties import EmailProperty, DateProperty, StringProperty, FloatProperty, IntegerProperty
from neomodel.cardinality import OneOrMore, One, ZeroOrMore

class RatingRel(StructuredRel):
rating = FloatProperty()

class UserProfileInfo(DjangoNode):
first_name = StringProperty(max_length=30,required = True)
last_name = StringProperty(max_length=150, required = True)
email = EmailProperty(unique=True,required = True)
username = StringProperty(max_length=150, unique=True, required = True)
password = StringProperty(max_length=10,unique=True, required = True)
address = StringProperty(max_length=200)
pincode = StringProperty(max_length=6)
phone = StringProperty(max_length=10, required = True)
latitude = FloatProperty()
longitude = FloatProperty()
favGenres = RelationshipTo('Genre', 'FAVORITEGENRE', cardinality=ZeroOrMore)
favBooks = RelationshipTo('Book', 'FAVORITEBOOK', cardinality=ZeroOrMore)
bookRating = RelationshipTo('Book', 'RATING', model = RatingRel, cardinality=ZeroOrMore)
class Meta:
app_label = 'core'

class Book(DjangoNode):
Title = StringProperty()
img_url = StringProperty()
rating = FloatProperty()
user = RelationshipFrom('UserProfileInfo','FAVORITEBOOK',cardinality=ZeroOrMore)
wrote = RelationshipFrom('Author','WROTE',cardinality=OneOrMore)
genre = RelationshipFrom('Genre', 'GENRE', cardinality=OneOrMore)
bookRating = RelationshipFrom('UserProfileInfo', 'RATING', model = RatingRel, cardinality=ZeroOrMore)

class Author(DjangoNode):
name = StringProperty()
wrote = RelationshipTo('Book','WROTE',cardinality=ZeroOrMore)

class Genre(DjangoNode):
name = StringProperty()
genre_id = IntegerProperty()
bookGenre = RelationshipTo('Book','GENRE',cardinality=ZeroOrMore)
favGenre = RelationshipFrom('UserProfileInfo','FAVORITEGENRE',cardinality=ZeroOrMore)

3 changes: 3 additions & 0 deletions core/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.
14 changes: 14 additions & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.urls import path
from core import views
app_name = 'core'

urlpatterns = [
path('search_by_name', views.search_by_name, name='search_by_name'),
path('search_by_genre', views.search_by_genre, name='search_by_genre'),
path('search_by_author', views.search_by_author, name='search_by_author'),
path('search_by_similarUser', views.search_by_similarUser, name='search_by_similarUser'),
path('book_details', views.book_details, name='book_details'),
path('user_login',views.user_login,name='user_login'),
path('user_register',views.user_register,name='user_register'),
#url(r'^base/$', views.base, name='base'),
]
Loading

0 comments on commit 9430c37

Please sign in to comment.