Showing posts from March, 2019

Importance notes for using Django Rest Framework

1. Serializers
class Snippet(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    class Meta:
        ordering = ('created',)

- serializers.Serializer

class SnippetSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    title = serializers.CharField(required=False, allow_blank=True, max_length=100)
    code = serializers.CharField(style={'base_template': 'textarea.html'})
    linenos = serializers.BooleanField(required=False)
    language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python')
    style = serializers.ChoiceField(choices=STYLE_CHOICES, defau…

OAuth 2.0 Authorization Framework

1. OAuth 2.0OAuth 2.0 is a protocol that allows a user to grant limited access to their resources on one site, to another site, without having to expose their credentials.

To get access to the protected resources OAuth 2.0 uses Access Tokens. An Access Token is a string representing the granted permissions.

OAuth Roles In any OAuth 2.0 flow we can identify the following roles: Resource Owner: the entity that can grant access to a protected resource. Typically this is the end-user. Resource Server: the server hosting the protected resources. This is the API you want to access. Client: the app requesting access to a protected resource on behalf of the Resource Owner. Authorization Server: the server that authenticates the Resource Owner, and issues Access Tokens after getting proper authorization. In this case, Auth0. Protocol flow We will now have a more detailed look on how the protocol works. As we will see in a while, OAuth has many "flavors" (called authorization grant types) t…

Django overview v1

A. Overview

1. Models and databases  - Models
 - Making queries
 - Aggregation
 - Search
 - Managers
 - Performing raw SQL queries
 - Database transactions
 - Multiple databases
 - Database access optimization
 - Database instrumentation

2. Handling HTTP requests  - URL dispatcher
 - Writing views
 - View decorators
 - File Uploads
  + Basic file uploads( Manual )
  + Handling uploaded files with a model
 - Django shortcut functions
 - Generic views
 - Middleware
 - How to use sessions

3. Working with forms  - Django’s role in forms
 - Forms in Django
 - Building a form( Widgets, Field data, Bound and unbound form instances )
 - Working with form templates

4. Templates  - Language
 - Built-in template tags and filters
 - Custom template tags and filters

5. Class-based views 6. Migrations 7. Managing files  - Using files in models  - The File object  - File storage

8. Authentication and authorization  - App: django.contrib.auth
 - Package: django-rules  ( Like policy in laravel or voter…