'Generate and process the form
@param r: the S3Request
@param attr: dict of controller parameters'

def create_form(self, r, **attr):

    authorised = self._permitted(method='create')
    if (not authorised):
        r.unauthorised()
    s3db = current.s3db
    T = current.T
    response = current.response
    settings = current.deployment_settings
    output = {'title': T('Create    Residents    Report')}
    table = s3db.dvr_site_activity
    table.date.default = r.utcnow.date()
    formfields = [table.site_id, table.date]
    from gluon import INPUT, A, SQLFORM
    submit_btn = INPUT(_class='tiny    primary    button', _name='submit', _type='submit', _value=T('Create    Report'))
    cancel_btn = A(T('Cancel'), _href=r.url(id=None, method=''), _class='action-lnk')
    buttons = [submit_btn, cancel_btn]
    resourcename = r.resource.name
    formstyle = settings.get_ui_formstyle()
    form = SQLFORM.factory(record=None, showid=False, formstyle=formstyle, table_name=resourcename, buttons=buttons, *formfields)
    output['form'] = form
    formname = ('%s/manage' % resourcename)
    if form.accepts(r.post_vars, current.session, formname=formname, onvalidation=self.validate, keepvalues=False, hideerror=False):
        from s3 import S3PermissionError, s3_store_last_record_id
        formvars = form.vars
        report = DRKSiteActivityReport(site_id=formvars.site_id, date=formvars.date)
        try:
            record_id = report.store()
        except S3PermissionError:
            current.auth.permission.homepage = r.url(id=None, method='')
            r.unauthorised()
        r.resource.lastid = str(record_id)
        s3_store_last_record_id('dvr_site_activity', record_id)
        current.response.confirmation = T('Report    created')
        self.next = r.url(id=record_id, method='read')
    response.view = self._view(r, 'create.html')
    return output
