mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
Switch zephyrs to the notion of a "Recipient", which is either a class or user.
(imported from commit edc46267dab9cc972358b6020ca28b009e15d8c5)
This commit is contained in:
parent
75ae3a3ac5
commit
2b9a3205be
@ -46,7 +46,6 @@ USE_TZ = True
|
||||
|
||||
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
|
||||
TEMPLATE_DIRS = ( os.path.join(SITE_ROOT, '..', 'templates'),)
|
||||
print TEMPLATE_DIRS
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash.
|
||||
|
||||
@ -138,8 +138,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.name + "','" + zephyr.id + "')' class='zephyr_class' style='background-color: yellow;'>" + zephyr.zephyr_class.name +
|
||||
"</span> / <span onclick='narrow_instance('" + zephyr.zephyr_class.name + "','" + zephyr.instance + "','" + zephyr.id + "')' class='zephyr_instance' style='background-color: green;'>" + zephyr.instance + "</span> / " + zephyr.sender + "<br />" +
|
||||
<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 />" +
|
||||
zephyr.content +
|
||||
"</p></td> \
|
||||
</tr>"
|
||||
@ -165,7 +165,7 @@ 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.name }}', '{{ zephyr.id }}')" class="zephyr_class" style="background-color: yellow;">{{ zephyr.zephyr_class.name }}</span> / <span onclick="narrow_instance('{{ zephyr.zephyr_class.name }}', '{{ zephyr.instance }}', '{{ zephyr.id }}')" class="zephyr_instance" style="background-color: green;">{{ zephyr.instance }}</span> / {{ zephyr.sender.user.username }}<br />
|
||||
<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 />
|
||||
{{ zephyr.content }}
|
||||
</p></td>
|
||||
</tr>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from django.core.management.base import NoArgsCommand
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass
|
||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Recipient
|
||||
|
||||
import datetime
|
||||
import random
|
||||
@ -23,6 +23,11 @@ class Command(NoArgsCommand):
|
||||
new_class = ZephyrClass()
|
||||
new_class.name = name
|
||||
new_class.save()
|
||||
|
||||
recipient = Recipient()
|
||||
recipient.user_or_class = new_class.pk
|
||||
recipient.type = "class"
|
||||
recipient.save()
|
||||
|
||||
# Create some test zephyrs, including:
|
||||
# - multiple classes
|
||||
@ -30,7 +35,7 @@ class Command(NoArgsCommand):
|
||||
# - multiple zephyrs per instance
|
||||
# - both single and multi-line content
|
||||
users = [user.id for user in User.objects.all()]
|
||||
zephyr_classes = [klass.id for klass in ZephyrClass.objects.all()]
|
||||
recipients = [klass.id for klass in Recipient.objects.all()]
|
||||
texts = file("zephyr/management/commands/test_zephyrs.txt", "r").readlines()
|
||||
offset = 0
|
||||
while offset < len(texts):
|
||||
@ -39,8 +44,9 @@ class Command(NoArgsCommand):
|
||||
length = random.randint(1, 5)
|
||||
new_zephyr.content = "".join(texts[offset: offset + length])
|
||||
offset += length
|
||||
new_zephyr.zephyr_class = ZephyrClass.objects.get(id=random.choice(zephyr_classes))
|
||||
new_zephyr.instance = new_zephyr.zephyr_class.name + str(random.randint(1, 3))
|
||||
new_zephyr.recipient = Recipient.objects.get(id=random.choice(recipients))
|
||||
zephyr_class = ZephyrClass.objects.get(pk=new_zephyr.recipient.pk)
|
||||
new_zephyr.instance = zephyr_class.name + str(random.randint(1, 3))
|
||||
new_zephyr.pub_date = datetime.datetime.utcnow()
|
||||
new_zephyr.save()
|
||||
|
||||
|
||||
@ -9,9 +9,13 @@ class UserProfile(models.Model):
|
||||
class ZephyrClass(models.Model):
|
||||
name = models.CharField(max_length=30)
|
||||
|
||||
class Recipient(models.Model):
|
||||
user_or_class = models.IntegerField()
|
||||
type = models.CharField(max_length=30)
|
||||
|
||||
class Zephyr(models.Model):
|
||||
sender = models.ForeignKey(UserProfile)
|
||||
zephyr_class = models.ForeignKey(ZephyrClass)
|
||||
recipient = models.ForeignKey(Recipient) # personal or class
|
||||
instance = models.CharField(max_length=30)
|
||||
content = models.CharField(max_length=200)
|
||||
pub_date = models.DateTimeField('date published')
|
||||
|
||||
@ -7,7 +7,7 @@ from django.template import RequestContext
|
||||
from django.shortcuts import render
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass
|
||||
from zephyr.models import Zephyr, UserProfile, ZephyrClass, Recipient
|
||||
from zephyr.forms import RegistrationForm
|
||||
|
||||
import datetime
|
||||
@ -40,9 +40,14 @@ def home(request):
|
||||
return HttpResponseRedirect('accounts/home/')
|
||||
|
||||
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
|
||||
|
||||
user = request.user
|
||||
user_profile = UserProfile.objects.get(user=user)
|
||||
if user_profile.pointer == -1:
|
||||
if user_profile.pointer == -1 and zephyrs:
|
||||
user_profile.pointer = min([zephyr.id for zephyr in zephyrs])
|
||||
user_profile.save()
|
||||
return render_to_response('zephyr/index.html', {'zephyrs': zephyrs, 'user_profile': user_profile},
|
||||
@ -67,9 +72,10 @@ 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)
|
||||
new_zephyr_list.append({"id": zephyr.id,
|
||||
"sender": zephyr.sender.user.username,
|
||||
"zephyr_class": zephyr.zephyr_class.name,
|
||||
"zephyr_class": zephyr_class.name,
|
||||
"instance": zephyr.instance,
|
||||
"content": zephyr.content
|
||||
})
|
||||
@ -77,6 +83,24 @@ def get_updates(request):
|
||||
return HttpResponse(simplejson.dumps(new_zephyr_list),
|
||||
mimetype='application/javascript')
|
||||
|
||||
@login_required
|
||||
def personal_zephyr(request):
|
||||
username = request.POST['username']
|
||||
if User.objects.filter(username=username):
|
||||
user = User.objects.get(username=username)
|
||||
else:
|
||||
# Do something reasonable.
|
||||
pass
|
||||
|
||||
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.pub_date = datetime.datetime.utcnow()
|
||||
new_zephyr.save()
|
||||
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
||||
|
||||
@login_required
|
||||
def zephyr(request):
|
||||
class_name = request.POST['class']
|
||||
@ -87,11 +111,17 @@ def zephyr(request):
|
||||
my_class.name = class_name
|
||||
my_class.save()
|
||||
|
||||
recipient = Recipient()
|
||||
recipient.user_or_class = my_class.pk
|
||||
recipient.type = "class"
|
||||
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 = my_class
|
||||
new_zephyr.recipient = recipient
|
||||
new_zephyr.instance = request.POST['instance']
|
||||
new_zephyr.pub_date = datetime.datetime.utcnow()
|
||||
new_zephyr.save()
|
||||
|
||||
return HttpResponseRedirect(reverse('zephyr.views.home'))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user