Skip to content

Commit

Permalink
added missing modal views/urls, adapted html to include the tokenizer…
Browse files Browse the repository at this point in the history
…, bumped version and updated README
  • Loading branch information
Philipp Wassibauer committed Jun 13, 2011
1 parent a886abc commit f645c3a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
14 changes: 14 additions & 0 deletions README.rst
Expand Up @@ -19,6 +19,20 @@ Features
* Installable using pip and easy_install
* Modular message sending using facebox


User Search
============
The app comes with a very basic user search component. If you want to extend it or adapt it to your needs
look at views.recipient_search. Adapt your own version in a seperate app and then
change the call in your compose templates:

$("#id_recipient").tokenInput("{% url recipient_search %}?format=json", parameters)

to point to your custom view.




Dependencies
============
* Haystack
Expand Down
2 changes: 1 addition & 1 deletion threaded_messages/__init__.py
@@ -1,2 +1,2 @@
VERSION = (0, 0, 4)
VERSION = (0, 0, 5)
__version__ = '.'.join(map(str, VERSION))
21 changes: 11 additions & 10 deletions threaded_messages/templates/django_messages/modal_compose.html
Expand Up @@ -22,23 +22,24 @@
<!-- remove if you have these dependencies are already satisfied in your app -->
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.form.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.tokeninput.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var recipient = $("#id_recipient").val();
$("#id_recipient").val("")

var parameters = {
classes: {
tokenList: "token-input-list-gidsy",
token: "token-input-token-gidsy",
tokenDelete: "token-input-delete-token-gidsy",
selectedToken: "token-input-selected-token-gidsy",
highlightedToken: "token-input-highlighted-token-gidsy",
dropdown: "token-input-dropdown-gidsy",
dropdownItem: "token-input-dropdown-item-gidsy",
dropdownItem2: "token-input-dropdown-item2-gidsy",
selectedDropdownItem: "token-input-selected-dropdown-item-gidsy",
inputToken: "token-input-input-token-gidsy"
tokenList: "token-input-list",
token: "token-input-token",
tokenDelete: "token-input-delete-token",
selectedToken: "token-input-selected-token",
highlightedToken: "token-input-highlighted-token",
dropdown: "token-input-dropdown",
dropdownItem: "token-input-dropdown-item",
dropdownItem2: "token-input-dropdown-item2",
selectedDropdownItem: "token-input-selected-dropdown-item",
inputToken: "token-input-input-token"
},

hintText: "{% trans "Type in a search term" %}",
Expand Down
14 changes: 14 additions & 0 deletions threaded_messages/urls.py
Expand Up @@ -15,4 +15,18 @@
url(r'^undelete/(?P<thread_id>[\d]+)/$', undelete, name='messages_undelete'),
url(r'^batch-update/$', batch_update, name='messages_batch_update'),
url(r'^trash/$', trash, name='messages_trash'),

url(r"^recipient-search/$", recipient_search, name="recipient_search"),
url(r'^message-reply/(?P<thread_id>[\d]+)/$', message_ajax_reply, name="message_reply"),

# modal composing
url(r'^compose/(?P<recipient>[\+\w]+)/$', compose, {
"template_name":"django_messages/modal_compose.html",
"form_class": ComposeForm
}, name='modal_messages_compose_to'),

url(r'^compose/$', compose, {
"template_name":"django_messages/modal_compose.html",
"form_class": ComposeForm
}, name='modal_messages_compose'),
)
36 changes: 36 additions & 0 deletions threaded_messages/views.py
Expand Up @@ -251,3 +251,39 @@ def batch_update(request, success_url=None):
return HttpResponseRedirect(referer)
else:
return HttpResponseRedirect(reverse("messages_inbox"))



@login_required
def message_ajax_reply(request, thread_id,
template_name="django_messages/message_list_view.html"):
thread = get_object_or_404(Thread, id=thread_id)
if request.POST:
form = ReplyForm(request.POST)
if form.is_valid():
(thread, new_message) = form.save(sender=request.user, thread=thread)
return render_to_response(template_name,{
"message": new_message,
}, context_instance=RequestContext(request))
else:
return HttpResponse(status=400, content="Invalid Form")


@login_required
def recipient_search(request):
term = request.GET.get("term")
users = User.objects.filter(Q(first_name__icontains=term)|
Q(last_name__icontains=term)|
Q(username__icontains=term)|
Q(email__icontains=term))
if request.GET.get("format") == "json":
data = []
for user in users:
avatar_img_url = avatar_url(user, size=50)
data.append({"id": user.username,
"url": reverse("profile_detail",args=(user.username,)),
"name": "%s %s"%(user.first_name, user.last_name),
"img": avatar_img_url})

return HttpResponse(simplejson.dumps(data),
mimetype='application/json')

0 comments on commit f645c3a

Please sign in to comment.