-
Notifications
You must be signed in to change notification settings - Fork 19
Notifications - issue #165 #240
Changes from 3 commits
9ac8daf
c71b0c5
93755bf
c240e5c
48303ef
63e9e79
feb6dbc
04ecad0
b63ad70
dd130f9
dc52c17
70cbcd2
3713e99
dcba65b
f6bb9c8
41c32ca
0f66119
e5909e1
fecf0b6
2268613
98ca54a
8c34061
b1059a0
8d9b496
750cde1
c59df26
db6555a
d799a04
a7f203d
8b134bd
2bc2865
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ class AuthoredDocument(mongoengine.Document): | |
|
||
meta = { | ||
'abstract': True, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
import mongoengine | ||
|
||
from piplmesh.account import models as account_models | ||
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. Import with relative import as you can see bellow. |
||
|
||
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. No need, because they are all part of the same package. 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. No empty line here. Those two are same package (PiplMesh). 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. You can use relative import also for above. |
||
from . import base | ||
|
||
POST_MESSAGE_MAX_LENGTH = 500 | ||
|
@@ -33,6 +35,7 @@ class Post(base.AuthoredDocument): | |
comments = mongoengine.ListField(mongoengine.EmbeddedDocumentField(Comment), default=lambda: [], required=False) | ||
attachments = mongoengine.ListField(mongoengine.EmbeddedDocumentField(Attachment), default=lambda: [], required=False) | ||
|
||
subscribers = mongoengine.ListField(mongoengine.ReferenceField(account_models.User), default=lambda: [], required=False) | ||
# TODO: Prevent posting comments if post is not published | ||
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. Empty line between subscribers and TODOs. |
||
# TODO: Prevent adding attachments if post is published | ||
# TODO: Prevent marking post as unpublished once it was published | ||
|
@@ -65,4 +68,4 @@ class LinkAttachment(Attachment): | |
|
||
link_url = mongoengine.URLField(required=True) | ||
link_caption = mongoengine.StringField(default='', required=True) | ||
link_description = mongoengine.StringField(default='', required=True) | ||
link_description = mongoengine.StringField(default='', required=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,15 @@ def hydrate(self, bundle): | |
return bundle | ||
|
||
class CommentResource(AuthoredResource): | ||
def obj_create(self, bundle, request=None, **kwargs): | ||
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. Please read my comments here: https://github.com/wlanslovenija/PiplMesh/pull/199/files#r1366928 So the main point is that you should decouple API from frontend. So in the API you just deal with storing data (so storing to list of subscribers is OK). But to send something for frontend ( So please define and use Django signals. And move the code for frontend to frontend. 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. And same as for discussion above, be careful where you put those signals. So adding subscribers is a part of creating an object. But sending notifications should come later, when we are really sure everything was done properly and we are just about to return the response. |
||
obj = super(CommentResource, self).obj_create(bundle, request=request, **kwargs) | ||
|
||
print obj.obj.author | ||
#self.parent.fields['subscribers'].append(obj.obj.author) | ||
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.
|
||
|
||
#obj.obj.save() | ||
#print list((name, obj, " \n\n") for name, obj in self.parent.fields.iteritems()) | ||
return obj | ||
class Meta: | ||
object_class = api_models.Comment | ||
allowed_methods = ('get', 'post', 'put', 'patch', 'delete') | ||
|
@@ -63,9 +72,14 @@ class PostResource(AuthoredResource): | |
|
||
comments = fields.EmbeddedListField(of='piplmesh.api.resources.CommentResource', attribute='comments', default=lambda: [], null=True, full=False) | ||
attachments = fields.EmbeddedListField(of='piplmesh.api.resources.AttachmentResource', attribute='attachments', default=lambda: [], null=True, full=True) | ||
|
||
def obj_create(self, bundle, request=None, **kwargs): | ||
obj = super(PostResource, self).obj_create(bundle, request=request, **kwargs) | ||
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. OK, obj_create returns 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. Probably better place for all this would be in http://django-tastypie.readthedocs.org/en/latest/resources.html#hydrate 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. See how we are populating fields in |
||
obj.obj.subscribers.append(bundle.request.user) | ||
obj.obj.save() | ||
return obj | ||
class Meta: | ||
queryset = api_models.Post.objects.all() | ||
#print queryset | ||
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. This should probably be removed. :-) |
||
allowed_methods = ('get', 'post', 'put', 'patch', 'delete') | ||
# TODO: Make proper authorization, current implementation is for development use only | ||
authorization = tastypie_authorization.Authorization() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
$(document).ready(function() { | ||
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. Space before |
||
$(".notifications").click(function (){ | ||
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. Space after |
||
if ($("#notif_box").hasClass('show')) { | ||
$("#notif_box").slideUp('fast'); | ||
$("#notif_box").toggleClass('show'); | ||
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. They beautify of jQuery is that you can chain this together:
But I am not sure why you are setting and clearing this class? |
||
} else { | ||
$("#notif_box").slideDown('fast'); | ||
$("#notif_box").toggleClass('show'); | ||
} | ||
}); | ||
$(".close_notif_box").click(function (){ | ||
if ($("#notif_box").hasClass('show')) { | ||
$("#notif_box").slideUp('fast'); | ||
$("#notif_box").toggleClass('show'); | ||
} | ||
}); | ||
$("#addPost").click(function (){ | ||
addPost("Bla bla bla bla Post..."); | ||
}); | ||
$("#addCom").click(function (){ | ||
addComment("Bla bla bla bla"); | ||
}); | ||
}); | ||
|
||
function addPost(message) { | ||
$.ajax({ | ||
type: 'POST', | ||
url: '/api/v1/post/', | ||
data: JSON.stringify({'message': message, 'is_published': true}), | ||
contentType: 'application/json', | ||
dataType: "json", | ||
success: function () { | ||
alert("Post napisan."); | ||
}, | ||
error: function (error) { | ||
console.log(error); | ||
alert("Oops, something went wrong... "); | ||
} | ||
}); | ||
} | ||
|
||
function addComment(comment) { | ||
$.ajax({ | ||
type: 'POST', | ||
url: '/api/v1/post/4fd23f8cc91da109b8000001/comments/', | ||
data: JSON.stringify({'message': comment}), | ||
contentType: 'application/json', | ||
dataType: "json", | ||
success: function () { | ||
alert("Komentar napisan."); | ||
}, | ||
error: function (error) { | ||
console.log(error); | ||
alert("Oops, something went wrong... "); | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,21 @@ | |
If user is already logged in, logout link is shown instead. | ||
{% endcomment %} | ||
{% if user.is_authenticated %} | ||
<li> | ||
<div class="notifications"> | ||
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. Why only if authenticated? All users can get notifications, no? We are using lazy users now, remember. authenticated means that user is registered. But all users can post content. |
||
1 | ||
</div> | ||
<div id="notif_box" class="hide"> | ||
<div id="notif_content"> | ||
Bla bla bla.<br /> | ||
Bla bla bla.<br /> | ||
</div> | ||
<div class='close_notif_box'> | ||
<div id="addPost">Add p</div> | ||
<div id="addCom">Add c</div> Close | ||
</div> | ||
</div> | ||
</li> | ||
<li class="image"> | ||
{% user_image %} | ||
</li> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This file is placed here by pip to indicate the source was put | ||
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. WHAT IS THIS? |
||
here by pip. | ||
|
||
Once this package is successfully installed this source code will be | ||
deleted (unless you remove this file). |
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.
Int field? What will be stored here?