'Get current subscription settings'

def _get_subscription(self, subscription_id=None):

    db = current.db
    s3db = current.s3db
    pe_id = current.auth.user.pe_id
    stable = s3db.pr_subscription
    if (subscription_id is not None):
        ftable = s3db.pr_filter
        rows = db(stable).select()
        query = (((((stable.deleted != True) & (stable.id == subscription_id)) & (stable.pe_id == pe_id)) & (stable.owned_by_group == None)) & (stable.owned_by_user == current.auth.user.id))
        left = ftable.on((ftable.id == stable.filter_id))
        row = db(query).select(stable.id, stable.method, stable.comments, stable.attachment, ftable.id, ftable.query, left=left, limitby=(0, 1)).first()
    else:
        row = None
    output = {'pe_id': pe_id}
    get_vars = {}
    if (subscription_id is None):
        cap_languages = current.deployment_settings.get_cap_languages()
        if (len(cap_languages) > 1):
            default_option_language = None
            default_user_language = current.auth.user.language
            if default_user_language:
                if (default_user_language == 'en'):
                    default_user_language = 'en-US'
                if (default_user_language in cap_languages):
                    default_option_language = default_user_language
            if (default_option_language is not None):
                get_vars = {'language__belongs': default_option_language}
    if (row and (row is not None)):
        s = getattr(row, 'pr_subscription')
        f = getattr(row, 'pr_filter')
        rtable = s3db.pr_subscription_resource
        query = ((rtable.subscription_id == s.id) & (rtable.deleted != True))
        rows = db(query).select(rtable.id, rtable.resource, rtable.url, rtable.last_check_time, rtable.next_check_time)
        if f.query:
            filters = json.loads(f.query)
            for (k, v) in filters:
                if (v is None):
                    continue
                if (k in get_vars):
                    if (type(get_vars[k]) is list):
                        get_vars[k].append(v)
                    else:
                        get_vars[k] = [get_vars[k], v]
                else:
                    get_vars[k] = v
        output.update({'id': s.id, 'filter_id': f.id, 'get_vars': get_vars, 'resources': rows, 'notify_on': ['new'], 'frequency': 'immediately', 'method': s.method, 'comments': s.comments, 'attachment': s.attachment})
    else:
        output.update({'id': None, 'filter_id': None, 'get_vars': get_vars, 'resources': None, 'notify_on': ['new'], 'frequency': 'immediately', 'method': stable.method.default, 'comments': None, 'attachment': False})
    return output
