Re: Seeking design guidance on a Team model where a user sends invitation to other users to join the team

2017-11-27 Thread Jack
Hey Adam.  I took a week to properly learn some JavaScript and jQuery and 
how to make ajax calls.  I just got it working!  It was much simpler than I 
thought.  I created a views to catch the appropriate agent's pk and put 
that in a data-href attribute like this:

Send Invite

Then I passed the button into an ajax call... a few lines of processing in 
the `send_invitation` views and it works nicely.  Took maybe 15 lines of 
code in total?

Thanks for your help, but mainly thanks for leading me into using ajax.  I 
was always too lazy to properly learn javascript but now, I can do a lot 
more with jquery and ajax!

Best regards,

On Friday, November 10, 2017 at 12:37:46 PM UTC-5, Adam wrote:
>
>
>
>
>
>
>
> Weird, I dont see our conversation,
>
> Anyway here is a simple setup:
>
> urls.py:
>
> from django.conf.urls import url
>
> from .views import ajax_comment_send
>
> urlpatterns = [
>
>  url("comment_send", ajax_comment_send, name="comment_send"),
>
> ]
>
>
>
> then a view - this is from my project, you will to make changes to do the 
> calculations. :)
>
> ...
>
> def ajax_comment_send(request):
>  if not request.is_ajax():
>  return HttpResponse('SERVER RESPONSE: ajax_comment_send, Not an ajax 
> call.')
>
>  comment_thread = None
>  recipient = None
>
>  if request.method == "POST":
>  content = request.POST.get("content", "0")
>  recip_id_str = request.POST.get("recip_id", "0") # this is where to make 
> changes
>
>  if scope == 'story':
>  comment_thread = CommentThread.objects.get(story__id=int(recip_id_str))
>  recipient = get_object_or_404(User, pk=comment_thread.first_recipient_id)
>
> ...
>
>  send_message = Comment.objects.create(
>  body=content,
>  comment_thread=comment_thread,
>  recipient=recipient,
>  sender=request.user
>  )
>
>  send_message.save()
>
>  return HttpResponse("SERVER RESPONSE ajax_comment_send; send_message.id: 
> " +
>  str(send_message.id)) # this is a check to help with debugging
>
>  return HttpResponse('SERVER RESPONSE: ajax_comment_send, AJAX fell 
> through.')
>
>
>
>
> this is the key part ; javascript in the front end:
>
>
> function replyThread (scope, recip_id, cntnt) {
>  console.log('replyThread : scope:' + scope + ', recip_id: ' + recip_id + ', 
> content: ' + cntnt);
>  $.ajax({
>  type: 'POST',
>  url: '/jos_comments/comment_send',
>  data: { // this is the part that scoops up the agents and sends it to 
> the backend
>  'scope': scope, // This is unique to me
>  'recip_id': recip_id,
>  'content': cntnt
>  },
>  success: function (serverResponse_data) {
>  console.log('replyThread success: ' + serverResponse_data);
>  $('#message_box').html(
>  "Message sent!");
>  setTimeout(function () {
>  getThreadComments(serverResponse_data.split(':')[1]); // this reloads 
> the messages; you probably don't need
>  }, 1500);
>  },
>  error: function (serverResponse_data) {
>  console.log('error:' + JSON.stringify(serverResponse_data).split(',').
> join('\n')); // helps with debug
>  }
>  });
> }
>
> Hope this helps
>
>
>
>
>
>
>
>
>
>
> On Saturday, November 4, 2017 at 8:27:12 PM UTC-7, Jack wrote:
>>
>> I have a model called *Team*, which has a ForeignKey relationship with 
>> *User* (a team can have many users, but a user can only be part of one 
>> team).
>>
>> A user can create a team, and that user will automatically become a *Team 
>> Leader* (a group, not a model).  The team leader can query the database 
>> for other users and send invitations to other users join his team.  Users 
>> who receive an invitation can either accept or decline the invitation; if a 
>> user accepts an invitation, he joins the team as as a *Team Member*
>>
>> My question is, how do I go about designing the invitation system?  After 
>> the team leader clicks the 'Send Invitation' button, the receiving-user 
>> should see a special invitation message on his dashboard, which he can 
>> either accept or decline.
>>
>> My current thinking tells me I should create a model called *Invitation* 
>> which has a OneToOne relationship with User.  When an invitation is sent, 
>> an instance of Invitation is created which is assigned to the 
>> receiving-user.  The invitation instance will be deleted when the 
>> receiving-user accepts or declines the invitation.
>>
>> Another method I can think of is to send an Email to the receiving-user.  
>> The Email will be like an account activation Email, except the activation 
>> link adds the receiving-user to the team and marks the receiving-user as a 
>> *team 
>> member.*
>>
>> Pointers and guidance welcome.  I feel like both my methods are clumsy 
>> and maybe there is a built-in feature in Django which I missed which could 
>> solve this problem much easier.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@goog

Re: Seeking design guidance on a Team model where a user sends invitation to other users to join the team

2017-11-10 Thread Adam






Weird, I dont see our conversation,

Anyway here is a simple setup:

urls.py:

from django.conf.urls import url

from .views import ajax_comment_send

urlpatterns = [

 url("comment_send", ajax_comment_send, name="comment_send"),

]



then a view - this is from my project, you will to make changes to do the 
calculations. :)

...

def ajax_comment_send(request):
 if not request.is_ajax():
 return HttpResponse('SERVER RESPONSE: ajax_comment_send, Not an ajax call.'
)

 comment_thread = None
 recipient = None

 if request.method == "POST":
 content = request.POST.get("content", "0")
 recip_id_str = request.POST.get("recip_id", "0") # this is where to make 
changes

 if scope == 'story':
 comment_thread = CommentThread.objects.get(story__id=int(recip_id_str))
 recipient = get_object_or_404(User, pk=comment_thread.first_recipient_id)

...

 send_message = Comment.objects.create(
 body=content,
 comment_thread=comment_thread,
 recipient=recipient,
 sender=request.user
 )

 send_message.save()

 return HttpResponse("SERVER RESPONSE ajax_comment_send; send_message.id: " 
+
 str(send_message.id)) # this is a check to help with debugging

 return HttpResponse('SERVER RESPONSE: ajax_comment_send, AJAX fell 
through.')




this is the key part ; javascript in the front end:


function replyThread (scope, recip_id, cntnt) {
 console.log('replyThread : scope:' + scope + ', recip_id: ' + recip_id + ', 
content: ' + cntnt);
 $.ajax({
 type: 'POST',
 url: '/jos_comments/comment_send',
 data: { // this is the part that scoops up the agents and sends it to the 
backend
 'scope': scope, // This is unique to me
 'recip_id': recip_id,
 'content': cntnt
 },
 success: function (serverResponse_data) {
 console.log('replyThread success: ' + serverResponse_data);
 $('#message_box').html(
 "Message sent!");
 setTimeout(function () {
 getThreadComments(serverResponse_data.split(':')[1]); // this reloads the 
messages; you probably don't need
 }, 1500);
 },
 error: function (serverResponse_data) {
 console.log('error:' + JSON.stringify(serverResponse_data).split(',').join(
'\n')); // helps with debug
 }
 });
}

Hope this helps










On Saturday, November 4, 2017 at 8:27:12 PM UTC-7, Jack wrote:
>
> I have a model called *Team*, which has a ForeignKey relationship with 
> *User* (a team can have many users, but a user can only be part of one 
> team).
>
> A user can create a team, and that user will automatically become a *Team 
> Leader* (a group, not a model).  The team leader can query the database 
> for other users and send invitations to other users join his team.  Users 
> who receive an invitation can either accept or decline the invitation; if a 
> user accepts an invitation, he joins the team as as a *Team Member*
>
> My question is, how do I go about designing the invitation system?  After 
> the team leader clicks the 'Send Invitation' button, the receiving-user 
> should see a special invitation message on his dashboard, which he can 
> either accept or decline.
>
> My current thinking tells me I should create a model called *Invitation* 
> which has a OneToOne relationship with User.  When an invitation is sent, 
> an instance of Invitation is created which is assigned to the 
> receiving-user.  The invitation instance will be deleted when the 
> receiving-user accepts or declines the invitation.
>
> Another method I can think of is to send an Email to the receiving-user.  
> The Email will be like an account activation Email, except the activation 
> link adds the receiving-user to the team and marks the receiving-user as a 
> *team 
> member.*
>
> Pointers and guidance welcome.  I feel like both my methods are clumsy and 
> maybe there is a built-in feature in Django which I missed which could 
> solve this problem much easier.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a15cf74-98d1-40ca-8a8a-e73f09e5cb5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seeking design guidance on a Team model where a user sends invitation to other users to join the team

2017-11-05 Thread shreekant bohra
You don't need to download source code if you have installed via pip. You
can add it to INSTALLED_APPS list in settings.py and follow other
instructions given in their github page.

--
Shree Kant Bohra
Co-founder
Geekybuddha Technologies




On Sun, Nov 5, 2017 at 7:46 PM, Jack  wrote:

> Thanks, I'm looking into it and you are right, it seems quite fitting for
> my project.
>
> Stupid question as I've never used a 3rd party app before...  Am I
> supposed to download the source code and put that into my project folder?
> I already did 'pip install django-invitations'.
>
> On Saturday, November 4, 2017 at 11:49:19 PM UTC-4, Shree Kant Bohra wrote:
>>
>> Check out django-invitations app, which does exactly what you need -
>> https://github.com/bee-keeper/django-invitations
>>
>>
>> --
>> Shree Kant Bohra
>> Co-founder
>> Geekybuddha Technologies
>>
>>
>>
>>
>> On Sun, Nov 5, 2017 at 8:57 AM, Jack  wrote:
>>
>>> I have a model called *Team*, which has a ForeignKey relationship with
>>> *User* (a team can have many users, but a user can only be part of one
>>> team).
>>>
>>> A user can create a team, and that user will automatically become a *Team
>>> Leader* (a group, not a model).  The team leader can query the database
>>> for other users and send invitations to other users join his team.  Users
>>> who receive an invitation can either accept or decline the invitation; if a
>>> user accepts an invitation, he joins the team as as a *Team Member*
>>>
>>> My question is, how do I go about designing the invitation system?
>>> After the team leader clicks the 'Send Invitation' button, the
>>> receiving-user should see a special invitation message on his dashboard,
>>> which he can either accept or decline.
>>>
>>> My current thinking tells me I should create a model called *Invitation*
>>> which has a OneToOne relationship with User.  When an invitation is sent,
>>> an instance of Invitation is created which is assigned to the
>>> receiving-user.  The invitation instance will be deleted when the
>>> receiving-user accepts or declines the invitation.
>>>
>>> Another method I can think of is to send an Email to the
>>> receiving-user.  The Email will be like an account activation Email, except
>>> the activation link adds the receiving-user to the team and marks the
>>> receiving-user as a *team member.*
>>>
>>> Pointers and guidance welcome.  I feel like both my methods are clumsy
>>> and maybe there is a built-in feature in Django which I missed which could
>>> solve this problem much easier.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/029d4382-fdb2-4fc5-8832-337e1f870e24%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/6c96ca21-20e9-49b4-9f17-407abcc66ea8%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD5EYcoh%2BC7GCOesy%2B8dBdP9mFTs5qxov9LJuRmORXSOeUHEqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seeking design guidance on a Team model where a user sends invitation to other users to join the team

2017-11-05 Thread Jack
Thanks, I'm looking into it and you are right, it seems quite fitting for 
my project.

Stupid question as I've never used a 3rd party app before...  Am I supposed 
to download the source code and put that into my project folder?  I already 
did 'pip install django-invitations'. 

On Saturday, November 4, 2017 at 11:49:19 PM UTC-4, Shree Kant Bohra wrote:
>
> Check out django-invitations app, which does exactly what you need - 
> https://github.com/bee-keeper/django-invitations
>
>
> --
> Shree Kant Bohra
> Co-founder 
> Geekybuddha Technologies
>
>
>
>
> On Sun, Nov 5, 2017 at 8:57 AM, Jack > 
> wrote:
>
>> I have a model called *Team*, which has a ForeignKey relationship with 
>> *User* (a team can have many users, but a user can only be part of one 
>> team).
>>
>> A user can create a team, and that user will automatically become a *Team 
>> Leader* (a group, not a model).  The team leader can query the database 
>> for other users and send invitations to other users join his team.  Users 
>> who receive an invitation can either accept or decline the invitation; if a 
>> user accepts an invitation, he joins the team as as a *Team Member*
>>
>> My question is, how do I go about designing the invitation system?  After 
>> the team leader clicks the 'Send Invitation' button, the receiving-user 
>> should see a special invitation message on his dashboard, which he can 
>> either accept or decline.
>>
>> My current thinking tells me I should create a model called *Invitation* 
>> which has a OneToOne relationship with User.  When an invitation is sent, 
>> an instance of Invitation is created which is assigned to the 
>> receiving-user.  The invitation instance will be deleted when the 
>> receiving-user accepts or declines the invitation.
>>
>> Another method I can think of is to send an Email to the receiving-user.  
>> The Email will be like an account activation Email, except the activation 
>> link adds the receiving-user to the team and marks the receiving-user as a 
>> *team 
>> member.*
>>
>> Pointers and guidance welcome.  I feel like both my methods are clumsy 
>> and maybe there is a built-in feature in Django which I missed which could 
>> solve this problem much easier.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/029d4382-fdb2-4fc5-8832-337e1f870e24%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6c96ca21-20e9-49b4-9f17-407abcc66ea8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seeking design guidance on a Team model where a user sends invitation to other users to join the team

2017-11-04 Thread shreekant bohra
Check out django-invitations app, which does exactly what you need -
https://github.com/bee-keeper/django-invitations


--
Shree Kant Bohra
Co-founder
Geekybuddha Technologies




On Sun, Nov 5, 2017 at 8:57 AM, Jack  wrote:

> I have a model called *Team*, which has a ForeignKey relationship with
> *User* (a team can have many users, but a user can only be part of one
> team).
>
> A user can create a team, and that user will automatically become a *Team
> Leader* (a group, not a model).  The team leader can query the database
> for other users and send invitations to other users join his team.  Users
> who receive an invitation can either accept or decline the invitation; if a
> user accepts an invitation, he joins the team as as a *Team Member*
>
> My question is, how do I go about designing the invitation system?  After
> the team leader clicks the 'Send Invitation' button, the receiving-user
> should see a special invitation message on his dashboard, which he can
> either accept or decline.
>
> My current thinking tells me I should create a model called *Invitation*
> which has a OneToOne relationship with User.  When an invitation is sent,
> an instance of Invitation is created which is assigned to the
> receiving-user.  The invitation instance will be deleted when the
> receiving-user accepts or declines the invitation.
>
> Another method I can think of is to send an Email to the receiving-user.
> The Email will be like an account activation Email, except the activation
> link adds the receiving-user to the team and marks the receiving-user as a 
> *team
> member.*
>
> Pointers and guidance welcome.  I feel like both my methods are clumsy and
> maybe there is a built-in feature in Django which I missed which could
> solve this problem much easier.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/029d4382-fdb2-4fc5-8832-337e1f870e24%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD5EYcroQh%3DvOAozZkYJnZpmpTeT-chnk1O3r-7yrQ4XrPYWzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Seeking design guidance on a Team model where a user sends invitation to other users to join the team

2017-11-04 Thread Jack
I have a model called *Team*, which has a ForeignKey relationship with 
*User* (a team can have many users, but a user can only be part of one 
team).

A user can create a team, and that user will automatically become a *Team 
Leader* (a group, not a model).  The team leader can query the database for 
other users and send invitations to other users join his team.  Users who 
receive an invitation can either accept or decline the invitation; if a 
user accepts an invitation, he joins the team as as a *Team Member*

My question is, how do I go about designing the invitation system?  After 
the team leader clicks the 'Send Invitation' button, the receiving-user 
should see a special invitation message on his dashboard, which he can 
either accept or decline.

My current thinking tells me I should create a model called *Invitation* 
which has a OneToOne relationship with User.  When an invitation is sent, 
an instance of Invitation is created which is assigned to the 
receiving-user.  The invitation instance will be deleted when the 
receiving-user accepts or declines the invitation.

Another method I can think of is to send an Email to the receiving-user.  
The Email will be like an account activation Email, except the activation 
link adds the receiving-user to the team and marks the receiving-user as a 
*team 
member.*

Pointers and guidance welcome.  I feel like both my methods are clumsy and 
maybe there is a built-in feature in Django which I missed which could 
solve this problem much easier.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/029d4382-fdb2-4fc5-8832-337e1f870e24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.