#NEWLINE# def _manage_subscriptions( self , resources , filters ) : #NEWLINE# #INDENT# '\n            Custom form to manage subscriptions\n\n            @param resources: available resources config\n            @param filters: filter widgets\n        ' #NEWLINE# from gluon.sqlhtml import SQLFORM #NEWLINE# from gluon.validators import IS_IN_SET #NEWLINE# from s3 import S3GroupedOptionsWidget #NEWLINE# T = current . T #NEWLINE# labels = Storage ( RESOURCES = T ( 'Subscribe To' ) , NOTIFY_ON = T ( 'Notify On' ) , FREQUENCY = T ( 'Frequency' ) , NOTIFY_BY = T ( 'Notify By' ) , MORE = T ( 'More Options' ) , LESS = T ( 'Less Options' ) ) #NEWLINE# messages = Storage ( ERROR = T ( 'Error: could not update notification settings' ) , SUCCESS = T ( 'Notification settings updated' ) ) #NEWLINE# subscription = self . _get_subscription ( ) #NEWLINE# formstyle = SQLFORM . formstyles . bootstrap #NEWLINE# form = FORM ( _id = 'subscription-form' , hidden = { #NEWLINE# #INDENT# 'subscription-filters' : '' , #NEWLINE# #UNINDENT# } ) #NEWLINE# filter_form = S3FilterForm ( filters , clear = False ) #NEWLINE# fieldset = FIELDSET ( filter_form . fields ( None , subscription [ 'get_vars' ] ) , _id = 'subscription-filter-form' ) #NEWLINE# form . append ( fieldset ) #NEWLINE# rows = [ ] #NEWLINE# stable = current . s3db . pr_subscription #NEWLINE# selector = S3GroupedOptionsWidget ( cols = 1 ) #NEWLINE# rows . append ( ( 'trigger_selector__row' , ( '%s:' % labels . NOTIFY_ON ) , selector ( stable . notify_on , subscription [ 'notify_on' ] , _id = 'trigger_selector' ) , '' ) ) #NEWLINE# switch = S3GroupedOptionsWidget ( cols = 1 , multiple = False , sort = False ) #NEWLINE# rows . append ( ( 'frequency_selector__row' , ( '%s:' % labels . FREQUENCY ) , switch ( stable . frequency , subscription [ 'frequency' ] , _id = 'frequency_selector' ) , '' ) ) #NEWLINE# fieldset = formstyle ( form , rows ) #NEWLINE# fieldset . insert ( 0 , DIV ( SPAN ( [ I ( _class = 'icon-reorder' ) , labels . MORE ] , _class = 'toggle-text' , _style = 'display:none' ) , SPAN ( [ I ( _class = 'icon-reorder' ) , labels . LESS ] , _class = 'toggle-text' ) , _id = 'notification-options' , _class = 'control-group' ) ) #NEWLINE# form . append ( fieldset ) #NEWLINE# row = ( 'submit__row' , '' , INPUT ( _type = 'submit' , _value = 'Update Settings' ) , '' ) #NEWLINE# fieldset = formstyle ( form , [ row ] ) #NEWLINE# form . append ( fieldset ) #NEWLINE# script = URL ( c = 'static' , f = 'scripts' , args = [ 'S3' , 's3.subscriptions.js' ] ) #NEWLINE# response = current . response #NEWLINE# response . s3 . scripts . append ( script ) #NEWLINE# if form . accepts ( current . request . post_vars , current . session , formname = 'subscription' , keepvalues = True ) : #NEWLINE# #INDENT# formvars = form . vars #NEWLINE# listify = ( lambda x : ( None if ( not x ) else ( x if ( type ( x ) is list ) else [ x ] ) ) ) #NEWLINE# subscription [ 'subscribe' ] = [ resources [ 0 ] ] #NEWLINE# subscription [ 'filters' ] = form . request_vars . get ( 'subscription-filters' , None ) #NEWLINE# subscription [ 'notify_on' ] = listify ( formvars . notify_on ) #NEWLINE# subscription [ 'frequency' ] = formvars . frequency #NEWLINE# subscription [ 'method' ] = [ 'EMAIL' ] #NEWLINE# success = self . _update_subscription ( subscription ) #NEWLINE# if success : #NEWLINE# #INDENT# response . confirmation = messages . SUCCESS #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response . error = messages . ERROR #NEWLINE# #UNINDENT# #UNINDENT# return form