def celery_get_notification(*args, **kwargs): '''Connect to https://notify.unifispot.com/notify.json and get notifications ''' current_app.logger.info( '-----------Running celery_get_notification-----------------------') accounts = Account.query.all() response = requests.get('http://notify.unifispot.com/notify.json') response.raise_for_status() data = response.json() for notify in data.get('notifications'): if not Notification.check_notify_added(notify.get('notifi_id')): #check if version id specified if notify.get('version') and compare_versions( notify.get('version'), version) != 0: break elif notify.get('min_version') and compare_versions( notify.get('min_version'), version) == 1: break elif notify.get('max_version') and compare_versions( notify.get('max_version'), version) == -1: break for account in accounts: db.session.add( Notification(content=notify['content'], notifi_type=notify['notifi_type'], notifi_id=notify['notifi_id'], user_id=0, account_id=account.id)) db.session.commit() return 1
def notifications(user): notifications = [] notifications = Notification.get_user_notifications(user.account.id,user.id) if user.check_admin(): notifications.extend(Notification.get_common_notifications(user.account.id)) notify_text = '' for notify in notifications: notify_text +='''<div class="alert alert-%s alert-dismissable" id="notification-%s"> <button aria-hidden="true" data-dismiss="alert" id="%s" class="close close-notification" type="button">x</button> %s </div>'''%(notify.get_type(),notify.id,notify.id,notify.content) return notify_text
def notifications(user): notifications = [] notifications = Notification.get_user_notifications( user.account.id, user.id) if user.check_admin(): notifications.extend( Notification.get_common_notifications(user.account.id)) notify_text = '' for notify in notifications: notify_text += '''<div class="alert alert-%s alert-dismissable" id="notification-%s"> <button aria-hidden="true" data-dismiss="alert" id="%s" class="close close-notification" type="button">x</button> %s </div>''' % (notify.get_type(), notify.id, notify.id, notify.content) return notify_text
def celery_get_notification(*args, **kwargs): '''Connect to https://notify.unifispot.com/notify.json and get notifications ''' current_app.logger.info('-----------Running celery_get_notification-----------------------') accounts = Account.query.all() response = requests.get('http://notify.unifispot.com/notify.json') response.raise_for_status() data = response.json() for notify in data.get('notifications'): if not Notification.check_notify_added(notify.get('notifi_id')): #check if version id specified if notify.get('version') and compare_versions(notify.get('version'),version) != 0: break elif notify.get('min_version') and compare_versions(notify.get('min_version'),version) == 1: break elif notify.get('max_version') and compare_versions(notify.get('max_version'),version) == -1: break for account in accounts: db.session.add(Notification(content=notify['content'],notifi_type=notify['notifi_type'], notifi_id=notify['notifi_id'],user_id=0,account_id=account.id)) db.session.commit() return 1