@contextfunction
def htform(context, form):
    "Set time zone"

    request = context['request']

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.HARDTREE_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get('default_timezone')[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get('default_timezone', user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = getattr(
            settings, 'HARDTREE_SERVER_TIMEZONE')[default_timezone][0]

    all_timezones = getattr(settings, 'HARDTREE_SERVER_TIMEZONE', [
                            (1, '(GMT-11:00) International Date Line West')])
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if not form.errors:
        for field in form:
            try:
                date = datetime.strptime(
                    str(field.form.initial[field.name]), "%Y-%m-%d %H:%M:%S")
                if date:
                    if sign == "-":
                        field.form.initial[
                            field.name] = date - timedelta(hours=hours, minutes=mins)
                    else:
                        field.form.initial[
                            field.name] = date + timedelta(hours=hours, minutes=mins)
            except:
                pass

    return form
dataset/ETHPy150Open treeio/treeio/treeio/core/templatetags/modules.py/htform/original