Python django.utils.timezone.get_default_timezone_name() Examples

The following are 6 code examples of django.utils.timezone.get_default_timezone_name(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.utils.timezone , or try the search function .
Example #1
Source File: utils.py    From Simple-Q-A-App-using-Python-Django with MIT License 6 votes vote down vote up
def question_score(question):
    creation_date = question.pub_date
    score = question.total_points
    answers_positive_points = list(
        question.answer_set.all().values_list(
            'answervote__value', flat=True)).count(True)
    answers_negative_points = list(
        question.answer_set.all().values_list(
            'answervote__value', flat=True)).count(False)
    score = score * 2 + answers_positive_points - answers_negative_points
    reference_date = pytz.timezone(
        timezone.get_default_timezone_name()).localize(datetime(1970, 1, 1))
    difference = creation_date - reference_date
    difference_seconds = difference.days * 86400 + difference.seconds +\
        (float(difference.microseconds) / 1000000)
    order = log(max(abs(score), 1), 10)
    sign = 1 if score > 0 else -1 if score < 0 else 0
    seconds = difference_seconds - 1134028003
    return round(sign * order + seconds / 45000, 7) 
Example #2
Source File: views.py    From opentaps_seas with GNU Lesser General Public License v3.0 6 votes vote down vote up
def about_view(request):
    g = hszinc.Grid()
    g.column['vendorUri'] = {}
    g.column['productUri'] = {}
    g.column['tz'] = {}
    g.column['serverName'] = {}
    g.column['productName'] = {}
    g.column['haystackVersion'] = {}
    g.column['productVersion'] = {}
    g.column['serverTime'] = {}
    g.column['serverBootTime'] = {}
    g.column['vendorName'] = {}
    g.extend([{
        'vendorUri': 'https://www.opensourcestrategies.com',
        'productUri': 'https://www.opensourcestrategies.com',
        'tz': timezone.get_default_timezone_name(),
        'serverName': Site.objects.get_current().domain,
        'productName': 'Opentaps-SEAS Haystack',
        'haystackVersion': '2.0',
        'productVersion': '1.0',
        'serverTime': timezone.now(),
        'vendorName': 'Opentaps-SEAS Haystack'
    }])
    return _hzinc_response(g) 
Example #3
Source File: tests.py    From django-aws-template with MIT License 5 votes vote down vote up
def testTimeZone(self):
        #tzname = request.session.get('django_timezone')
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, status.HTTP_200_OK)

        # If not loggedin, no timezone in session
        session = self.client.session
        self.assertFalse('django_timezone' in session)

        ok = self.client.login(email='user1@foo.com', password='pass')
        self.assertTrue(ok)
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, status.HTTP_200_OK)

        # Default Time zone
        session = self.client.session
        self.assertTrue('django_timezone' in session)
        self.assertEqual(session["django_timezone"], timezone.get_default_timezone_name())

        self.client.logout()

        u4 = user_model.objects.create_user(username='user4', email='user4@foo.com', password='pass')
        u4.name = 'New York Dude'
        u4.time_zone = 'America/New_York'
        u4.is_active = True
        u4.save()

        ok = self.client.login(email='user4@foo.com', password='pass')
        self.assertTrue(ok)
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, status.HTTP_200_OK)

        # Default Time zone
        session = self.client.session
        self.assertTrue('django_timezone' in session)
        self.assertEqual(session["django_timezone"], timezone.get_current_timezone_name())
        self.assertEqual(timezone.get_current_timezone_name(), 'America/New_York')

        self.client.logout() 
Example #4
Source File: test_consumers.py    From chatter with MIT License 5 votes vote down vote up
def test_multitenant_chat_consumer():
    settings.CHANNEL_LAYERS = TEST_CHANNEL_LAYERS
    client, room, user = prepare_room_and_user()
    communicator = WebsocketCommunicator(
        multitenant_application, f"/ws/django_chatter/chatrooms/{room.id}/",
        headers=[
            (
                b'cookie',
                f'sessionid={client.cookies["sessionid"].value}'.encode('ascii')
            ),
            (b'host', b'localhost:8000')]
        )
    connected, subprotocol = await communicator.connect()
    assert connected
    data = {
        'message_type': 'text',
        'message': "Hello!",
        'sender': user.username,
        'room_id': str(room.id),
        }
    await communicator.send_json_to(data)
    response = await communicator.receive_json_from()
    response = response
    message = Message.objects.all()[0]
    time = message.date_created
    # zone = pytz.timezone(get_default_timezone_name())
    # time = time.astimezone(tz=zone)
    # formatted = dateformat.DateFormat(time)
    # time = formatted.format('M d, Y h:i a')

    assert response['message_type'] == 'text'
    assert response['message'] == 'Hello!'
    assert response['sender'] == 'user0'
    assert response['room_id'] == str(room.id)
    assert response['date_created'] == time.strftime("%d %b %Y %H:%M:%S %Z")
    await communicator.disconnect() 
Example #5
Source File: test_timezone.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_get_default_timezone(self):
        self.assertEqual(timezone.get_default_timezone_name(), 'America/Chicago') 
Example #6
Source File: test_timezone.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_get_default_timezone(self):
        self.assertEqual(timezone.get_default_timezone_name(), 'America/Chicago')