This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
class Grid(object): | |
'''Parses a csv file into a grid. Each cell in the grid is a list of strings, corresponding to | |
the string that was in the corresponding cell in the spreadsheet split by the given | |
'cell_item_separator', which defaults to a comma''' | |
def __init__(self, csv_text, width=0, height=0, cell_item_separator=','): | |
lines = list(csv.reader(csv_text.splitlines())) | |
self.height = height if height > 0 else len(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
class Grid(object): | |
'''Parses a csv file into a grid. Each cell in the grid is a list of strings, corresponding to | |
the string that was in the corresponding cell in the spreadsheet split by the given | |
'cell_item_separator', which defaults to a comma''' | |
def __init__(self, csv_text, width=0, height=0, cell_item_separator=','): | |
lines = list(csv.reader(csv_text.splitlines())) | |
self.height = height if height > 0 else len(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSTALLED_APPS = [ | |
'rest_framework', # add DRF | |
'rest_framework.authtoken', #add token authentication | |
'users.apps.UsersConfig', | |
'users.apps.UsersConfig', | |
'notes.apps.NotesConfig', | |
'meteos.apps.MeteosConfig', | |
'passports.apps.PassportsConfig', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REST_FRAMEWORK = { | |
'DEFAULT_AUTHENTICATION_CLASSES': ( | |
'rest_framework.authentication.TokenAuthentication', | |
), | |
'DEFAULT_PERMISSION_CLASSES': ( | |
'rest_framework.permissions.IsAuthenticated', | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth import authenticate | |
from rest_framework.authtoken.models import Token | |
from rest_framework.decorators import api_view, permission_classes | |
from rest_framework.permissions import AllowAny | |
from rest_framework.status import ( | |
HTTP_400_BAD_REQUEST, | |
HTTP_404_NOT_FOUND, | |
HTTP_200_OK, | |
) | |
from rest_framework.response import Response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
class UserSigninSerializer(serializers.Serializer): | |
username = serializers.CharField(required = True) | |
password = serializers.CharField(required = True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from django.urls import path | |
from users.views import signin | |
urlpatterns = [ | |
path('admin/', admin.site.urls), | |
path('api/v1/signin', signin) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.authtoken.models import Token | |
from datetime import timedelta | |
from django.utils import timezone | |
from django.conf import settings | |
#this return left time | |
def expires_in(token): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.authentication import TokenAuthentication | |
from rest_framework.authtoken.models import Token | |
from rest_framework.exceptions import AuthenticationFailed | |
from datetime import timedelta | |
from django.utils import timezone | |
from django.conf import settings | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REST_FRAMEWORK = { | |
'DEFAULT_AUTHENTICATION_CLASSES': ( | |
'users.authentication.ExpiringTokenAuthentication', # custom authentication class | |
), | |
'DEFAULT_PERMISSION_CLASSES': ( | |
'rest_framework.permissions.IsAuthenticated', | |
) | |
} |
OlderNewer