-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from bounswe/lab-5
Lab 5 Pull Request
- Loading branch information
Showing
16 changed files
with
720 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.16 on 2024-11-05 12:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app', '0008_translation_remove_word_categories_delete_category_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='word', | ||
name='sentence', | ||
field=models.CharField(default='Sentence not available', max_length=1000), | ||
), | ||
] |
38 changes: 38 additions & 0 deletions
38
backend/app/views_directory/create_post-activity-streams.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from rest_framework import status | ||
from rest_framework.decorators import api_view | ||
from rest_framework.response import Response | ||
from ..models import Post, Tags | ||
from ..serializers import PostSerializer | ||
|
||
@api_view(['POST']) | ||
def create_post(request): | ||
post_data = request.data | ||
|
||
serializer = PostSerializer(data=post_data) | ||
if serializer.is_valid(): | ||
post = serializer.save() | ||
|
||
if 'tags' in post_data: | ||
tags = post_data['tags'] | ||
post.tags.add(*[Tags.objects.get_or_create(name=tag)[0] for tag in tags]) | ||
|
||
activity_stream = { | ||
"@context": "https://www.w3.org/ns/activitystreams", | ||
"type": "Create", | ||
"actor": { | ||
"type": "Person", | ||
"name": post.author.username, | ||
}, | ||
"object": { | ||
"type": "Note", | ||
"id": post.id, | ||
"name": post.title, | ||
"content": post.description, | ||
"tags": [{"type": "Hashtag", "name": tag} for tag in post.tags.values_list('name', flat=True)] | ||
}, | ||
"published": post.created_at.isoformat() | ||
} | ||
|
||
return Response({'activity_stream': activity_stream}, status=status.HTTP_201_CREATED) | ||
|
||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
78 changes: 78 additions & 0 deletions
78
backend/app/views_directory/like-unlike-views-with-activity-streams.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from django.shortcuts import get_object_or_404 | ||
from rest_framework.decorators import api_view, permission_classes | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from app.models import Post | ||
import json | ||
from datetime import datetime | ||
|
||
def log_activity(actor, verb, obj_type, obj_id, obj_content): | ||
activity = { | ||
"@context": "localhost", | ||
"type": "Post Like/Unlike", | ||
"actor": { | ||
"type": "Person", | ||
"id": actor.id, | ||
"name": actor.username | ||
}, | ||
"verb": verb, | ||
"object": { | ||
"type": obj_type, | ||
"id": obj_id, | ||
"content": obj_content | ||
}, | ||
"published": datetime.utcnow().isoformat() + 'Z' | ||
} | ||
print(json.dumps(activity)) | ||
|
||
@api_view(['POST']) | ||
@permission_classes([IsAuthenticated]) | ||
def like_post(request): | ||
post_id = request.data.get("post_id") | ||
if not post_id: | ||
return Response({"detail": "Post ID is required."}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
post = get_object_or_404(Post, id=post_id) | ||
if request.user in post.liked_by.all(): | ||
return Response({"detail": "You have already liked this post."}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
post.liked_by.add(request.user) | ||
post.like_count = post.liked_by.count() | ||
post.save() | ||
|
||
log_activity( | ||
actor=request.user, | ||
verb="like", | ||
obj_type="Post", | ||
obj_id=post.id, | ||
obj_content=post.content | ||
) | ||
|
||
return Response({"detail": "Post liked successfully.", "like_count": post.like_count}, status=status.HTTP_200_OK) | ||
|
||
@api_view(['POST']) | ||
@permission_classes([IsAuthenticated]) | ||
def unlike_post(request): | ||
post_id = request.data.get("post_id") | ||
if not post_id: | ||
return Response({"detail": "Post ID is required."}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
post = get_object_or_404(Post, id=post_id) | ||
if request.user not in post.liked_by.all(): | ||
return Response({"detail": "You have not liked this post yet."}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
post.liked_by.remove(request.user) | ||
post.like_count = post.liked_by.count() | ||
post.save() | ||
|
||
# Log the "unlike" activity | ||
log_activity( | ||
actor=request.user, | ||
verb="unlike", | ||
obj_type="Post", | ||
obj_id=post.id, | ||
obj_content=post.content | ||
) | ||
|
||
return Response({"detail": "Post unliked successfully.", "like_count": post.like_count}, status=status.HTTP_200_OK) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
word,related_word,relation_type | ||
a,synset-A-noun-6,synonym | ||
a,letter,broader | ||
abandon,synset-abandon-verb-1,synonym | ||
abandon,discard,broader | ||
abandon,chuck,narrower | ||
abandon,forfeit,narrower | ||
abandon,dispense,narrower | ||
abandon,consign,narrower | ||
abandon,synset-wildness-noun-1,synonym | ||
abandon,passion,broader | ||
abandon,synset-abandon-verb-2,synonym | ||
abandon,foreswear,narrower | ||
abandon,synset-abandon-noun-1,synonym | ||
abandon,unrestraint,broader | ||
abandon,synset-abandon-verb-10,synonym | ||
abandon,synset-abandon-verb-1,synonym | ||
abandon,leave,broader | ||
abandon,maroon,narrower | ||
abandon,expose,narrower | ||
abandon,ditch,narrower | ||
abandon,walk,narrower | ||
abandon,synset-vacate-verb-2,synonym | ||
abandon,leave,broader | ||
abandoned,synset-abandoned-adjectivesatellite-2,synonym | ||
abandoned,synset-abandoned-adjectivesatellite-1,synonym | ||
ability,c,broader | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,c,narrower | ||
ability,sh85082114,narrower | ||
ability,sh2005004875,narrower | ||
ability,sh85142795,narrower | ||
ability,sh85041103,narrower | ||
ability,sh2008004738,narrower | ||
ability,sh97008210,narrower | ||
ability,sh85082750,narrower | ||
ability,sh85075527,narrower | ||
ability,sh85076844,narrower | ||
ability,sh85075480,narrower | ||
ability,sh85009146,narrower | ||
ability,sh2008008130,narrower | ||
ability,sh89002679,narrower | ||
ability,sh2010000098,narrower | ||
ability,sh85126514,narrower | ||
ability,sh85046278,narrower | ||
ability,sh85033833,narrower | ||
ability,sh85088948,narrower | ||
ability,sh85087575,narrower | ||
ability,sh00002431,narrower | ||
ability,sh85067157,narrower | ||
ability,synset-ability-noun-3,synonym | ||
ability,cognition,broader | ||
ability,know-how,narrower | ||
ability,hand,narrower | ||
ability,skill,narrower | ||
ability,intelligence,narrower | ||
ability,creativity,narrower | ||
ability,aptitude,narrower | ||
ability,bilingualism,narrower | ||
ability,leadership,narrower | ||
ability,faculty,narrower | ||
ability,superior,narrower | ||
ability,capacity,narrower | ||
ability,skill,narrower | ||
ability,originality,narrower | ||
ability,synset-ability-noun-1,synonym | ||
ability,quality,broader | ||
ability,totipotency,narrower | ||
ability,Midas,narrower | ||
ability,immunocompetence,narrower | ||
ability,physical,narrower | ||
ability,penetration,narrower | ||
ability,magical,narrower | ||
ability,interoperability,narrower | ||
ability,form,narrower | ||
ability,adaptability,narrower | ||
ability,competence,narrower | ||
ability,sensitivity,narrower | ||
ability,capability,narrower | ||
ability,contractility,narrower | ||
able,synset-able-adjectivesatellite-5,synonym | ||
able,synset-able-adjectivesatellite-1,synonym | ||
able,synset-able-adjectivesatellite-3,synonym | ||
able,synset-able-adjective-1,synonym | ||
abnormal,synset-abnormal-adjective-2,synonym | ||
abnormal,synset-abnormal-adjectivesatellite-3,synonym | ||
abnormal,synset-abnormal-adjective-2,synonym | ||
abnormally,synset-abnormally-adverb-1,synonym | ||
aboard,synset-aboard-adverb-1,synonym | ||
aboard,synset-aboard-adverb-4,synonym | ||
aboard,synset-aboard-adverb-1,synonym | ||
aboard,synset-aboard-adverb-1,synonym | ||
abolish,synset-abolish-verb-3,synonym | ||
abolish,cashier,narrower | ||
abolish,abrogate,narrower |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
word,turkish_translation | ||
a,a | ||
a,bir | ||
abandon,terk etmek | ||
abandon,bırakmak | ||
abandon,kovmak | ||
abandoned,terk edilmiş | ||
abnormal,anormal |
Oops, something went wrong.