Exemple #1
0
    def test_update_profile(self):
        url = reverse('view_profile')

        # Test profile update with the same email - Nothing happens
        response = self.c.post(url, {'email': '*****@*****.**', 'timezone': 'UTC',})


        self.assertRedirects(response, reverse('view_profile'), status_code=302)

        user_preferences = user_preferences_model.get_preferences(user_id=self.user.id)

        assert user_preferences['timezone'] == 'UTC'
        


        response = self.c.post(url, {'email': '*****@*****.**', 'timezone': 'Europe/Sofia',})

        user_preferences = user_preferences_model.get_preferences(user_id=self.user.id)

        assert user_preferences['timezone'] == 'Europe/Sofia'


        # Test profile update with the same email
        response = self.c.post(url, {'email': '*****@*****.**',  'timezone': 'UTC'})

        self.assertRedirects(response, reverse('view_profile'), status_code=302)


        updated_user = User.objects.get(id=self.user.id)

        assert updated_user.email == '*****@*****.**'
Exemple #2
0
    def process_request(self, request):

        #  Defaults
        request.now = datetime.utcnow()
        request.debug = settings.DEBUG
        request.version = VERSION

        request.timezone = 'UTC'

        if request.user.is_authenticated():
            user_preferences = user_preferences_model.get_preferences(user_id=request.user.id)

            user_timezone = user_preferences.get('timezone', 'UTC')
            request.timezone = str(user_timezone)  # Pytz timezone object
            request.timezone_offset = localtime_utc_timedelta(tz=request.timezone)

            request.account_id = settings.ACCOUNT_ID

            request.dashboards = dashboard_model.get_all(account_id=request.account_id)

            request.bookmarks = bookmarks_model.get_all()

            # Enable disable minified js and css files
            try:
                request.devmode = settings.DEVMODE
            except:
                request.devmode = False
Exemple #3
0
    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)

        user_preferences = user_preferences_model.get_preferences(
            user_id=self.user.id)
        user_timezone = user_preferences.get('timezone', 'UTC')

        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['timezone'].widget.attrs.update({
            'select2-dropdown': '',
            'data-size': 360
        })

        self.fields['timezone'].initial = user_timezone
        self.fields['email'].initial = self.user.email