Skip to content

Commit ee39ec0

Browse files
committed
docker
1 parent 3a27e09 commit ee39ec0

File tree

8 files changed

+109
-34
lines changed

8 files changed

+109
-34
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# syntax=docker/dockerfile:1
2+
FROM python:3
3+
ENV PYTHONDONTWRITEBYTECODE=1
4+
ENV PYTHONUNBUFFERED=1
5+
WORKDIR /code
6+
COPY requirements.txt /code/
7+
RUN pip install -r requirements.txt
8+
COPY . /code/

apps/feed/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def api_add_like(request):
5656
Like.objects.create(tweek_id=tweek.id, created_by=request.user)
5757

5858
if request.user != tweek.created_by:
59-
create_notification(request, tweek.created_by, 'like')
59+
create_notification(request.user, tweek.created_by, 'like')
6060

6161
return JsonResponse({'success': True})
6262

@@ -90,7 +90,7 @@ def api_add_dislike(request):
9090
Dislike.objects.create(tweek_id=tweek.id, created_by=request.user)
9191

9292
if request.user != tweek.created_by:
93-
create_notification(request, tweek.created_by, 'dislike')
93+
create_notification(request.user, tweek.created_by, 'dislike')
9494

9595
return JsonResponse({'success': True})
9696

apps/notification/api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from apps.notification.models import Notification
2+
from .serializers import NotificationSerializer
3+
from rest_framework import generics
4+
5+
6+
class NotificationsList(generics.ListAPIView):
7+
serializer_class = NotificationSerializer
8+
9+
def get_queryset(self):
10+
return Notification.objects.filter(to_user=self.kwargs.get("user_id"))
11+
12+
13+

apps/notification/serializers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from datetime import datetime
2+
from rest_framework import serializers
3+
from django.contrib.humanize.templatetags.humanize import naturaltime
4+
5+
from apps.notification.models import Notification
6+
7+
8+
class NotificationSerializer(serializers.ModelSerializer):
9+
class Meta:
10+
model = Notification
11+
fields = '__all__'

apps/notification/templates/notification/notifications.html

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,57 @@
99
<span class="opacity-100">Notificações</span>
1010
</a>
1111
</div>
12-
<div class="flex flex-col">
13-
{% for notification in notifications %}
14-
<div class="flex flex-row h-fit w-full p-4 pt-3 pl-3 border-solid border-b-2 hover:bg-gray-100 dark:hover:bg-gray-700 border-gray-100 dark:border-gray-700" >
15-
<div class="flex mr-2">
16-
{% if notification.created_by.twikkerprofile.avatar %}
17-
<img class="rounded-full h-12 w-12" src="{{ notification.created_by.twikkerprofile.avatar.url }}">
18-
{% endif %}
19-
</div>
20-
<div>
21-
{% if notification.notification_type == 'message' %}
22-
<a href="{% url 'notifications' %}?goto=conversation&notification={{ notification.id }}">
23-
<strong>{{ notification.created_by.username }}</strong> sent you a message
24-
<small>{{ notification.created_at|naturaltime }}</small>
25-
</a>
26-
{% elif notification.notification_type == 'follower' %}
27-
<a href="{% url 'notifications' %}?goto=twikkerprofile&notification={{ notification.id }}">
28-
<strong>{{ notification.created_by.username }}</strong> started following you
29-
<small>{{ notification.created_at|naturaltime }}</small>
30-
</a>
31-
{% elif notification.notification_type == 'like' %}
32-
<a href="{% url 'notifications' %}?goto=twikkerprofile&notification={{ notification.id }}">
33-
<strong>{{ notification.created_by.username }}</strong> liked a tweek you made
34-
<small>{{ notification.created_at|naturaltime }}</small>
35-
</a>
36-
{% elif notification.notification_type == 'mention' %}
37-
<a href="{% url 'notifications' %}?goto=twikkerprofile&notification={{ notification.id }}">
38-
<strong>{{ notification.created_by.username }}</strong> mentioned you in a tweek
39-
<small>{{ notification.created_at|naturaltime }}</small>
40-
</a>
41-
{% endif %}
42-
</div>
12+
<div id="notificationapp" class="flex flex-col">
13+
<div v-for="notification in notifications" class="flex flex-row h-fit w-full p-4 pt-3 pl-3 border-solid border-b-2 hover:bg-gray-100 dark:hover:bg-gray-700 border-gray-100 dark:border-gray-700" >
14+
<div>
15+
<a v-if="notification.notification_type == 'message'" >
16+
<strong>[[ notification.created_by ]]</strong> sent you a message
17+
<small>[[ notification.created_at ]]</small>
18+
</a>
19+
<a v-if="notification.notification_type == 'follower'" >
20+
<strong>[[ notification.created_by ]]</strong> started following you
21+
<small>[[ notification.created_at ]]</small>
22+
</a>
23+
<a v-if="notification.notification_type == 'like'" >
24+
<strong>[[ notification.created_by ]]</strong> liked a tweek you made
25+
<small>[[ notification.created_at ]]</small>
26+
</a>
27+
<a v-if="notification.notification_type == 'dislike'">
28+
<strong>[[ notification.created_by ]]</strong> liked a tweek you made
29+
<small>[[ notification.created_at ]]</small>
30+
</a>
31+
<a v-if="notification.notification_type == 'mention'">
32+
<strong>[[ notification.created_by ]]</strong> mentioned you in a tweek
33+
<small>[[ notification.created_at ]]</small>
34+
</a>
4335
</div>
44-
{% endfor %}
36+
</div>
4537
</div>
4638
</div>
39+
{% endblock %}
40+
41+
{% block script %}
42+
<script>
43+
const {createApp} = Vue
44+
const notificationapp = createApp({
45+
delimiters: ['[[', ']]'],
46+
data () {
47+
return {
48+
notifications: [],
49+
}
50+
},
51+
mounted() {
52+
this.getNotifications();
53+
},
54+
methods: {
55+
getNotifications(){
56+
fetch('/api/notifications/' + {{ request.user.id }})
57+
.then(response => response.json())
58+
.then(data => {
59+
this.notifications = data
60+
})
61+
},
62+
}
63+
}).mount("#notificationapp")
64+
</script>
4765
{% endblock %}

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
# db:
3+
# image: postgres
4+
# volumes:
5+
# - ./data/db:/var/lib/postgresql/data
6+
# environment:
7+
# - POSTGRES_DB=postgres
8+
# - POSTGRES_USER=postgres
9+
# - POSTGRES_PASSWORD=postgres
10+
web:
11+
build: .
12+
command: python manage.py runserver 0.0.0.0:8000
13+
volumes:
14+
- .:/code
15+
ports:
16+
- "8000:8000"
17+
environment:
18+
- POSTGRES_NAME=postgres
19+
- POSTGRES_USER=postgres
20+
- POSTGRES_PASSWORD=postgres
21+
# depends_on:
22+
# - db

requirements.txt

-606 Bytes
Binary file not shown.

twikker/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
follow_tweeker, toggle_dark_mode
3030
from apps.conversation.api import api_add_message, api_get_global_messages, api_get_dm_messages
3131

32+
from apps.notification.api import NotificationsList
33+
3234
urlpatterns = [
3335
#
3436
#
@@ -74,6 +76,7 @@
7476
path('api/messages/global/', api_get_global_messages, name='api_get_global_messages'),
7577
path('api/messages/<int:conversation_id>/', api_get_dm_messages, name='api_get_dm_messages'),
7678
path('api/tweek/<int:tweek_id>/', api_get_tweek, name='api_get_tweek'),
79+
path('api/notifications/<int:user_id>', NotificationsList.as_view(), name='api_get_notifications'),
7780

7881

7982
path('settings/darkmode/', toggle_dark_mode, name='darkmode'),

0 commit comments

Comments
 (0)