<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def prepare(_next, self):
 """Hook after prepare and set expiration widget to ``self.form``. """

        _next(self)
        cfg = ugm_general(self.model)
        if cfg.attrs['users_account_expiration'] != 'True':
            return
        mode = 'edit'
        if not self.request.has_permission(
                'manage_expiration', self.model.parent):
            mode = 'display'
        if self.action_resource == 'edit':
            attr = cfg.attrs['users_expires_attr']
            unit = int(cfg.attrs['users_expires_unit'])
            value = int(self.model.attrs.get(attr, 0))
            # if format days, convert to seconds
            if unit == 0:
                value *= 86400
        else:
            value = UNSET
        expires_widget = factory(
            'field:label:expiration',
            name='active',
            value=value,
            props={
                'label': _('active', default='Active')
            },
            mode=mode
        )
        save_widget = self.form['save']
        self.form.insertbefore(expires_widget, save_widget)