'Build form for subscription settings'

def create_form(self):

    T = current.T
    db = current.db
    response = current.response
    user = current.auth.user.pe_id
    stable = current.s3db.pr_subscription
    formstyle = current.deployment_settings.get_ui_formstyle()
    query = ((stable.pe_id == user) & (stable.deleted != True))
    row = db(query).select(stable.id, stable.frequency, stable.email_format, limitby=(0, 1))
    messages = Storage(ERROR=T('Error:    could    not    update    subscription    settings'), SUCCESS=T('Settings    updated'))
    if row:
        freq_field = stable.frequency
        format_field = stable.email_format
        freq_field.default = row[0].frequency
        format_field.default = row[0].email_format
        form = SQLFORM.factory(freq_field, format_field, formstyle=formstyle)
        if form.accepts(current.request.post_vars, current.session, keepvalues=True):
            formvars = form.vars
            from templates.SSF.config import TaskSubscriptions
            sub = TaskSubscriptions()
            sub.subscription['frequency'] = formvars.frequency
            sub.subscription['email_format'] = formvars.email_format
            if sub.update_subscription():
                response.confirmation = messages.SUCCESS
            else:
                response.error = messages.ERROR
        return form
    else:
        return None
