This file contains hidden or 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
class UpdatePostAPIView(APIView): | |
permission_classes = (IsAuthenticated,) | |
parser_classes = (MultiPartParser, FormParser) | |
@staticmethod | |
def get(request: WSGIRequest, pk: int) -> Response: | |
try: | |
# Solves the problem of checking whether user owns post referenced. | |
post = Post.objects.filter(user=request.user).get(pk=pk) |
This file contains hidden or 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 status | |
from rest_framework.views import APIView | |
from rest_framework.response import Response | |
from rest_framework.permissions import IsAuthenticated | |
from rest_framework.parsers import MultiPartParser, FormParser | |
from post.serializers import ImageSerializer, PostCreateSerializer | |
class CreatePostAPIView(APIView): |
This file contains hidden or 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 typing import List | |
from datetime import datetime | |
from django.db import models | |
from django.core.exceptions import SuspiciousOperation | |
class Post(models.Model): | |
timestamp: datetime = models.DateTimeField(auto_now_add=True) |
This file contains hidden or 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 | |
from user.models import User | |
class UserSerializer(serializers.ModelSerializer): | |
first_name = serializers.CharField(required=False) | |
last_name = serializers.CharField(allow_blank=True, required=False) | |
password = serializers.CharField( |
This file contains hidden or 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.db import models | |
from django.contrib.auth.models import AbstractUser | |
from django.utils.translation import gettext_lazy as _ | |
class User(AbstractUser): | |
private = models.BooleanField(default=False) | |
email = models.EmailField(_('email address'), unique=True) | |
bio = models.CharField( |
This file contains hidden or 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
<TaskOptions> | |
<TaskOptions> | |
<option name="arguments" value="-S $FilePath$" /> | |
<option name="checkSyntaxErrors" value="true" /> | |
<option name="description" /> | |
<option name="exitCodeBehavior" value="ERROR" /> | |
<option name="fileExtension" value="py" /> | |
<option name="immediateSync" value="false" /> | |
<option name="name" value="Black" /> | |
<option name="output" value="$FilePath$" /> |
This file contains hidden or 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 typing import List, Any, Iterable | |
class Node(object): | |
def __init__(self, item): | |
self.itm = item | |
self.nxt = None | |
self.prv = None | |
def __repr__(self) -> str: |
This file contains hidden or 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
class Person { | |
std::string name; | |
std::string family; | |
public: | |
Person(std::string n, std::string f) : name(n), family(f) {}; | |
}; | |
void AssertSameFamily(const Person& p1, const Person& p2) |
This file contains hidden or 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
/* | |
Generated by ship.py on Sat May 23 15:05:18 2020. | |
*/ | |
#include "shipyard.hpp" | |
#include "test_primelib.cpp" | |
int main(int argc, char* argv[]) | |
{ | |
const auto tests = sy::create_tests({ | |
TESTFUNC(test_n_prime), |
This file contains hidden or 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
#include "shipyard.hpp" | |
#include "primelib.cpp" | |
void test_is_prime() | |
{ | |
sy::AssertTrue(is_prime(5), "is_prime(5) == true"); | |
sy::AssertFalse(is_prime(12), "is_prime(12) == false"); | |
} |