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

feat: Separate ticket for each attendee #7458

Merged
merged 4 commits into from
Nov 22, 2020

Conversation

codedsun
Copy link
Contributor

Fixes #7397 feat: Ticket pdf path made with attendee identifier

Short description of what this resolves:

Changes proposed in this pull request:

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@auto-label auto-label bot added the feature label Nov 19, 2020
@codedsun
Copy link
Contributor Author

Directory Structure

image

Ticket Holder
image

Ticket purchaser
image

@codecov
Copy link

codecov bot commented Nov 20, 2020

Codecov Report

Merging #7458 (a3cf1a1) into development (8a65edc) will decrease coverage by 0.00%.
The diff coverage is 28.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #7458      +/-   ##
===============================================
- Coverage        65.39%   65.38%   -0.01%     
===============================================
  Files              265      265              
  Lines            13234    13249      +15     
===============================================
+ Hits              8654     8663       +9     
- Misses            4580     4586       +6     
Impacted Files Coverage Δ
app/api/helpers/order.py 63.50% <0.00%> (+0.46%) ⬆️
app/api/helpers/storage.py 63.93% <ø> (ø)
app/models/order.py 88.50% <0.00%> (ø)
app/api/custom/orders.py 66.30% <21.42%> (-4.43%) ⬇️
app/api/custom/invoices.py 41.30% <33.33%> (+3.00%) ⬆️
app/models/ticket_holder.py 78.08% <60.00%> (-1.33%) ⬇️
app/api/schema/microlocations.py 100.00% <0.00%> (ø)
app/models/microlocation.py 95.65% <0.00%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a65edc...5558cda. Read the comment docs.

@order_blueprint.route('/attendees/<int:attendee_id>.pdf')
@jwt_required
def ticket_attendee_pdf(attendee_id):
if current_user:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of this check

@jwt_required
def ticket_attendee_pdf(attendee_id):
if current_user:
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too broad try block

except FileNotFoundError:
return NotFoundError({'source': ''}, 'File Not found')
else:
raise ForbiddenError({'source': ''}, 'Unauthorized Access')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use early return

try:
return send_from_directory('../', file_path, as_attachment=True)
except FileNotFoundError:
return NotFoundError({'source': ''}, 'File Not found')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if the file doesn't exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What shall be the behaviour?

@codedsun codedsun force-pushed the ticket-attendee branch 2 times, most recently from bccccb8 to a8c1b00 Compare November 21, 2020 06:32
try:
return send_from_directory('../', file_path, as_attachment=True)
except FileNotFoundError:
return NotFoundError({'source': ''}, 'File Not found')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should generate the file and send if file not found

):

raise ForbiddenError({'source': ''}, 'Unauthorized Access')
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of else

Comment on lines 175 to 179
if os.path.exists(file_path):
return send_from_directory('../', file_path, as_attachment=True)
else:
create_pdf_tickets_for_holder(ticket_holder.order)
return send_from_directory('../', file_path, as_attachment=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if os.path.exists(file_path):
return send_from_directory('../', file_path, as_attachment=True)
else:
create_pdf_tickets_for_holder(ticket_holder.order)
return send_from_directory('../', file_path, as_attachment=True)
if not os.path.isfile(file_path):
create_pdf_tickets_for_holder(ticket_holder.order)
return send_from_directory('../', file_path, as_attachment=True)

Think of the simplest way to achieve a solution which minimizes duplication

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this change needs to be in other endpoint as well

try:
return send_from_directory('../', file_path, as_attachment=True)
except FileNotFoundError:
if not os.path.exists(file_path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not os.path.exists(file_path):
if not os.path.isfile(file_path):

Copy link
Contributor Author

@codedsun codedsun Nov 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamareebjamal - this change should be done everywhere then because i read that isfile will return true only when it points to a file while exist can return true for a directory also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pdf is a file, not a directory

Copy link
Member

@iamareebjamal iamareebjamal Nov 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my past review, I wrote isfile only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my bad apologies.

try:
return send_from_directory('../', file_path, as_attachment=True)
except FileNotFoundError:
if not os.path.exists(file_path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not os.path.exists(file_path):
if not os.path.isfile(file_path):

@iamareebjamal iamareebjamal changed the title feat: Ticket pdf path made with attendee identifier feat: Separate ticket for each attendee Nov 22, 2020
@iamareebjamal iamareebjamal merged commit 4a77516 into fossasia:development Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ticket PDF should exist for each attendee
2 participants