mirror of https://github.com/zulip/zulip.git
Add basic personals functionality.
(imported from commit a4fecbe40672f34295b1e908526b6c45056bcb7f)
This commit is contained in:
parent
2b9a3205be
commit
f6819d09d5
|
@ -9,6 +9,7 @@ urlpatterns = patterns('',
|
|||
url(r'^update$', 'zephyr.views.update', name='update'),
|
||||
url(r'^get_updates$', 'zephyr.views.get_updates', name='get_updates'),
|
||||
url(r'^zephyr/', 'zephyr.views.zephyr', name='zephyr'),
|
||||
url(r'^personal-zephyr/', 'zephyr.views.personal_zephyr', name='personal_zephyr'),
|
||||
url(r'^accounts/home/', 'zephyr.views.accounts_home', name='accounts_home'),
|
||||
url(r'^accounts/login/', 'django.contrib.auth.views.login', {'template_name': 'zephyr/login.html'}),
|
||||
url(r'^accounts/logout/', 'django.contrib.auth.views.logout', {'template_name': 'zephyr/index.html'}),
|
||||
|
|
|
@ -118,6 +118,11 @@ function narrow_instance(class_name, instance, target_zephyr) {
|
|||
scroll_to_zephyr(target_zephyr, old_top);
|
||||
}
|
||||
|
||||
function prepare_personal(username) {
|
||||
$("#recipient").val(username);
|
||||
$("#new_personal_zephyr").focus();
|
||||
}
|
||||
|
||||
function unhide() {
|
||||
$("tr").show();
|
||||
|
||||
|
@ -138,8 +143,8 @@ function get_updates() {
|
|||
var new_str = "<tr id=" + zephyr.id + "> \
|
||||
<td class='pointer'><p></p></td> \
|
||||
<td class='zephyr'> \
|
||||
<p><span onclick='narrow('" + zephyr.zephyr_class + "','" + zephyr.id + "')' class='zephyr_class' style='background-color: yellow;'>" + zephyr.zephyr_class +
|
||||
"</span> / <span onclick='narrow_instance('" + zephyr.zephyr_class + "','" + zephyr.instance + "','" + zephyr.id + "')' class='zephyr_instance' style='background-color: green;'>" + zephyr.instance + "</span> / " + zephyr.sender + "<br />" +
|
||||
<p><span onclick='narrow('" + zephyr.display_recipient + "','" + zephyr.id + "')' class='zephyr_class' style='background-color: yellow;'>" + zephyr.display_recipient +
|
||||
"</span> / <span onclick='narrow_instance('" + zephyr.display_recipient + "','" + zephyr.instance + "','" + zephyr.id + "')' class='zephyr_instance' style='background-color: green;'>" + zephyr.instance + "</span> / " + zephyr.sender + "<br />" +
|
||||
zephyr.content +
|
||||
"</p></td> \
|
||||
</tr>"
|
||||
|
@ -154,7 +159,14 @@ zephyr.content +
|
|||
Class: <input type="text" name="class" id="class" value="" />
|
||||
Instance: <input type="text" name="instance" id="instance" value="" /><br />
|
||||
Content: <textarea rows="4" cols="60" name="new_zephyr" id="new_zephyr" value="" /></textarea>
|
||||
<input type="submit" value="Zephyr" />
|
||||
<input type="submit" name="zephyr" value="Zephyr" />
|
||||
</form>
|
||||
|
||||
<form action="/personal-zephyr/" method="post">
|
||||
{% csrf_token %}
|
||||
User: <input type="text" name="recipient" id="recipient" value="" /><br />
|
||||
Content: <textarea rows="4" cols="60" name="new_personal_zephyr" id="new_personal_zephyr" value="" /></textarea>
|
||||
<input type="submit" name="personal_zephyr" value="Send Personal" />
|
||||
</form>
|
||||
|
||||
<span id="unhide" style="background-color: aqua;" onclick="unhide()">Unhide</span>
|
||||
|
@ -165,7 +177,9 @@ Content: <textarea rows="4" cols="60" name="new_zephyr" id="new_zephyr" value=""
|
|||
<tr id={{ zephyr.id }}>
|
||||
<td class="pointer">{% if user_profile.pointer == zephyr.id %}<p id="selected">>{% else %}<p>{% endif %}</p></td>
|
||||
<td class="zephyr">
|
||||
<p><span onclick="narrow('{{ zephyr.zephyr_class }}', '{{ zephyr.id }}')" class="zephyr_class" style="background-color: yellow;">{{ zephyr.zephyr_class }}</span> / <span onclick="narrow_instance('{{ zephyr.zephyr_class }}', '{{ zephyr.instance }}', '{{ zephyr.id }}')" class="zephyr_instance" style="background-color: green;">{{ zephyr.instance }}</span> / {{ zephyr.sender.user.username }}<br />
|
||||
<p><span onclick="narrow('{{ zephyr.display_recipient }}', '{{ zephyr.id }}')" class="zephyr_class" style="background-color: {% if zephyr.recipient.type == 'class' %}yellow{% else %}magenta{% endif %};">{{ zephyr.display_recipient }}</span> /
|
||||
<span onclick="narrow_instance('{{ zephyr.display_recipient }}', '{{ zephyr.instance }}', '{{ zephyr.id }}')" class="zephyr_instance" style="background-color: green;">{{ zephyr.instance }}</span> /
|
||||
<span onclick="prepare_personal('{{ zephyr.sender.user.username }}')" style="background-color: magenta;">{{ zephyr.sender.user.username }}</span><br />
|
||||
{{ zephyr.content }}
|
||||
</p></td>
|
||||
</tr>
|
||||
|
|
|
@ -41,9 +41,12 @@ def home(request):
|
|||
|
||||
zephyrs = Zephyr.objects.all()
|
||||
for zephyr in zephyrs:
|
||||
# This is gross, but we'll probably be denormalizing this soon anyway.
|
||||
zephyr_class = ZephyrClass.objects.get(pk=zephyr.recipient.user_or_class)
|
||||
zephyr.zephyr_class = zephyr_class.name
|
||||
if zephyr.recipient.type == "class":
|
||||
zephyr_class = ZephyrClass.objects.get(pk=zephyr.recipient.user_or_class)
|
||||
zephyr.display_recipient = zephyr_class.name
|
||||
else:
|
||||
user = User.objects.get(pk=zephyr.recipient.user_or_class)
|
||||
zephyr.display_recipient = user.username
|
||||
|
||||
user = request.user
|
||||
user_profile = UserProfile.objects.get(user=user)
|
||||
|
@ -72,10 +75,16 @@ def get_updates(request):
|
|||
new_zephyrs = Zephyr.objects.filter(id__gt=pointer)
|
||||
new_zephyr_list = []
|
||||
for zephyr in new_zephyrs:
|
||||
zephyr_class = ZephyrClass.objects.get(pk=zephyr.recipient.user_or_class)
|
||||
if zephyr.recipient.type == "class":
|
||||
zephyr_class = ZephyrClass.objects.get(pk=zephyr.recipient.user_or_class)
|
||||
display_recipient = zephyr_class.name
|
||||
else:
|
||||
user = User.objects.get(pk=zephyr.recipient.user_or_class)
|
||||
display_recipient = user.username
|
||||
|
||||
new_zephyr_list.append({"id": zephyr.id,
|
||||
"sender": zephyr.sender.user.username,
|
||||
"zephyr_class": zephyr_class.name,
|
||||
"display_recipient": display_recipient,
|
||||
"instance": zephyr.instance,
|
||||
"content": zephyr.content
|
||||
})
|
||||
|
@ -85,20 +94,26 @@ def get_updates(request):
|
|||
|
||||
@login_required
|
||||
def personal_zephyr(request):
|
||||
username = request.POST['username']
|
||||
username = request.POST['recipient']
|
||||
if User.objects.filter(username=username):
|
||||
user = User.objects.get(username=username)
|
||||
else:
|
||||
# Do something reasonable.
|
||||
pass
|
||||
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
||||
|
||||
recipient = Recipient()
|
||||
recipient.user_or_class = user.pk
|
||||
recipient.type = "personal"
|
||||
recipient.save()
|
||||
|
||||
new_zephyr = Zephyr()
|
||||
new_zephyr.sender = UserProfile.objects.get(user=request.user)
|
||||
new_zephyr.content = request.POST['new_zephyr']
|
||||
new_zephyr.zephyr_class = username
|
||||
new_zephyr.instance = request.POST['instance']
|
||||
new_zephyr.content = request.POST['new_personal_zephyr']
|
||||
new_zephyr.recipient = recipient
|
||||
new_zephyr.instance = u''
|
||||
new_zephyr.pub_date = datetime.datetime.utcnow()
|
||||
new_zephyr.save()
|
||||
|
||||
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
||||
|
||||
@login_required
|
||||
|
|
Loading…
Reference in New Issue