Skip to content

Instantly share code, notes, and snippets.

🤙
Forever coding

Mitch Tabian mitchtabian

🤙
Forever coding
Block or report user

Report or block mitchtabian

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AppComponent.kt
package com.codingwithmitch.openapi.di
import android.app.Application
import com.codingwithmitch.openapi.BaseApplication
import dagger.BindsInstance
import dagger.Component
import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector
import javax.inject.Singleton
View api_is_author_of_blogpost.py
@api_view(['GET',])
@permission_classes((IsAuthenticated,))
def api_is_author_of_blogpost(request, slug):
try:
blog_post = BlogPost.objects.get(slug=slug)
except BlogPost.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
data = {}
user = request.user
View ListAdapterTemplate.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
#parse("File Header.java")
View ListAdapterTemplate.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.View.OnClickListener
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
View header.html
<div class="search-bar mt-sm-2 mr-2">
<form onsubmit="return executeQuery();">
<input type="text" class="form-control" name="q" id="id_q" placeholder="Search...">
</form>
</div>
<script type="text/javascript">
document.getElementById("id_q").value = "{{query}}"
</script>
<script>
View registration_view.py
from rest_framework.decorators import api_view, authentication_classes, permission_classes
# Register
# Response: https://gist.github.com/mitchtabian/c13c41fa0f51b304d7638b7bac7cb694
# Url: https://<your-domain>/api/account/register
@api_view(['POST', ])
@permission_classes([])
@authentication_classes([])
def registration_view(request):
View BlogPostCreateSerializer.py
class BlogPostCreateSerializer(serializers.ModelSerializer):
class Meta:
model = BlogPost
fields = ['title', 'body', 'image', 'date_updated', 'author']
def save(self):
View BlogPostUpdateSerialzier.py
import cv2
import sys
import os
from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.storage import FileSystemStorage
IMAGE_SIZE_MAX_BYTES = 1024 * 1024 * 2 # 2MB
MIN_TITLE_LENGTH = 5
MIN_BODY_LENGTH = 50
View BlogPostSerializer.py
class BlogPostSerializer(serializers.ModelSerializer):
username = serializers.SerializerMethodField('get_username_from_author')
image = serializers.SerializerMethodField('validate_image_url')
class Meta:
model = BlogPost
fields = ['pk', 'title', 'slug', 'body', 'image', 'date_updated', 'username']
View ObtainApiTokenView.py
from rest_framework.views import APIView
from django.contrib.auth import authenticate
class ObtainAuthTokenView(APIView):
authentication_classes = []
permission_classes = []
def post(self, request):
context = {}
You can’t perform that action at this time.