Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-090
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-090
2021-090
Commits
0718938b
Commit
0718938b
authored
Nov 09, 2021
by
IT18111170-Silva S.H.I
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated: discount model
parent
8f2fdda6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
33 deletions
+50
-33
Agri_Backend/Agripreneur_App/Routes/PricePage.py
Agri_Backend/Agripreneur_App/Routes/PricePage.py
+50
-33
No files found.
Agri_Backend/Agripreneur_App/Routes/PricePage.py
View file @
0718938b
from
extensions
import
mongo
,
db
from
extensions
import
mongo
,
db
from
Main
import
app
from
Main
import
app
from
flask
import
Response
,
request
,
send_from_directory
from
flask
import
Response
,
request
,
send_from_directory
,
session
# import pymongo
# import pymongo
import
json
import
json
from
bson.objectid
import
ObjectId
from
bson.objectid
import
ObjectId
...
@@ -18,47 +18,64 @@ def get_image(filename):
...
@@ -18,47 +18,64 @@ def get_image(filename):
return
send_from_directory
(
os
.
path
.
join
(
root_dir
,
"Agri_Backend"
),
filename
,
as_attachment
=
True
)
return
send_from_directory
(
os
.
path
.
join
(
root_dir
,
"Agri_Backend"
),
filename
,
as_attachment
=
True
)
@
app
.
route
(
"/discount/<id>"
,
methods
=
[
"GET"
])
@
app
.
route
(
"/discount/<id>"
,
methods
=
[
"GET"
])
@
check_for_token
@
check_for_token
def
calculate_discount
(
id
):
def
calculate_discount
(
id
):
request
.
headers
id
=
session
[
'Auth'
][
'_id'
]
# should have payload wi9th the user detaisl and it is send to FE
# should have payload wi9th the user detaisl and it is send to FE
user_earns
=
db
.
CropData
.
find
({
"userID._id"
:
ObjectId
(
id
)},)
user_earns
=
db
.
CropData
.
find_one
({
"_id"
:
ObjectId
(
id
)})
# print(user_earns)
# print(user_earns)
mongores
=
list
(
user_earns
)
print
(
mongores
)
user_points
=
user_earns
[
'points'
]
for
user
in
mongores
:
user
[
"points"
]
=
str
(
user
[
"points"
])
print
(
user
[
"points"
])
earnsUser
=
int
(
user
[
"points"
])
# print(user_points)
# print(user_points)
if
user_points
==
1
:
try
:
discount
=
1
elif
user_points
==
2
:
discount
=
2
elif
user_points
==
3
:
discount
=
3
elif
user_points
==
4
:
discount
=
4
elif
user_points
==
5
:
discount
=
5
elif
user_points
==
6
:
discount
=
6
elif
user_points
==
7
:
discount
=
7
elif
user_points
==
8
:
discount
=
8
elif
user_points
==
9
:
discount
=
9
elif
user_points
==
10
:
discount
=
10
payload
=
user_earns
[
"userID"
]
print
(
payload
)
# abc = json.stringify(payload)
if
earnsUser
==
1
:
# print(abc)
discount
=
1
# TypeError: exceptions must derive from BaseException
elif
earnsUser
==
2
:
discount
=
2
elif
earnsUser
==
3
:
discount
=
3
elif
earnsUser
==
4
:
discount
=
4
elif
earnsUser
==
5
:
discount
=
5
elif
earnsUser
==
6
:
discount
=
6
elif
earnsUser
==
7
:
discount
=
7
elif
earnsUser
==
8
:
discount
=
8
elif
earnsUser
==
9
:
discount
=
9
elif
earnsUser
==
10
:
discount
=
10
print
(
discount
)
return
Response
(
return
Response
(
response
=
json
.
dumps
({
"
Discount percentage"
:
discount
,
"payload"
:
json
.
loads
(
dumps
(
payload
))
}),
response
=
json
.
dumps
({
"
message"
:
discount
}),
status
=
200
,
status
=
200
,
)
except
Exception
as
Ex
:
print
(
"**********"
)
print
(
Ex
)
return
Response
(
response
=
json
.
dumps
({
"message"
:
"error discount"
}),
status
=
500
,
)
)
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment