-
Notifications
You must be signed in to change notification settings - Fork 5
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
Unique coupon code in org and assignee email in item #295
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
99aa110
checking for unique coupon code in org
aa2ea08
forgot to add participant view
e869c4a
linting fix
cac63a4
added makefile for easy build
0843da1
added csrf token in form
76755a1
added link to github issue and 404
e451301
fixed timezone in query
b93cd35
fixed item collection description and error message for assignee details
ac9bd18
removed field specific errors
e7107b4
Move webpack config and package json to assets folder. Add Make file.…
vidya-ram df70ee7
Merge branch 'fix-coupon-code' of https://github.com/hasgeek/boxoffic…
vidya-ram b991f0c
removed extra fields from AssigneeForm
3f30b87
fix form save
332bb25
added todo for sending notification on asignee update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
cd boxoffice/static; make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
from .order_refund import * | ||
from .discount import * | ||
from .category import * | ||
from .participant import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from baseframe import __ | ||
import baseframe.forms as forms | ||
|
||
from boxoffice.models import Assignee, Item, LineItem | ||
|
||
__all__ = ['AssigneeForm'] | ||
|
||
|
||
class AssigneeForm(forms.Form): | ||
email = forms.EmailField( | ||
__("Email"), | ||
validators=[forms.validators.DataRequired(), forms.validators.Length(max=254)], | ||
) | ||
fullname = forms.StringField( | ||
__("Full Name"), validators=[forms.validators.DataRequired()] | ||
) | ||
phone = forms.StringField( | ||
__("Phone number"), validators=[forms.validators.DataRequired()] | ||
) | ||
city = forms.StringField(__("City"), validators=[forms.validators.DataRequired()]) | ||
company = forms.StringField( | ||
__("Company"), validators=[forms.validators.DataRequired()] | ||
) | ||
jobtitle = forms.StringField( | ||
__("Job Title"), validators=[forms.validators.DataRequired()] | ||
) | ||
subscribe = forms.BooleanField( | ||
__("Sign up to be notified about HasGeek events"), | ||
validators=[forms.validators.DataRequired()], | ||
) | ||
|
||
def validate_email(self, field): | ||
existing_assignees = ( | ||
Assignee.query.join(LineItem) | ||
.filter(LineItem.item == self.edit_parent.item) | ||
.filter(Assignee.email == field.data) | ||
) | ||
if self.edit_obj is not None: | ||
existing_assignees = existing_assignees.filter( | ||
Assignee.id != self.edit_obj.id | ||
) | ||
if existing_assignees.count() > 0: | ||
raise forms.ValidationError(__("Email address has been already used")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: assets | ||
|
||
assets: | ||
npm install | ||
npm run build | ||
|
||
buildonly: | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,95 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from flask import request, jsonify, make_response | ||
from .. import app | ||
from ..models import db | ||
from ..models import LineItem, Assignee | ||
from ..models import Order | ||
from coaster.views import load_models | ||
from flask import jsonify, make_response, request | ||
|
||
from boxoffice.mailclient import send_ticket_assignment_mail | ||
from utils import xhr_only | ||
|
||
from coaster.views import load_models, render_with | ||
|
||
from .. import app | ||
from ..forms import AssigneeForm | ||
from ..models import Assignee, LineItem, Order, db | ||
|
||
|
||
@app.route('/participant/<access_token>/assign', methods=['GET', 'OPTIONS', 'POST']) | ||
@xhr_only | ||
@load_models( | ||
(Order, {'access_token': 'access_token'}, 'order') | ||
) | ||
@render_with(json=True) | ||
@load_models((Order, {'access_token': 'access_token'}, 'order')) | ||
def assign(order): | ||
""" | ||
Assign a line_item to a participant | ||
""" | ||
assignee_dict = request.json.get('attendee') | ||
if not request.json or not assignee_dict or not assignee_dict.get('email') or not assignee_dict.get('fullname'): | ||
return make_response(jsonify(status='error', error='missing_attendee_details', error_description="Attendee details are missing"), 400) | ||
line_item = LineItem.query.get(request.json.get('line_item_id')) | ||
if line_item.is_cancelled: | ||
return make_response(jsonify(status='error', error='cancelled_ticket', error_description="Ticket has been cancelled"), 400) | ||
|
||
item_assignee_details = line_item.item.assignee_details | ||
assignee_details = {} | ||
if item_assignee_details: | ||
for key in item_assignee_details.keys(): | ||
assignee_details[key] = assignee_dict.get(key) | ||
if line_item.current_assignee and assignee_dict['email'] == line_item.current_assignee.email: | ||
# updating details of the current assignee | ||
line_item.current_assignee.fullname = assignee_dict['fullname'] | ||
line_item.current_assignee.phone = assignee_dict['phone'] | ||
line_item.current_assignee.details = assignee_details | ||
db.session.commit() | ||
if line_item is None: | ||
return { | ||
'status': 'error', | ||
'error': 'missing_line_item', | ||
'error_description': u"Invalid line item", | ||
} | ||
iambibhas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif line_item.is_cancelled: | ||
return ( | ||
{ | ||
'status': 'error', | ||
'error': 'cancelled_ticket', | ||
'error_description': u"Ticket has been cancelled", | ||
}, | ||
400, | ||
) | ||
|
||
if line_item.current_assignee is not None: | ||
assignee_form = AssigneeForm.from_json( | ||
request.json.get('attendee'), | ||
obj=line_item.current_assignee, | ||
parent=line_item, | ||
csrf_token=request.json.get('csrf_token'), | ||
) | ||
else: | ||
iambibhas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assignee_form = AssigneeForm.from_json( | ||
request.json.get('attendee'), | ||
parent=line_item, | ||
csrf_token=request.json.get('csrf_token'), | ||
) | ||
|
||
if assignee_form.validate_on_submit(): | ||
item_assignee_details = line_item.item.assignee_details | ||
assignee_details = {} | ||
if item_assignee_details: | ||
for key in item_assignee_details.keys(): | ||
assignee_details[key] = assignee_form.data.get(key) | ||
if ( | ||
line_item.current_assignee | ||
and assignee_form.data['email'] == line_item.current_assignee.email | ||
): | ||
# updating details of the current assignee | ||
line_item.current_assignee.fullname = assignee_form.data['fullname'] | ||
line_item.current_assignee.phone = assignee_form.data['phone'] | ||
line_item.current_assignee.details = assignee_details | ||
db.session.commit() | ||
else: | ||
if line_item.current_assignee: | ||
# Archive current assignee | ||
line_item.current_assignee.current = None | ||
new_assignee = Assignee( | ||
current=True, | ||
email=assignee_form.data.get('email'), | ||
fullname=assignee_form.data.get('fullname'), | ||
phone=assignee_form.data.get('phone'), | ||
details=assignee_details, | ||
line_item=line_item, | ||
) | ||
db.session.add(new_assignee) | ||
db.session.commit() | ||
send_ticket_assignment_mail.queue(line_item.id) | ||
return {'status': 'ok', 'result': {'message': 'Ticket assigned'}} | ||
else: | ||
if line_item.current_assignee: | ||
# Archive current assignee | ||
line_item.current_assignee.current = None | ||
new_assignee = Assignee(current=True, email=assignee_dict.get('email'), fullname=assignee_dict.get('fullname'), | ||
phone=assignee_dict.get('phone'), details=assignee_details, line_item=line_item) | ||
db.session.add(new_assignee) | ||
db.session.commit() | ||
send_ticket_assignment_mail.queue(line_item.id) | ||
return make_response(jsonify(status='ok', result={'message': 'Ticket assigned'}), 201) | ||
return ( | ||
{ | ||
'status': 'error', | ||
'error': 'invalid_assignee_details', | ||
'error_description': ", ".join( | ||
[str(err.pop()) for err in assignee_form.errors.values()] | ||
iambibhas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
}, | ||
400, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I get the difference between these two queries. Explain it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously it was searching for other instances of the same code being used in the same discount policy. I changed it to look inside the same organization until we figure out how to do it within the same item collection. Right now there is no relationship between a discount policy and an item collection, and discount coupons are created within an organization, and not an item collection. Hence this.