-
-
Notifications
You must be signed in to change notification settings - Fork 775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Notifications app #2967
[WIP] Notifications app #2967
Changes from 1 commit
20eea61
7ab6e9b
287b3c4
97b2a72
e2d315f
3e2f9a7
49594fd
a6a8f05
e28a42d
3e6aa8f
3080253
b4972d7
b6be53b
be85747
fd08458
7cbb857
d0b3330
710efeb
dfb235c
fad9fb9
6e958e1
cfd0469
195e6ac
cfe8504
a2c6716
c31bd59
73640f4
74b8bd3
2d50b12
f33c079
81b246b
5021197
0b3e682
f01d9b9
2475d7f
80d93cf
f6ef416
b67d6e9
abdbf37
403a278
e47ac1d
15064e8
476cb70
5d25b33
4def040
80acc0e
1dc59cc
a01df33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- v1.88.0
- v1.31.1
- v1.25.0
- v1.6.0
- v1.4
- stablebak20191002
- stablebackup20190923
- stable-22-02-21
- stable20200416_2
- stable20190904
- stable20190131
- release-20190128
- release20190923
- release_20190117
- pre_bundle
- masterback20210317
- masterback20190923
- master20200416
- master20190904
- master20190205
- master20190131
- master_bak_20190917
- ls
- compress_final
- 201905022stable-2
- 20211201_stable
- 20211201_master
- 20211130_stable
- 20211130_master
- 20211115_stable
- 20211115_master
- 20211101_stable
- 20211101_master
- 20211018_stable
- 20211018_master
- 20211004_stable
- 20211004_master_1
- 20211004_master
- 20210929_stable
- 20210929_master
- 20210927_stable
- 20210927_master
- 20210922_stable_1
- 20210922_stable
- 20210922_master_1
- 20210922_master
- 20210907_stable
- 20210907_master
- 20210719_stable
- 20210719_master
- 20210608_stable
- 20210608_master
- 20210317_stable
- 20210317_master
- 20210304_stable_2
- 20210304_stable
- 20210304_master_2
- 20210304_master
- 20210222
- 20210219stable
- 20210219master
- 20210217_stable
- 20210217_stable_bk
- 20210217_master
- 20210205_stable
- 20210205_master
- 20210203_stable
- 20210203_master
- 20210120_stable
- 20210120_master
- 20210111_stable
- 20210111_master
- 20210108_stable
- 20210108_master
- 20201222stable-beforechat
- 20201209_stable
- 20201209_master
- 20201201_stable
- 20201201_master_final
- 20201201_master_after_gr8_merge
- 20201118stable
- 20201118master
- 20201113master-rc1
- 20201113master-rc
- 20201112master
- 20201030_stable
- 20201030_master
- 20201028stable
- 20201028master
- 20201014stable
- 20201014master_2
- 20201014master_1
- 20201014master
- 20201007_stable_2
- 20201007_stable
- 20201007stable
- 20201007_master_2
- 20201007_master
- 20201007master
- 20200930master
- 20200924_stable
- 20200924_master
- 20200923master
- 20200914master
- 20200914-2stable
- 20200914-2master
- 20200909stable
- 20200909master
- 20200904stable
- 20200904master
- 20200826stable
- 20200826master
- 20200820master
- 20200813stable-2
- 20200813stable
- 20200813master-2
- 20200813master
- 20200812stable
- 20200812master
- 20200810stable
- 20200810master-2
- 20200810master
- 20200804master
- 20200728stable
- 20200728master_2
- 20200728master
- 20200710stable
- 20200710master
- 20200706stable
- 20200706master
- 20200703stable
- 20200703master
- 20200630stable
- 20200630master_2
- 20200630master
- 20200623stable
- 20200623master
- 20200608stable
- 20200608master
- 20200601_stable
- 20200601_master
- 20200529stable
- 20200529master
- 20200528stable-2
- 20200528stable
- 20200528master-2
- 20200528master
- 20200522stable
- 20200522master
- 20200521stable
- 20200521master
- 20200513stable
- 20200513master
- 20200506stable_2
- 20200506stable
- 20200506master_2
- 20200506master
- 20200505stable
- 20200505master
- 20200501stable
- 20200501master
- 20200430stable
- 20200430master
- 20200423stable
- 20200423master-4
- 20200423master-3
- 20200423master-2
- 20200423master
- 20200416stable
- 20200416master
- 20200414stable
- 20200414master
- 20200408stable-2
- 20200408stable
- 20200408master-2
- 20200408master
- 20200402master
- 20200401stable
- 20200401master
- 20200304stable
- 20200304master
- 20200220stable
- 20200220master
- 20200205stable
- 20200205master
- 20200128_stable
- 20200128_master
- 20200115stable
- 20200115master
- 20200109stable
- 20200109master-2
- 20200109master
- 20192808master
- 20192519master-2
- 20191218stable
- 20191218master
- 20191211stable
- 20191211master-2
- 20191211master
- 20191204stable
- 20191204master
- 20191120stable
- 20191120master
- 20191113stable
- 20191113master
- 20191106stable
- 20191106master-2
- 20191106master
- 20191024stable
- 20191024master
- 20191023stable
- 20191023master
- 20191016stable
- 20191016master
- 20191002stable
- 20191002master
- 20190925stable
- 20190925master
- 20190920stable-2
- 20190920stable
- 20190920master-2
- 20190920master
- 20190912stable
- 20190912master-3
- 20190912master-2
- 20190912master
- 20190904stable
- 20190904master-2
- 20190904master
- 20190829stable
- 20190821stable
- 20190821master
- 20190814
- 20190814stable
- 20190814master
- 20190808-stable
- 20190808-master
- 20190731stable
- 20190731master-2
- 20190731master
- 20190724stable
- 20190724master-2
- 20190724master
- 20190718stable
- 20190718master-2
- 20190718master
- 20190710stable
- 20190710master-2
- 20190710master
- 20190703stable
- 20190703master
- 20190627stable
- 20190627master
- 20190626stable
- 20190626master
- 20190620stable
- 20190620master
- 20190613stable
- 20190613master
- 20190612stable
- 20190612master
- 20190531stable
- 20190531master
- 20190530stable
- 20190530master
- 20190529stable
- 20190529master
- 20190522stable
- 20190522master-4
- 20190522master-3
- 20190522master-2
- 20190522master
- 20190515stable
- 20190515master
- 20190508stable
- 20190508master
- 20190502stable
- 20190502master-2
- 20190502master
- 20190424stable
- 20190424master
- 20190417stable
- 20190417master-4
- 20190417master-3
- 20190417master-2
- 20190417master
- 20190411stable-2
- 20190411stable
- 20190411master-2
- 20190411master
- 20190404stable-2
- 20190404stable
- 20190404master-2
- 20190404master
- 20190329stable
- 20190329master
- 20190329-rc
- 20190327-rc2
- 20190327-rc
- 20190321stable
- 20190321master-2
- 20190321master
- 20190314stable
- 20190314master
- 20190307stable-3
- 20190307stable
- 20190307master-3
- 20190307master-2
- 20190307master
- 20190305stable
- 20190305master
- 20190221stable
- 20190221master
- 20190211stable
- 20190211master
- 20190208
- 20190128
- 2020804stable
- 201907
- 160320stable-backup
- 160320stable
- 160320master
- 061519stable
- 031020stable
- 031020master
- 20201_05_13_stable
- 20201_05_13_master
- 20201_04_22_stable
- 20201_04_22_master
- 20201_04_22_master_final
- 20201_04_08_stable
- 20201_04_08_master
- 20201_03_09_stable
- 20201_03_09_master
- 20201_02_22_v2_stable
- 20201_02_22_stable_no_compress
- 2022_08_17_stable
- 2022_08_15_stable
- 2022_08_15_master
- 2022_06_16_stable
- 2022_06_15_stable
- 2022_06_14_stable
- 2022_06_06_stable
- 2022_06_06_mastetr
- 2022_06_06_master
- 2022_06_01_stable
- 2022_06_01_master
- 2022_05_23_stable
- 2022_05_21_stable
- 2022_05_21_master
- 2022_05_06_stable
- 2022_05_06_master
- 2022_05_04_stable
- 2022_05_04_master
- 2022_03_09_stable
- 2022_03_09_master
- 2022_03_08_stable
- 2022_03_08_master
- 2022_03_07_stable
- 2022_03_07_master
- 2022_03_01_stable
- 2022_03_01_master
- 2022_02_17_stable
- 2022_02_17_master
- 2022_01_11_stable
- 2022_01_11_master
- 2021_12_23_stable
- 2021_12_15_stable
- 2021_12_15_master
- 2021_11_29_stable
- 2021_11_29_master
- 2021_11_26_stable
- 2021_11_26_stable_final
- 2021_11_26_master_final
- 2021_11_24_stable
- 2021_11_24_master
- 2021_09_07_stable
- 2021_08_23_stable
- 2021_08_23_master
- 2021_08_16_stable
- 2021_08_16_master
- 2021_07_27_stable
- 2021_07_27_master
- 2021_07_15_stable
- 2021_07_12_stable
- 2021_07_12_master
- 2021_07_01_stable
- 2021_07_01_master
- 2021_06_15_stable
- 2021_06_15_master
- 2021_05_24_stable_before_ql
- 2021_05_24_master_before_ql
- 2021_04_08_master
- 2020_10_07_stable
- 2020_10_07_master
- 2020_04_08_master
- 1.57.1
- 1.33.1
- 1.9.0-rc
- 1.0
- 201903072019stable-2
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
var notifications = [] | ||
const isHidden = false | ||
const container = $('.notifications__list') | ||
|
||
function requestNotifications() { | ||
var getNotifications = fetchData ('/notification/','GET') | ||
|
||
$.when( getNotifications ).then(function(response) { | ||
|
||
// if (notifications.length) { | ||
// newNotifications = filterNewData(response); | ||
// } else { | ||
// } | ||
// newNotifications = response; | ||
// console.log(newNotifications) | ||
var flag = compareJson(response, notifications) | ||
if (flag === false) { | ||
console.log('updating') | ||
console.log(notifications, response) | ||
notifications = response; | ||
templateSuggestions(response) | ||
} | ||
// return response | ||
}) | ||
} | ||
|
||
function templateSuggestions(notifications) { | ||
var tmp = ` | ||
${notifications.map((notify, index) => ` | ||
<li class="notifications__item"> | ||
<span class="notifications__item-readed"> | ||
<b class="notification__dot-small"></b> | ||
</span> | ||
<div> | ||
${notify.message_html} | ||
</div> | ||
<time class="notifications__time" datetime="${notify.created_on}" title="${notify.created_on}"> | ||
${notify.created_on} | ||
</time> | ||
</li>` | ||
).join(' ')} | ||
`; | ||
|
||
container.html(tmp); | ||
} | ||
|
||
function checkHidden() { | ||
if (typeof document.hidden !== "undefined") { | ||
return isHidden = document.hidden | ||
} else { | ||
return isHidden = false | ||
} | ||
} | ||
|
||
function filterNewData(data) { | ||
|
||
return notifications.filter( | ||
function(item) { | ||
|
||
return data.indexOf(item) < 0; | ||
} | ||
); | ||
} | ||
|
||
function compareJson(obj1, obj2) { | ||
var flag = true | ||
if (Object.keys(obj1).length==Object.keys(obj2).length){ | ||
for(key in obj1) { | ||
if(obj1[key] == obj2[key]) { | ||
continue; | ||
} | ||
else { | ||
return flag=false; | ||
break; | ||
} | ||
} | ||
} | ||
else { | ||
return flag=false; | ||
} | ||
} | ||
|
||
requestNotifications() | ||
|
||
var intervalNotifications = window.setInterval(requestNotifications, 5000); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 2.1.2 on 2018-12-03 22:38 | ||
|
||
from django.db import migrations, models | ||
import economy.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Notification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('modified_on', models.DateTimeField(default=economy.models.get_time)), | ||
('created_on', models.DateTimeField(auto_now_add=True, null=True)), | ||
('to_user_id', models.IntegerField()), | ||
('from_user_id', models.IntegerField()), | ||
('CTA_URL', models.URLField(max_length=255, null=True)), | ||
('CTA_Text', models.CharField(max_length=255)), | ||
('message_html', models.CharField(help_text='Html message', max_length=255, null=True)), | ||
('is_read', models.BooleanField(default=False)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from economy.models import SuperModel | ||
|
||
# Create your models here. | ||
|
||
class Notification(models.Model): | ||
class Notification(SuperModel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E302 expected 2 blank lines, found 1 |
||
created_on = models.DateTimeField(auto_now_add=True, blank=True, null=True) | ||
to_user_id = models.IntegerField() | ||
from_user_id = models.IntegerField() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,59 @@ | ||
from django.shortcuts import render | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F401 'django.shortcuts.render' imported but unused |
||
from django.core.paginator import Paginator | ||
from inbox.models import Notification | ||
|
||
from django.http import Http404, JsonResponse | ||
|
||
# Create your views here. | ||
|
||
def inbox(request, notification): | ||
try: | ||
notification = Notification.get(notification=notification) | ||
return notification | ||
except Exception as e: | ||
print(e) | ||
raise Http404 | ||
return JsonResponse("Hello, world. You're at the polls index.") | ||
# def inbox(request): | ||
# profile = request.user.profile if request.user.is_authenticated and request.user.profile else None | ||
|
||
# try: | ||
# grant = Notification.objects.prefetch_related('subscriptions', 'milestones').get(pk=grant_id, slug=grant_slug) | ||
# notification = Notification.get(notification=notification) | ||
# return notification | ||
# except Exception as e: | ||
# print(e) | ||
# raise Http404 | ||
# return JsonResponse("Hello, world. You're at the polls index.") | ||
|
||
|
||
|
||
def inbox(request): | ||
"""Handle grants explorer.""" | ||
profile = request.user.profile if request.user.is_authenticated and request.user.profile else None | ||
limit = request.GET.get('limit', 25) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F841 local variable 'limit' is assigned to but never used |
||
page = request.GET.get('page', 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F841 local variable 'page' is assigned to but never used |
||
sort = request.GET.get('sort_option', '-created_on') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F841 local variable 'sort' is assigned to but never used |
||
|
||
_notifications = Notification.objects.filter(to_user_id=profile.id).order_by(sort) | ||
|
||
if request.method == 'POST': | ||
sort = request.POST.get('sort_option', '-created_on') | ||
_notifications = Notification.objects.order_by(sort) | ||
|
||
paginator = Paginator(_notifications, limit) | ||
notifications = paginator.get_page(page) | ||
|
||
params = [{ | ||
'is_read': 'false', | ||
'created_on': '2018-11-15T19:59:08.081864Z', | ||
'to_user_id': '7', | ||
'from_user_id': '1', | ||
'CTA_URL': 'http://localhost:8000/issue/owocki/pytrader/142/1555', | ||
'CTA_Text': 'You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…', | ||
'message_html': 'You haven’t responded to <b>#2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…</b>', | ||
}, | ||
{ | ||
'is_read': 'false', | ||
'created_on': '2018-11-15T19:59:08.081864Z', | ||
'to_user_id': '7', | ||
'from_user_id': '1', | ||
'CTA_URL': 'http://localhost:8000/issue/owocki/pytrader/142/1555', | ||
'CTA_Text': 'You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…', | ||
'message_html': 'You haven’t responded to <b>#2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…</b>', | ||
}, | ||
|
||
] | ||
return JsonResponse(params, status=200, safe=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F401 'django.db.models' imported but unused