Permalink
Browse files

template_name

  • Loading branch information...
1 parent d26ace8 commit 43aaa31134fd05f588dce5fcda7fa79919ffad1b Mike Krieger committed Dec 11, 2008
Showing with 40 additions and 18 deletions.
  1. +7 −3 greetings/models.py
  2. +8 −8 greetings/urls.py
  3. +25 −7 greetings/views.py
View
@@ -15,6 +15,8 @@ def __unicode__(self):
class Phone(models.Model):
number = models.TextField()
+ def __unicode__(self):
+ return self.number
class Person(models.Model):
emails = models.ManyToManyField(Email, null=True, blank=True)
@@ -24,9 +26,9 @@ def __unicode__(self):
if self.name:
return self.name
elif self.phones:
- return self.phones
+ return str(self.phones.all())
elif self.emails:
- return self.emails
+ return str(self.emails.all())
class EmailInline(admin.StackedInline):
model = Email
@@ -41,10 +43,12 @@ class Card (models.Model):
audio_file = models.FileField(upload_to='audio_uploads/', null=True, blank=True)
image_file = models.FileField(upload_to='image_uploads/', null=True, blank=True)
template = models.ForeignKey(Template, null=True, blank=True)
+ template_name = models.CharField(max_length=100, null=True, blank=True)
text_content = models.TextField()
short_hash = models.CharField(max_length=10, null=True, blank=True)
+ date_sent = models.DateTimeField(auto_now_add=True, null=True, blank=True)
def __unicode__(self):
- return "Card from %s to %s that says %s" % (self.from_person, self.to_people, self.text_content)
+ return "Card from %s sent at %s to %s that says %s" % (self.from_person, self.date_sent, str(self.to_people.all()), self.text_content)
View
@@ -5,12 +5,12 @@
urlpatterns = patterns('',
- url(r'card/(?P<hash>(\w+))/', 'greetingsweb.greetings.views.card_from_hash', name="get-greeting"),
- url(r'secret/greetingbyid/(?P<greeting_id>(\d+))/', 'greetingsweb.greetings.views.card_from_id', name="get-greeting"),
- url(r'attach/', 'greetingsweb.greetings.views.add_attachment', name="add-attachment"),
- url(r'open/(?P<hash>(\w+))/', 'greetingsweb.greetings.views.open_from_hash', name="open"),
- url(r'makegreeting/', 'greetingsweb.greetings.views.make_greeting', name='make-greeting'),
- url(r'newuser/', 'greetingsweb.greetings.views.new_user', name='new-user'),
- url(r'infofor/(?P<person_id>(\d+))/', "greetingsweb.greetings.views.more_info_for_person", name='person-info'),
- url(r'allcardsfor/(?P<person_id>(\d+))/(?P<since_id>(\d+))/', "greetingsweb.greetings.views.all_cards_for_id", name='cards-for'),
+ url(r'^card/(?P<hash>(\w+))/', 'greetingsweb.greetings.views.card_from_hash', name="get-greeting"),
+ url(r'^secret/greetingbyid/(?P<greeting_id>(\d+))/', 'greetingsweb.greetings.views.card_from_id', name="get-greeting"),
+ url(r'^attach/', 'greetingsweb.greetings.views.add_attachment', name="add-attachment"),
+ url(r'^open/(?P<hash>(\w+))/', 'greetingsweb.greetings.views.open_from_hash', name="open"),
+ url(r'^makegreeting/', 'greetingsweb.greetings.views.make_greeting', name='make-greeting'),
+ url(r'^newuser/', 'greetingsweb.greetings.views.new_user', name='new-user'),
+ url(r'^infofor/(?P<person_id>(\d+))/', "greetingsweb.greetings.views.more_info_for_person", name='person-info'),
+ url(r'^allcardsfor/(?P<person_id>(\d+))/(?P<since_id>(\d+))/', "greetingsweb.greetings.views.all_cards_for_id", name='cards-for'),
)
View
@@ -8,6 +8,7 @@
from django.forms import ModelForm
from django.db.models.query import Q
from django.utils import simplejson
+from django.contrib.humanize.templatetags.humanize import naturalday
from django.core.exceptions import ObjectDoesNotExist
from greetingsweb.greetings.models import *
import base64
@@ -77,7 +78,10 @@ def json_from_card(card):
json['from_id'] = greeting.from_person.id
json['to'] = [str(person) for person in greeting.to_people.all() ]
json['hash'] = greeting.short_hash
+ json['date'] = naturalday(greeting.date_sent, "M j")
json['text'] = greeting.text_content
+ if greeting.template_name:
+ json['template_name'] = greeting.template_name
if greeting.image_file:
json['image_url'] = greeting.image_file.url
json['template'] = greeting.template
@@ -140,6 +144,9 @@ def new_user(request):
email_list = request.REQUEST['email_list'].split(',')
phone_list = request.REQUEST['phone_list'].split(',')
user = find_person_from_lists(email_list=email_list, phone_list=phone_list)
+ if user:
+ user.name = request.REQUEST['name']
+ user.save()
if not user:
user = Person()
user.name = request.REQUEST['name']
@@ -184,16 +191,24 @@ def new_user(request):
def get_or_create_person_from_phone(phone):
try:
- phone_obj = Phone.objects.get(number=phone)
- user = find_person_from_lists(phone_list=(phones,))
+ try:
+ phone_obj = Phone.objects.get(number=phone)
+ except ObjectDoesNotExist, e:
+ phone_obj = Phone()
+ phone_obj.number = phone
+ phone_obj.save()
+ user = find_person_from_lists(phone_list=(phone,))
if user:
+ print "OMG I FOUND SOMEONE", user
return user
else:
+ print "dont know nobody with that phone"
user = Person()
user.save()
user.phones.add(phone_obj)
return user
except Exception, e:
+ print str(e)
return None
def random_lowercase_list(length=4):
@@ -219,6 +234,7 @@ def make_greeting(request):
new_card.save()
for phone in request.REQUEST["to_people_phones"].split(","):
other_person = get_or_create_person_from_phone(phone)
+ print "other person was found to be", other_person, " based on ", phone.strip()
if other_person:
new_card.to_people.add( get_or_create_person_from_phone(phone) )
if check_request_parameters(request, ("text",) ):
@@ -257,7 +273,9 @@ def check_or_make_dir(dirname):
def open_from_hash(request,hash):
- return HttpResponseRedirect("greet://%s" % hash)
+ card = get_object_or_404(Card, short_hash=hash)
+ # for now, just the first person
+ return HttpResponseRedirect("greet://%s/%s" % (hash, card.to_people.all()[0].id))
def add_attachment(request):
print "Attaching..."
@@ -276,21 +294,21 @@ def add_attachment(request):
short_name = "image_uploads/%s/" % (date_string)
dir_name = settings.MEDIA_ROOT + (short_name)
check_or_make_dir(dir_name)
- out_url = dir_name + "%s.caf"%card.short_hash
+ out_url = dir_name + "%s.jpg"%card.short_hash
elif request.REQUEST['type'] == 'sound':
sound = True
short_name = "audio_uploads/%s/" % (date_string)
dir_name = settings.MEDIA_ROOT + (short_name)
check_or_make_dir(dir_name)
- out_url = dir_name + "%s.caf"%card.short_hash
+ out_url = dir_name + "%s.caf" %card.short_hash
print "Out to ", out_url
out_fl = open(out_url, 'w')
for eachfile in request.FILES:
out_fl.write(request.FILES[eachfile].read())
if image:
- card.image_file = out_url
+ card.image_file = short_name + "%s.jpg" %card.short_hash
elif sound:
- card.audio_file = out_url
+ card.audio_file = short_name + "%s.caf" %card.short_hash
card.save()
json_response['success'] = True
except Exception, e:

0 comments on commit 43aaa31

Please sign in to comment.