Skip to content

Commit

Permalink
Merge branch 'art-show-launch' into fix-override-price-calc
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsuta committed Sep 28, 2023
2 parents d2fa66e + 1e8f5d6 commit d839b85
Show file tree
Hide file tree
Showing 22 changed files with 488 additions and 388 deletions.
10 changes: 7 additions & 3 deletions uber/model_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,8 @@ def discounted_price(app):


ArtShowPiece.required = [('name', 'Name'),
('for_sale','If this piece is for sale'),
('gallery', 'Gallery'),
('type', 'Type'),
('media', 'Media')]
('type', 'Type')]


@validation.ArtShowPiece
Expand Down Expand Up @@ -905,6 +903,12 @@ def print_run_if_print(piece):
return "What you entered for the print edition or run total ({}/{}) isn't even a number".format(piece.print_run_num, piece.print_run_total)


@validation.ArtShowPiece
def media_if_original(piece):
if piece.type == c.ORIGINAL and not piece.media:
return "Please describe what medium your original art is on."


@validation.ArtShowPiece
def price_checks_if_for_sale(piece):
if piece.for_sale:
Expand Down
16 changes: 12 additions & 4 deletions uber/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,16 +1039,24 @@ def create_admin_account(self, attendee, password='', generate_pwd=True, **param
self.add(new_account)
return new_account

def create_attendee_account(self, email=None, normalized_email=None, password=None):
from uber.models import Attendee, AttendeeAccount
def create_attendee_account(self, email=None, password=None):
from uber.models import AttendeeAccount
from uber.utils import normalize_email

new_account = AttendeeAccount(email=email, hashed=bcrypt.hashpw(password, bcrypt.gensalt()) if password else '')
new_account = AttendeeAccount(email=normalize_email(email), hashed=bcrypt.hashpw(password, bcrypt.gensalt()) if password else '')
self.add(new_account)

return new_account

def add_attendee_to_account(self, attendee, account):
if c.ONE_MANAGER_PER_BADGE and attendee.managers and account.hashed != '':
from uber.utils import normalize_email

unclaimed_account = account.hashed != ''
if c.SSO_EMAIL_DOMAINS:
local, domain = normalize_email(account.email, split_address=True)
unclaimed_account = unclaimed_account and domain not in c.SSO_EMAIL_DOMAINS

if c.ONE_MANAGER_PER_BADGE and attendee.managers and not unclaimed_account:
attendee.managers.clear()
if attendee not in account.attendees:
account.attendees.append(attendee)
Expand Down
2 changes: 1 addition & 1 deletion uber/models/attendee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ def strip_email(self):

@presave_adjustment
def normalize_email(self):
self.email = normalize_email(self.email)
self.email = normalize_email(self.email).lower()

@hybrid_property
def normalized_email(self):
Expand Down
40 changes: 21 additions & 19 deletions uber/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def __init__(self, receipt=None, receipt_email='', description='', amount=0, cus
if not self.amount:
self.amount = receipt.current_amount_owed
if create_receipt_item:
self.receipt_manager.create_receipt_item(receipt, self.description, self.amount)
self.receipt_manager.create_custom_receipt_item(receipt, self.description, self.amount)

if c.AUTHORIZENET_LOGIN_ID:
self.merchant_auth = apicontractsv1.merchantAuthenticationType(
Expand Down Expand Up @@ -698,7 +698,7 @@ def send_authorizenet_txn(self, txn_type=c.AUTHCAPTURE, **params):
transaction.order = order

transaction.transactionType = c.AUTHNET_TXN_TYPES[txn_type]
transaction.customerIP = cherrypy.request.remote.ip
transaction.customerIP = cherrypy.request.headers.get('X-Forwarded-For', cherrypy.request.remote.ip)

if self.amount:
transaction.amount = Decimal(int(self.amount) / 100)
Expand Down Expand Up @@ -792,16 +792,18 @@ def create_receipt_item(self, receipt, desc, amount):
))

def update_transaction_refund(self, txn, refund_amount):
from uber.models import Session

txn.refunded += refund_amount
self.items_to_add.append(txn)

with Session() as session:
model = session.get_model_by_receipt(txn.receipt)
if isinstance(model, uber.models.Attendee) and model.paid == c.HAS_PAID:
model.paid = c.REFUNDED
self.items_to_add.append(model)
def create_custom_receipt_item(self, receipt, desc, amount):
from uber.models import AdminAccount, ReceiptItem

self.items_to_add.append(ReceiptItem(receipt_id=receipt.id,
desc=desc,
amount=amount,
count=1,
who=AdminAccount.admin_name() or 'non-admin'
))

@classmethod
def create_new_receipt(cls, model, create_model=False, items=None):
Expand Down Expand Up @@ -979,14 +981,6 @@ def auto_update_receipt(self, model, receipt, params):
from uber.models import Attendee, Group, ReceiptItem, AdminAccount
if not receipt:
return []

changed_params = {}
for key, val in params.items():
column = model.__table__.columns.get(key)
if column is not None:
coerced_val = model.coerce_column_data(column, val)
if coerced_val != getattr(model, key, None):
changed_params[key] = coerced_val

receipt_items = []

Expand Down Expand Up @@ -1034,8 +1028,16 @@ def auto_update_receipt(self, model, receipt, params):
if changed_params.get('power_fee', None) != None and c.POWER_PRICES.get(int(changed_params.get('power'), 0), None) == None:
receipt_item = self.add_receipt_item_from_param(model, receipt, 'power_fee', changed_params)
receipt_items += [receipt_item] if receipt_item else []
changed_params.pop('power')
changed_params.pop('power_fee')
params.pop('power')
params.pop('power_fee')

changed_params = {}
for key, val in params.items():
column = model.__table__.columns.get(key)
if column is not None:
coerced_val = model.coerce_column_data(column, val)
if coerced_val != getattr(model, key, None):
changed_params[key] = coerced_val

cost_changes = getattr(model.__class__, 'cost_changes', [])
credit_changes = getattr(model.__class__, 'credit_changes', [])
Expand Down
12 changes: 12 additions & 0 deletions uber/receipt_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,30 @@ def overridden_app_cost(app):

@cost_calculation.ArtShowApplication
def panel_cost(app):
if app.overridden_price != None:
return

return ("General Panel", c.COST_PER_PANEL * 100, 'panels', app.panels) if app.panels else None

@cost_calculation.ArtShowApplication
def table_cost(app):
if app.overridden_price != None:
return

return ("General Table", c.COST_PER_TABLE * 100, 'tables', app.tables) if app.tables else None

@cost_calculation.ArtShowApplication
def mature_panel_cost(app):
if app.overridden_price != None:
return

return ("Mature Panel", c.COST_PER_PANEL * 100, 'panels_ad', app.panels_ad) if app.panels_ad else None

@cost_calculation.ArtShowApplication
def mature_table_cost(app):
if app.overridden_price != None:
return

return ("Mature Table", c.COST_PER_TABLE * 100, 'tables_ad', app.tables_ad) if app.tables_ad else None

@cost_calculation.ArtShowApplication
Expand Down
37 changes: 24 additions & 13 deletions uber/site_sections/art_show_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,31 @@ def save_art_show_piece(self, session, app_id, message='', **params):
piece = session.art_show_piece(params, restricted=restricted, bools=['for_sale', 'no_quick_sale'])
app = session.art_show_application(app_id)

if cherrypy.request.method == 'POST':
piece.app_id = app.id
piece.app = app
message = check(piece)
if not message:
session.add(piece)
if not restricted and 'voice_auctioned' not in params:
piece.voice_auctioned = False
elif not restricted and 'voice_auctioned' in params and params['voice_auctioned']:
piece.voice_auctioned = True
session.commit()
if not params.get('name'):
message += "ERROR: Please enter a name for this piece."
if not params.get('gallery'):
message += "<br>" if not params.get('name') else "ERROR: "
message += "Please select which gallery you will hang this piece in."
if not params.get('type'):
message += "<br>" if not params.get('gallery') or not params.get('name') else "ERROR: "
message += "Please choose whether this piece is a print or an original."
if message:
return {'error': message}

piece.app_id = app.id
piece.app = app
message = check(piece)
if message:
return {'error': message}

session.add(piece)
if not restricted and 'voice_auctioned' not in params:
piece.voice_auctioned = False
elif not restricted and 'voice_auctioned' in params and params['voice_auctioned']:
piece.voice_auctioned = True
session.commit()

return {'error': message,
'success': 'Piece "{}" successfully saved'.format(piece.name)}
return {'success': 'Piece "{}" successfully saved'.format(piece.name)}

@ajax
def remove_art_show_piece(self, session, id, **params):
Expand Down
2 changes: 1 addition & 1 deletion uber/site_sections/preregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def check_account(session, email, password, confirm_password, skip_if_logged_in=
if email and valid_email(email):
return valid_email(email)

super_normalized_old_email = normalize_email_legacy(normalize_email(old_email))
super_normalized_old_email = normalize_email_legacy(normalize_email(old_email)) if old_email else ''

existing_account = session.query(AttendeeAccount).filter_by(normalized_email=normalize_email_legacy(email)).first()
if existing_account and (old_email and normalize_email_legacy(normalize_email(existing_account.email)) != super_normalized_old_email
Expand Down
17 changes: 10 additions & 7 deletions uber/site_sections/reg_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ def assign_account_by_email(session, attendee, account_email):
from uber.site_sections.preregistration import set_up_new_account

account = session.query(AttendeeAccount).filter_by(normalized_email=normalize_email_legacy(account_email)).first()

if c.ONE_MANAGER_PER_BADGE and attendee.managers:
# It's too confusing for an admin to move someone to a new account and still see them on their old account
# If an admin typoes the new account's email, that's a them problem
attendee.managers.clear()

if not account:
if c.ONE_MANAGER_PER_BADGE and attendee.managers:
# It's too confusing for an admin to move someone to a new account and still see them on their old account
# If an admin typoes the new account's email, that's a them problem
attendee.managers.clear()
set_up_new_account(session, attendee, account_email)
session.commit()
return "New account made for {} under email {}.".format(attendee.full_name, account_email)
Expand Down Expand Up @@ -285,7 +287,7 @@ def undo_refund_receipt_item(self, session, id='', **params):
@ajax
def add_receipt_txn(self, session, id='', **params):
receipt = session.model_receipt(id)
model = session.get_model_by_receipt(item.receipt)
model = session.get_model_by_receipt(receipt)

message = check_custom_receipt_item_txn(params, is_txn=True)
if message:
Expand Down Expand Up @@ -611,10 +613,11 @@ def attendee_account_form(self, session, id, message='', **params):

new_email = params.get('new_account_email', '')
if cherrypy.request.method == 'POST' and new_email:
if normalize_email(normalize_email_legacy(new_email)) == normalize_email(account.normalized_email):
normalized_new_email = normalize_email(new_email)
if normalize_email_legacy(normalized_new_email) == normalize_email_legacy(account.normalized_email):
message = "That is already the email address for this account!"
else:
existing_account = session.query(AttendeeAccount).filter_by(normalized_email=normalize_email_legacy(new_email)).first()
existing_account = session.query(AttendeeAccount).filter_by(normalized_email=normalize_email_legacy(normalized_new_email)).first()
if existing_account:
message = "That account already exists. You can instead reassign this account's attendees."
else:
Expand Down
2 changes: 1 addition & 1 deletion uber/templates/art_show_admin/pieces.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"index", "Return to App List", True
) }}
<h2>Art Show Pieces{% if app.attendee %} for {{ app.attendee|form_link }}{% endif %}</h2>
{% include 'art_show_common/art_pieces_form.html' %}
<div class="card"><div class="card-body">{% include 'art_show_common/art_pieces_form.html' %}</div></div>
{% endblock %}
Loading

0 comments on commit d839b85

Please sign in to comment.