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

fix: Check if identifier does not contain of all digits. #6572

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

##### v1.8.0 (Unreleased):

- No Changes
- Run `python manage.py fix_digit_identifier` to correct all digit identifiers

##### v1.7.0 (2019-10-19):

Expand Down
6 changes: 2 additions & 4 deletions app/models/event.py
Expand Up @@ -28,8 +28,7 @@

def get_new_event_identifier(length=8):
identifier = str(binascii.b2a_hex(os.urandom(int(length / 2))), 'utf-8')
count = get_count(Event.query.filter_by(identifier=identifier))
if count == 0:
if not identifier.isdigit() and get_count(Event.query.filter_by(identifier=identifier)) == 0:
return identifier
else:
return get_new_event_identifier(length)
Expand Down Expand Up @@ -364,7 +363,7 @@ def get_average_rating(self):

def is_payment_enabled(self):
return self.can_pay_by_paypal or self.can_pay_by_stripe or self.can_pay_by_omise or self.can_pay_by_alipay \
or self.can_pay_by_cheque or self.can_pay_by_bank or self.can_pay_onsite or self.can_pay_by_paytm
or self.can_pay_by_cheque or self.can_pay_by_bank or self.can_pay_onsite or self.can_pay_by_paytm

@property
def average_rating(self):
Expand Down Expand Up @@ -455,7 +454,6 @@ def has_speakers(self):
return Speaker.query.filter_by(event_id=self.id).count() > 0



@event.listens_for(Event, 'after_update')
@event.listens_for(Event, 'after_insert')
def receive_init(mapper, connection, target):
Expand Down
9 changes: 9 additions & 0 deletions manage.py
Expand Up @@ -37,6 +37,15 @@ def add_event_identifier():
save_to_db(event)


@manager.command
def fix_digit_identifier():
events = Event.query.filter(Event.identifier.op('~')('^[0-9\.]+$')).all()

Choose a reason for hiding this comment

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

invalid escape sequence '.'

for event in events:
event.identifier = get_new_event_identifier()
db.session.add(event)
db.session.commit()


@manager.option('-n', '--name', dest='name', default='all')
@manager.option('-s', '--switch', dest='switch', default='off')
def module(name, switch):
Expand Down