desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Helper function. Test response for 200 status code. Also test if response body contains event/service name.'
def _test_path(self, path, *strings):
with app.test_request_context(): login(self.app, u'test@example.com', u'test') response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) for string in strings: self.assertIn(string, response.data) headers_keys = [key.lower() ...
'Create Event but don\'t define services for it.'
def setUp(self):
self.app = Setup.create_app() with app.test_request_context(): register(self.app, u'test@example.com', u'test') create_event(creator_email=u'test@example.com')
'Helper function. Test response for 404 status code. Also test if response body contains \'does no exist\' string.'
def _test_path(self, path):
with app.test_request_context(): login(self.app, u'test@example.com', u'test') response = self.app.get(path) self.assertEqual(response.status_code, 404) self.assertIn('does not exist', response.data)
'Helper function. Test response for 200 status code. Also test if response body contains event/service name.'
def _test_path(self, path, service1, service2):
with app.test_request_context(): login(self.app, u'test@example.com', u'test') response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) self.assertIn(service1, response.data) self.assertIn(service2, response.data)
'Checks the one to many relationship between event and social_links'
def test_add_social_link_to_db(self):
self.app = Setup.create_app() with app.test_request_context(): event = ObjectMother.get_event() social_link1 = SocialLink(name='Link1', link='some_random_link_1', event_id='1') social_link2 = SocialLink(name='Link2', link='some_random_link_2', event_id='1') save_to_db(event, 'Eve...
'Unicode handling for Event model'
def test_event_name(self):
with app.test_request_context(): try: str(Event.query.get(1)) except UnicodeEncodeError: self.fail('UnicodeEncodeError for event')
'Unicode handling for Microlocation model'
def test_microlocation_name(self):
with app.test_request_context(): try: str(Microlocation.query.get(1)) except UnicodeEncodeError: self.fail('UnicodeEncodeError for microlocation')
'Unicode handling for Session model'
def test_session_title(self):
with app.test_request_context(): try: str(Session.query.get(1)) except UnicodeEncodeError: self.fail('UnicodeEncodeError for session')
'Unicode handling for Sponsor model'
def test_sponsor_name(self):
with app.test_request_context(): try: str(Sponsor.query.get(1)) except UnicodeEncodeError: self.fail('UnicodeEncodeError for sponsor')
'Unicode handling for Speaker model'
def test_speaker_name(self):
with app.test_request_context(): try: str(Speaker.query.get(1)) except UnicodeEncodeError: self.fail('UnicodeEncodeError for speaker')
'Checks the one to many relationship between event and session_types and the many to one relationship between session and session_types'
def test_add_session_type_to_db(self):
self.app = Setup.create_app() with app.test_request_context(): event = ObjectMother.get_event() session1 = ObjectMother.get_session() session_type1 = SessionType(name='Type1', length='30', event_id='1') session_type2 = SessionType(name='Type2', length='30', event_id='1') ...
'Helper function. Test response for 200 status code. Also test if response body contains event/service name.'
def _test_path(self, path, *strings):
with app.test_request_context(): response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) for string in strings: self.assertIn(string, response.data)
'tests swagger.json. Also writes the file so that auto-build of gh-pages can run'
def test_swagger_json(self):
resp = self.app.get('/api/v1/swagger.json') self.assertIn('event', resp.data) data = json.loads(resp.data) fp = open('static/uploads/swagger.json', 'w') fp.write(json.dumps(data, indent=2, sort_keys=True)) fp.close()
'Registers an email and logs in.'
def _login_user(self):
with app.test_request_context(): login(self.app, u'test@example.com', u'test')
'Tests - 1. Without login, try to do a PUT request and catch 401 error 2. Login and match 200 response code and make sure that data changed'
def _test_model(self, name, data, path=None, *args):
if (not path): path = (get_path(1) if (name == 'event') else get_path(1, (name + 's'), 1)) response = self._put(path, data) self.assertEqual(401, response.status_code, msg=response.data) self._login_user() response = self._put(path, data) self.assertEqual(200, response.status_code, msg=r...
'exports and extracts in static/uploads/test_event_import'
def _create_set(self, event_id=1, config=None):
if (config is None): config = {'image': True} resp = self._do_successful_export(event_id, config) zip_file = StringIO() zip_file.write(resp.data) path = 'static/uploads/test_event_import' if os.path.isdir(path): shutil.rmtree(path, ignore_errors=True) with zipfile.ZipFile(zip...
'test successful export of media, unicode and more'
def test_export_media(self):
resp = self._put(get_path(1), {'logo': 'https://placehold.it/350x150'}) self.assertIn('placehold', resp.data, resp.data) resp = self._put(get_path(1, 'speakers', 1), {'photo': 'https://placehold.it/350x150'}) resp = self._put(get_path(1, 'sponsors', 1), {'photo': 'https://placehold.it/350x150'}) res...
'test if export settings are marshalled by default properly Also check when settings are all False, nothing is exported'
def test_export_settings_marshal(self):
resp = self._put(get_path(1), {'logo': 'https://placehold.it/350x150'}) self.assertIn('placehold', resp.data, resp.data) self._create_set(1, {}) dr = 'static/uploads/test_event_import' data = open((dr + '/event'), 'r').read() obj = json.loads(data) self.assertIn('placehold', obj['logo']) ...
'Tests order of export of fields in export files'
def test_export_order(self):
self._create_set() dr = 'static/uploads/test_event_import' data = open((dr + '/event'), 'r').read() self.assertTrue((data.find('id') < data.find('background_image'))) self.assertTrue((data.find('location_name') < data.find('copyright'))) self.assertTrue((data.find('event_ver') < data.find('track...
'tests if error is returned correctly. Needed after task was run through celery'
def test_import_validation_error(self):
with app.test_request_context(): speaker = Speaker(name='SP', email='invalid_email', organisation='org', country='japan', event_id=1) save_to_db(speaker, 'speaker invalid saved') self._test_import_error(checks=['Invalid', 'email', '400'])
'Registers an email and logs in.'
def _login_user(self):
with app.test_request_context(): login(self.app, u'test@example.com', u'test')
'Logs in a user and creates model. Tests for 200 status on deletion and for the deleted object. Tests that the deleted object no longer exists.'
def _test_model(self, name, data):
self._login_user() path = (get_path() if (name == 'event') else get_path(1, (name + 's'))) response = self.app.post(path, data=json.dumps(data), headers={'Content-Type': 'application/json'}) self.assertEqual(response.status_code, 201) path = (get_path(1) if (name == 'event') else get_path(1, (name +...
'Test successful uploads of relative and direct links, both types of media'
def test_media_successful_uploads(self):
self._create_set() self._update_json('event', 'background_image', '/bg.png') self._create_file('bg.png') self._update_json('speakers', 'photo', '/spkr.png', 1) self._create_file('spkr.png') self._update_json('sponsors', 'logo', 'http://google.com/favicon.ico', 1) data = self._make_zip_from_d...
'Tests when relative link to a media if non-existant'
def test_non_existant_media_import(self):
self._create_set() self._update_json('event', 'background_image', '/non.png') data = self._make_zip_from_dir() event_dic = self._do_succesful_import(data) self.assertEqual(event_dic['background_image'], None)
'Tests if version data is being preserved'
def test_version_preserved(self):
self._create_set() data_old = json.loads(open('static/uploads/test_event_import/event').read()) data = self._make_zip_from_dir() event_dic = self._do_succesful_import(data) for i in data_old['version']: self.assertEqual(data_old['version'][i], event_dic['version'][i], (json.dumps(data_old['v...
'Registers an email and logs in.'
def _login_user(self):
with app.test_request_context(): login(self.app, u'test@example.com', u'test')
'send a post request to a url'
def post_request(self, path, data):
return self.app.post(path, data=json.dumps(data), headers={'content-type': 'application/json'})
'Tests - 1. Without login, try to do a POST request and catch 401 error 2. Login and match 201 response code and correct response data Param: checks - list of strings to assert in successful response data'
def _test_model(self, name, data, path=None, checks=[]):
if (not path): path = (get_path() if (name == 'event') else get_path(1, (name + 's'))) response = self.post_request(path, data) self.assertEqual(401, response.status_code, msg=response.data) self._login_user() response = self.post_request(path, data) self.assertEqual(201, response.status...
'Test to make sure extra key added in payload is removed'
def test_session_api_extra_payload(self):
extraData = POST_SESSION_DATA.copy() extraData['new_key_2'] = 'value' self._test_model('session', extraData)
'sends a login request and returns the response'
def _send_login_request(self, password):
response = self.app.post('/api/v1/login', data=json.dumps({'email': 'myemail@gmail.com', 'password': password}), headers={'content-type': 'application/json'}) return response
'1. Test getting JWT token with wrong credentials and getting 401 2. Get JWT token with right credentials 3. Send a sample successful POST request'
def _test_model(self, name, data):
path = (get_path() if (name == 'event') else get_path(1, (name + 's'))) response = self._send_login_request('wrong_password') self.assertEqual(response.status_code, 401) response = self._send_login_request('test') self.assertEqual(response.status_code, 200) token = json.loads(response.data)['acc...
'send a post request to a url'
def post(self, path, data):
return self.app.post(path, data=json.dumps(data), headers={'content-type': 'application/json'})
'test export and import of pentabarf'
def test_export_import(self):
self._publishEvent(1) resp = self.app.get('/api/v1/events/1') identifier = json.loads(resp.data).get('identifier') resp = self.app.get(('/e/%s/schedule/pentabarf.xml' % identifier)) self.assertEqual(resp.status_code, 200) self.assertIn('conference', resp.data) print resp.data resp = self...
'test export and import of ical'
def test_export_import(self):
self._publishEvent(1) resp = self.app.get('/api/v1/events/1') identifier = json.loads(resp.data).get('identifier') resp = self.app.get(('/e/%s/schedule/calendar.ics' % identifier)) self.assertEqual(resp.status_code, 200) self.assertIn('BEGIN:VEVENT', resp.data) self.assertIn('TestSpeaker', r...
'test export and import of xcal'
def test_export_import(self):
self._publishEvent(1) resp = self.app.get('/api/v1/events/1') identifier = json.loads(resp.data).get('identifier') resp = self.app.get(('/e/%s/schedule/calendar.xcs' % identifier)) self.assertEqual(resp.status_code, 200) self.assertIn('TestSpeaker', resp.data) self.assertIn('TestSession', re...
'Sets a random value to each of the :fields in :data and makes sure PUT request failed. At last check if original value had prevailed'
def _test_model(self, name, data, fields=None):
if (fields is None): fields = [] path = (get_path(1) if (name == 'event') else get_path(1, (name + 's'), 1)) self._login_user() for field in fields: data_copy = data.copy() data_copy[field] = 'r@nd0m_g00d_for_n0thing_v@lue' response = self._put(path, data_copy) se...
'Sets a random value to each of the :fields in :data and makes sure POST request failed'
def _test_model(self, name, data, fields=None):
if (fields is None): fields = [] path = (get_path() if (name == 'event') else get_path(1, (name + 's'))) self._login_user() for field in fields: data_copy = data.copy() data_copy[field] = 'r@nd0m_g00d_for_n0thing_v@lue' response = self.post_request(path, data_copy) ...
'send a post request to a url'
def _post(self, path, data):
resp = self.app.post(path, data=json.dumps(data), headers={'content-type': 'application/json'}) self.assertEqual(resp.status_code, 201) return resp
'Tests the 404 response, then add item and test the success response'
def _test_model(self, name):
login(self.app, u'test@example.com', u'test') path = get_path(1, (name + 's'), 'page') response = self.app.get(path, follow_redirects=True) self.assertEqual(response.status_code, 404) with app.test_request_context(): create_services(1) response = self.app.get(path, follow_redirects=True)...
'Helper function to return json from the url'
def _json_from_url(self, url):
response = self.app.get(url) self.assertEqual(response.status_code, 200) return json.loads(response.data)
'Tests - 1. When just one item, check if next and prev urls are empty 2. When one more item added, limit results to 1 and see if next is not empty 3. start from position 2 and see if prev is not empty'
def _test_model(self, name):
login(self.app, u'test@example.com', u'test') if (name == 'event'): path = get_path('page') else: path = get_path(1, (name + 's'), 'page') data = self._json_from_url(path) self.assertEqual(data['next'], '') self.assertEqual(data['previous'], '') with app.test_request_context(...
'Register blueprints :param app: a flask app instance :return:'
@staticmethod def register(app):
app.register_blueprint(pages) app.register_blueprint(home_routes) app.register_blueprint(utils_routes) app.register_blueprint(sitemaps) app.register_blueprint(babel) app.register_blueprint(event_invoicing) app.register_blueprint(ticketing) app.register_blueprint(event_detail) app.reg...
'Method return all events'
@staticmethod def get_all_events():
return Event.query.order_by(desc(Event.created_at)).filter_by(deleted_at=None).all()
'Method return all events'
@staticmethod def get_all_events_with_discounts():
return Event.query.order_by(desc(Event.id)).filter_by(deleted_at=None).filter((Event.discount_code_id is not None)).filter((Event.discount_code_id > 0)).all()
'Method return all events'
@staticmethod def get_all_users_events_roles():
return UsersEventsRoles.query
':return: All Sessions with correct event_id'
@staticmethod def get_sessions_by_event_id(event_id):
return Session.query.filter_by(event_id=event_id).filter(Session.deleted_at.is_(None))
':return: All Sessions with correct event_id'
@staticmethod def get_sessions_by_state(state):
return Session.query.filter((Session.state == state)).filter(Session.deleted_at.is_(None))
':return: Filtering sessions by event id and session state'
@staticmethod def get_sessions_by_state_and_event_id(state, event_id):
return Session.query.filter((Session.event_id == event_id)).filter((Session.state == state)).filter(Session.deleted_at.is_(None))
':param event_id: Event id :return: All Track with event id'
@staticmethod def get_tracks(event_id):
return Track.query.filter_by(event_id=event_id)
':return: All Tracks filtered by event_id'
@staticmethod def get_tracks_by_event_id():
return Track.query.filter_by(event_id=get_event_id())
':param state: State of the session :param event_id: Event id :return: Return all Sessions objects with Event id'
@staticmethod def get_sessions(event_id, state='accepted'):
return Session.query.filter_by(event_id=event_id, state=state).filter(Session.deleted_at.is_(None))
':return: Image Sizes'
@staticmethod def get_image_sizes():
return ImageSizes.query.all()
':return: Image Sizes'
@staticmethod def get_image_sizes_by_type(type):
return ImageSizes.query.filter_by(type=type).first()
':return: Image Configs'
@staticmethod def get_image_configs():
return ImageConfig.query.all()
':param event_id: Event id :return: Return json element of custom form'
@staticmethod def get_custom_form_elements(event_id):
return CustomForms.query.filter_by(event_id=event_id).first()
':return: Return Sessions object with the current user as a speaker by ID'
@staticmethod def get_sessions_of_user_by_id(session_id, user=login.current_user):
try: return Session.query.filter(Session.speakers.any((Speaker.user_id == user.id))).filter((Session.id == session_id)).filter(Session.deleted_at.is_(None)).one() except MultipleResultsFound: return None except NoResultFound: return None
':return: Return all Sessions objects with the current user as a speaker'
@staticmethod def get_sessions_of_user(upcoming_events=True, user_id=None):
if upcoming_events: return Session.query.filter(Session.speakers.any((Speaker.user_id == (login.current_user.id if (not user_id) else int(user_id))))).filter((Session.starts_at >= datetime.datetime.now())).filter(Session.deleted_at.is_(None)) else: return Session.query.filter(Session.speakers.an...
':param event_id: Event id :return: Speaker objects filter by event_id'
@staticmethod def get_speakers(event_id):
return Speaker.query.filter_by(event_id=event_id).order_by(asc(Speaker.name))
':param event_id: Event id :return: All Sponsors filtered by event_id'
@staticmethod def get_sponsors(event_id):
return Sponsor.query.filter_by(event_id=event_id)
':param event_id: Event id :return: All Microlocation filtered by event_id'
@staticmethod def get_microlocations(event_id):
return Microlocation.query.filter_by(event_id=event_id)
':return: All Microlocation filtered by event_id'
@staticmethod def get_microlocations_by_event_id():
return Microlocation.query.filter_by(event_id=get_event_id())
':param microlocation_id: Microlocation id :return: Microlocation with microlocation_id'
@staticmethod def get_microlocation(microlocation_id):
return Microlocation.query.get(microlocation_id)
':return: All system users'
@staticmethod def get_all_users():
return User.query.all()
':return: User'
@staticmethod def get_user(user_id):
return User.query.get(int(user_id))
'Returns an Event given its id/identifier. Aborts with a 404 if event not found. :returns Event :rtype: Event'
@staticmethod def get_event(event_id_or_identifier, should_abort=True):
if represents_int(event_id_or_identifier): event = Event.query.get(event_id_or_identifier) else: event = Event.query.filter_by(identifier=event_id_or_identifier).first() if ((event is None) and should_abort): abort(404) return event
'Returns an Event given its /identifier. Aborts with a 404 if event not found.'
@staticmethod def get_event_by_identifier(identifier):
event = Event.query.filter_by(identifier=identifier).first() if (event is None): abort(404) return event
'return only those events where current_user has non-attendee permissions access'
@staticmethod def trim_attendee_events(events, user_id):
return [_ for _ in events if _.has_staff_access(user_id)]
'Get session by id'
@staticmethod def get_session(session_id):
return Session.query.get(session_id)
'Get speaker by id'
@staticmethod def get_speaker(speaker_id):
return Speaker.query.get(speaker_id)
'Get speaker by id'
@staticmethod def get_speaker_by_email(email_id):
return Speaker.query.filter_by(email=email_id)
'Get speaker by id'
@staticmethod def get_speaker_by_email_event(email_id, event_id):
return Speaker.query.filter_by(email=email_id).filter_by(event_id=event_id)
':param event_id: Event id :return: All Tracks filtered by event_id'
@staticmethod def get_session_types_by_event_id(event_id):
return SessionType.query.filter_by(event_id=event_id)
':param event_id: Event id :return: All Tracks filtered by event_id'
@staticmethod def get_social_links_by_event_id(event_id):
return SocialLink.query.filter_by(event_id=event_id)
'Get All Mails by latest first'
@staticmethod def get_all_mails(count=300):
mails = Mail.query.order_by(desc(Mail.time)).limit(count).all() return mails
'Get all notifications, latest first.'
@staticmethod def get_all_notifications(count=300):
notifications = Notification.query.order_by(desc(Notification.received_at)).limit(count).all() return notifications
'Get all available timezones :return:'
@staticmethod def get_all_timezones():
return [(item, ((('(UTC' + datetime.datetime.now(pytz.timezone(item)).strftime('%z')) + ') ') + item)) for item in pytz.common_timezones]
'Get all activities by recent first'
@staticmethod def get_all_activities(count=300):
activities = Activity.query.order_by(desc(Activity.time)).limit(count).all() return activities
'Get all imports by user by recent first'
@staticmethod def get_imports_by_user(count=50, user_id=None):
imports = ImportJob.query.filter_by(user=(login.current_user if (not user_id) else int(user_id))).order_by(desc(ImportJob.starts_at)).limit(count).all() return imports
'Get Module with the largest id (latest Module).'
@staticmethod def get_module():
return Module.query.order_by(desc(Module.id)).first()
'get export job for an event'
@staticmethod def get_export_jobs(event_id):
return ExportJob.query.filter_by(event_id=event_id).first()
'Make a GET request :param return_json: :param params: :param headers: :param endpoint: :return:'
def get(self, endpoint, headers=None, params=None, return_json=True):
if (not headers): headers = self.headers response = requests.get((self.api_url + endpoint), headers=headers, params=params, verify=False) if return_json: return response.json() else: return response.text
'Get all pods under a namespace :param namespace: :return:'
def get_pods(self, namespace=None):
if (not namespace): namespace = self.namespace return self.get((('namespaces/' + namespace) + '/pods'))
':param namespace: :param pod: :return:'
def get_logs(self, pod, namespace=None):
if (not namespace): namespace = self.namespace params = {'pretty': 'true', 'tailLines': 100} return self.get((((('namespaces/' + namespace) + '/pods/') + pod) + '/log'), return_json=False, params=params)
'Make a GET request :param params: :param headers: :param endpoint: :return:'
def get(self, endpoint, headers=None, params=None):
if (not headers): headers = self.headers return requests.get((self.api_url + endpoint), headers=headers, verify=False, params=params).json()
'Get the latest heroku release :return:'
def get_latest_release(self):
new_headers = self.headers new_headers['Range'] = 'version ..; max=1, order=desc' return self.get('releases', headers=new_headers)[0]
':return:'
def get_logplex_url(self):
params = {'tail': True, 'dyno': 'web.1', 'lines': 100, 'source': 'app'} return self.get('log-sessions', params=params).get('logplex_url')
'Create a User Notification :param user: User object to send the notification to :param action: Action being performed :param title: The message title :param message: The message'
@staticmethod def create_user_notification(user, action, title, message):
notification = Notification(user=user, action=action, title=title, message=message, received_at=datetime.now()) saved = save_to_db(notification, 'User notification saved')
'Mark a particular notification read.'
@staticmethod def mark_user_notification_as_read(notification):
notification.is_read = True save_to_db(notification, 'Mark notification as read')
'Mark all notifications for a User as read.'
@staticmethod def mark_all_user_notification_as_read(user):
unread_notifs = Notification.query.filter_by(user=user, is_read=False) for notif in unread_notifs: notif.is_read = True db.session.add(notif) db.session.commit()
'Save an event role invite to database and return accept and decline links. :param email: Email for the invite :param role_name: Role name for the invite :param event_id: Event id'
@staticmethod def add_event_role_invite(email, role_name, event_id):
role = Role.query.filter_by(name=role_name).first() event = Event.query.get(event_id) role_invite = RoleInvite(email=email.lower(), event=event, role=role, created_at=datetime.now()) hash = random.getrandbits(128) role_invite.hash = ('%032x' % hash) save_to_db(role_invite, 'Role Invite sav...
'Invite will be saved to database with proper Event id and User id :param user_id: Invite belongs to User by user id :param event_id: Invite belongs to Event by event id'
@staticmethod def add_invite_to_event(user_id, event_id):
new_invite = Invite(user_id=user_id, event_id=event_id) hash = random.getrandbits(128) new_invite.hash = ('%032x' % hash) save_to_db(new_invite, 'Invite saved') record_activity('invite_user', event_id=event_id, user_id=user_id)
'Settings will be toggled to database with proper User id'
@staticmethod def toggle_email_notification_settings(user_id, value):
events = DataGetter.get_all_events() user = DataGetter.get_user(user_id) notification_ids = [] for event in events: if (user.is_speaker_at_event(event.id) or user.is_organizer(event.id)): email_notification = DataGetter.get_email_notification_settings_by_event_id(user_id, event.id) ...
'Session will be saved to database with proper Event id :param no_name: :param use_current_user: :param state: :param request: The request :param event_id: Session belongs to Event by event id'
@staticmethod def add_session_to_event(request, event_id, state=None, use_current_user=True, no_name=False):
form = request.form slide_temp_url = form.get('slides_url') video_temp_url = form.get('video_url') audio_temp_url = form.get('audio_url') slide_file = '' video_file = '' audio_file = '' if slide_temp_url: slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_...
'Session will be saved to database with proper Event id :param session_id: :param user: :param request: view data form :param event_id: Session belongs to Event by event id'
@staticmethod def add_speaker_to_session(request, event_id, session_id, user=login.current_user):
session = DataGetter.get_session(session_id) speaker = save_speaker(request, event_id, user=user) session.speakers.append(speaker) sessions_modified.send(current_app._get_current_object(), event_id=session.event_id) save_to_db(session, 'Session updated') update_version(event_id, False, 'speak...
'Speaker will be saved to database with proper Event id :param no_name: :param user: :param request: view data form :param event_id: Speaker belongs to Event by event id'
@staticmethod def add_speaker_to_event(request, event_id, user=login.current_user, no_name=False):
speaker = Speaker.query.filter_by(email=request.form.get('email', '')).filter_by(event_id=event_id).first() speaker = save_speaker(request, event_id=event_id, speaker=speaker, user=user, no_name=no_name) update_version(event_id, False, 'speakers_ver')
'Role will be removed from database :param uer_id: Role id to remove object'
@staticmethod def remove_role(uer_id):
uer = UsersEventsRoles.query.get(uer_id) record_activity('delete_role', role=uer.role, user=uer.user, event_id=uer.event_id) delete_from_db(uer, 'UER deleted') flash("You've successfully deleted role.")
'Return date with proper format'
def format_date(self, date):
return str(date.strftime('%Y-%m-%dT%H:%M:%S%Z'))
'Update version in db'
def update(self):
previous_version = Version.query.filter_by(event_id=self.event_id).order_by(Version.id.desc()).first() if (not previous_version): version = Version(event_id=self.event_id) db.session.add(version) db.session.commit() else: self._create_new_version(previous_version)
'Set version info of an event to data'
def set(self, data):
previous_version = Version.query.filter_by(event_id=self.event_id).order_by(Version.id.desc()).first() if (not previous_version): previous_version = Version(event_id=self.event_id, **data) else: for key in data: setattr(previous_version, key, data[key]) db.session.add(previou...
':return: Return all order objects with the current user'
@staticmethod def get_orders_of_user(user_id=None, upcoming_events=True):
if (not user_id): user_id = login.current_user.id query = Order.query.join(Order.event).filter((Order.user_id == user_id)).filter(or_((Order.status == 'completed'), (Order.status == 'placed'))) if upcoming_events: return query.filter((Event.starts_at >= datetime.now())) else: ret...