Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Shushunya committed Nov 7, 2023
1 parent 562924a commit 85c0a34
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
4 changes: 3 additions & 1 deletion profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ class SavedCompany(models.Model):

class ViewedCompany(models.Model):
date = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(CustomUser, on_delete=models.CASCADE, blank=True, null=True)
user = models.ForeignKey(
CustomUser, on_delete=models.CASCADE, blank=True, null=True
)
company = models.ForeignKey(Profile, on_delete=models.CASCADE)

@property
Expand Down
4 changes: 2 additions & 2 deletions profiles/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def has_object_permission(self, request, view, obj):
return True

return obj.person == request.user


class RequestIsCreate(BasePermission):
def has_permission(self, request, view):
return request.method == 'POST'
return request.method == "POST"


class IsOwner(BasePermission):
Expand Down
12 changes: 10 additions & 2 deletions profiles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,17 @@ class Meta:
class ViewedCompanySerializer(serializers.ModelSerializer):
user_profile_name = serializers.SerializerMethodField()
company_name = serializers.SerializerMethodField()

class Meta:
model = ViewedCompany
fields = ("id", "user", "company", "date", "user_profile_name", "company_name",)
fields = (
"id",
"user",
"company",
"date",
"user_profile_name",
"company_name",
)

def get_user_profile_name(self, obj):
if obj.user:
Expand All @@ -251,7 +259,7 @@ def get_user_profile_name(self, obj):

def get_company_name(self, obj):
return obj.company_name

def create(self, validated_data):
user = validated_data.get("user")
profile = Profile.objects.get(id=validated_data.get("company"))
Expand Down
4 changes: 3 additions & 1 deletion profiles/tests/test_viewed_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def test_create_viewed_company_authorized(self):
)
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
self.assertEqual(self.user.id, response.data["user"])
self.assertEqual(self.user_profile.name, response.data["user_profile_name"])
self.assertEqual(
self.user_profile.name, response.data["user_profile_name"]
)
self.assertEqual(profile.id, response.data["company"])
self.assertEqual(profile.name, response.data["company_name"])

Expand Down
4 changes: 3 additions & 1 deletion profiles/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
name="saved_companies_destroy",
),
path(
"viewed-list/", ViewedCompanyCreate.as_view(), name="viewed_company_create"
"viewed-list/",
ViewedCompanyCreate.as_view(),
name="viewed_company_create",
),
path("regions/", RegionListView.as_view(), name="region-list"),
path("categories/", CategoryList.as_view(), name="category_list"),
Expand Down
26 changes: 14 additions & 12 deletions profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
Activity,
Region,
)
from .permissions import UserIsProfileOwnerOrReadOnly, ReadOnly, IsOwnCompany, IsOwner, RequestIsCreate
from .permissions import (
UserIsProfileOwnerOrReadOnly,
ReadOnly,
IsOwnCompany,
IsOwner,
RequestIsCreate,
)
from .serializers import (
SavedCompanySerializer,
ProfileListSerializer,
Expand Down Expand Up @@ -187,19 +193,15 @@ def perform_destroy(self, instance):
class ViewedCompanyCreate(CreateAPIView):
serializer_class = ViewedCompanySerializer
queryset = ViewedCompany.objects.all()
permission_classes = [(RequestIsCreate & (~IsOwner | ~IsAuthenticated)), ]

# @cached_property
# def _get_profile(self):
# self._track_contacts_request()
# return self.get_object()

permission_classes = [
(RequestIsCreate & (~IsOwner | ~IsAuthenticated)),
]

def perform_create(self, serializer):
serializer.save(
user=self.request.user,
company=self.request.data.get("company")
)

user=self.request.user, company=self.request.data.get("company")
)


class CategoryList(ListCreateAPIView):
serializer_class = CategorySerializer
Expand Down

0 comments on commit 85c0a34

Please sign in to comment.