Esempio n. 1
0
    def clean_publish_dt(self):
        date = self.cleaned_data['publish_dt']

        if date:
            date = localize_date(date, from_tz=self.timezone, to_tz=settings.TIME_ZONE)

        return date
Esempio n. 2
0
    def clean_publish_dt(self):
        date = self.cleaned_data['publish_dt']

        if date:
            date = localize_date(date,
                                 from_tz=self.timezone,
                                 to_tz=settings.TIME_ZONE)

        return date
Esempio n. 3
0
    def __init__(self, *args, **kwargs):
        # checking for user argument here for a more
        # localized form
        self.user = None
        self.timezone = None

        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)

        super(PostForm, self).__init__(*args, **kwargs)

        # add span class to charfields
        for field in self.fields.values():
            if isinstance(field, forms.fields.CharField):
                if 'class' in field.widget.attrs:
                    field.widget.attrs['class'] = "%s %s" % (
                        field.widget.attrs['class'],
                        'span8',
                    )
                else:
                    field.widget.attrs['class'] = 'span8'

        # disable publish_dt if draft
        if not self.instance.status or self.instance.status == 'draft':
            self.fields['publish_dt'].widget.attrs['disabled'] = 'disabled'

        # get the published dt
        publish_dt = self.instance.publish_dt
        if not publish_dt:
            publish_dt = datetime.now()

        # adjust the date/time to the users preference
        if self.user and not self.user.is_anonymous():
            user_settings = Setting.objects.get(user=self.user)
            self.timezone = user_settings.timezone

            publish_dt = localize_date(publish_dt, to_tz=self.timezone)
        else:
            self.timezone = 'US/Central'
            publish_dt = localize_date(publish_dt, to_tz=self.timezone)

        self.initial['publish_dt'] = publish_dt
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        # checking for user argument here for a more
        # localized form
        self.user = None
        self.timezone = None

        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)

        super(PostForm, self).__init__(*args, **kwargs)

        # add span class to charfields
        for field in self.fields.values():
            if isinstance(field, forms.fields.CharField):
                if 'class' in field.widget.attrs:
                    field.widget.attrs['class'] = "%s %s" % (
                        field.widget.attrs['class'],
                        'span8',
                    )
                else:
                    field.widget.attrs['class'] = 'span8'

        # disable publish_dt if draft
        if not self.instance.status or self.instance.status == 'draft':
            self.fields['publish_dt'].widget.attrs['disabled'] = 'disabled'

        # get the published dt
        publish_dt = self.instance.publish_dt
        if not publish_dt:
            publish_dt = datetime.now()

        # adjust the date/time to the users preference
        if self.user and not self.user.is_anonymous():
            user_settings = Setting.objects.get(user=self.user)
            self.timezone = user_settings.timezone

            publish_dt = localize_date(publish_dt, to_tz=self.timezone)
        else:
            self.timezone = 'US/Central'
            publish_dt = localize_date(publish_dt, to_tz=self.timezone)

        self.initial['publish_dt'] = publish_dt
Esempio n. 5
0
def localize(dt, user):
    from_tz = settings.TIME_ZONE
    to_tz = "US/Central"

    if not dt:
        return None

    # get the users timezone
    if not user.is_anonymous():
        user_settings = Setting.objects.get(user=user)
        to_tz = user_settings.timezone

    return localize_date(dt, from_tz=from_tz, to_tz=to_tz)
Esempio n. 6
0
def localize(dt, user):
    from_tz = settings.TIME_ZONE
    to_tz = "US/Central"

    if not dt:
        return None

    # get the users timezone
    if not user.is_anonymous():
        user_settings = Setting.objects.get(user=user)
        to_tz = user_settings.timezone

    return localize_date(dt, from_tz=from_tz, to_tz=to_tz)