Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
Initial Commit. Archiving old favmeal code. Just for the reference
Browse files Browse the repository at this point in the history
  • Loading branch information
nandak522 committed May 22, 2011
0 parents commit 89f1ae9
Show file tree
Hide file tree
Showing 367 changed files with 26,670 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
*.py[co]
*~
.project
.pydevproject
*settings.py
Empty file added __init__.py
Empty file.
Empty file added admin.py
Empty file.
Empty file added common/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions common/common_models.py
@@ -0,0 +1,40 @@
from django.db import models

class BaseModel(models.Model):
id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
modified_on = models.DateTimeField(auto_now=True)

class Meta:
abstract = True

class AddressManager(models.Manager):
def create_address(self, place, landmark, area, city='Hyderabad', zip=None, latitude=None, longitude=None):
address_exists = self.exists(place=place, landmark=landmark, area=area, city=city, zip=zip, latitude=latitude, longitude=longitude)
if address_exists:
return self.filter(place=place.strip().lower(), landmark=landmark.strip().lower(), area=area.strip().lower(), city=city, zip=zip, latitude=latitude, longitude=longitude)[0]
address = Address(place=place, landmark=landmark, area=area, city=city, zip=zip, latitude=latitude, longitude=longitude)
address.save()
return address

def exists(self, place, landmark, area, city='Hyderabad', zip=None, latitude=None, longitude=None):
try:
if self.filter(place=place.strip().lower(), landmark=landmark.strip().lower(), area=area.strip().lower(), city=city, zip=zip, latitude=latitude, longitude=longitude).count():
return True
except Address.DoesNotExist:
return False
return False

class Address(BaseModel):
place = models.CharField(max_length=100, blank=False)
landmark = models.CharField(max_length=50, blank=False)
area = models.CharField(max_length=50, blank=False)
city = models.CharField(max_length=50, default='Hyderabad', blank=False)
zip = models.IntegerField(max_length=6, blank=True, null=True)
latitude = models.DecimalField(max_digits=17, decimal_places=14, blank=True, null=True)
longitude = models.DecimalField(max_digits=17, decimal_places=14, blank=True, null=True)
objects = AddressManager()

def __unicode__(self):
return '%s, %s' % (self.place, self.area)

78 changes: 78 additions & 0 deletions common/common_views.py
@@ -0,0 +1,78 @@
from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponsePermanentRedirect
from utils import response, post_data, _request_param_post, _request_param_get
from utils import _add_noticemsg, _add_errormsg, _add_successmsg
from django.conf import settings
from django.core import urlresolvers

def view_contactus(request,homepage_template,contactus_template):
selected_maintab = 'contactus'
if request.method != 'POST':
from common.forms import ContactUsQueryForm
form = ContactUsQueryForm()
return response(contactus_template, locals(), request)
from common.forms import ContactUsQueryForm
form = ContactUsQueryForm(post_data(request))
if not form.is_valid():
return response(contactus_template, locals(), request)
email = form.cleaned_data.get('email')
name = form.cleaned_data.get('name')
query = form.cleaned_data.get('query')
from utils.emailer import customer_query_emailer
mail_sent = customer_query_emailer(subject="Customer Query",from_email=email,email_body=query,from_name=name)
if mail_sent:
_add_successmsg(request,'Query Successfully Submitted. We will get back to you very soon. Thankyou.')
return response(homepage_template, locals(), request)
_add_errormsg(request,'Query can\'t be submitted now. Please try again.')
return response(contactus_template, locals(), request)

def view_refer_friend(request, referfriend_template):
if request.method != 'POST':
from common.forms import ReferFriendForm
form = ReferFriendForm()
return response(referfriend_template, locals(), request)
from common.forms import ReferFriendForm
form = ReferFriendForm(post_data(request))
if not form.is_valid():
_add_errormsg(request,'Please fill up valid inforsettingsmation in required fields')
return response(referfriend_template, locals(), request)
name = form.cleaned_data.get('name')
email = form.cleaned_data.get('email')
ref_emails = form.cleaned_data.get('ref_emails')
ref_mobiles = form.cleaned_data.get('ref_mobiles')
if _send_invitations(request,name, email, ref_emails, ref_mobiles):
_add_successmsg(request, 'Your friend(s) \' %s \' have been invited. Thanks for being with favmeal!' % (ref_emails))
return response(referfriend_template, locals(), request)
else:
_add_errormsg(request,'There seems to be a problem in sending the invitation. Please try again!')
return response(referfriend_template, locals(), request)

def _send_invitations(request,name, email, ref_emails, ref_mobiles):
datalist = []
referfriend_mail_sub = "Do you know about Favmeal?"
all_emails_list = ref_emails.strip().split(',')
try:
from django.core.mail import send_mail, EmailMessage
from django.template.loader import render_to_string
html_content = render_to_string('referfriend_mail_content.html', {name:name})

if name:
from_email = '%s<%s>' % (name, email)
else:
from_email = '%s<%s>' % (email, email)
for to_email in all_emails_list:
msg = EmailMessage(referfriend_mail_sub, html_content, from_email, [to_email])
msg.content_subtype = "html"
msg.attach_file(settings.MEDIA_ROOT+'flat/Favmeal_Brochure.pdf')
all_invited = msg.send(fail_silently=False)
#FIXME:Refactor the below code
admin_mail_sub = "[Refer Friend] By %s<%s>" % (name,email)
admin_mail_body = "From: %s<%s>\nReferred email Ids: %s; Referred Mobiles: %s" % (name,email,ref_emails,ref_mobiles)
admin_mail_sent = send_mail(admin_mail_sub, admin_mail_body, '',['contact@favmeal.com'], fail_silently=False)
except Exception,e:
#FIXME:Avoid global Exceptions. Have proper handling mechanism for each case
_add_errormsg(request,'We are facing difficulty with mail servers. Please try again.')
return False
if all_invited:
return admin_mail_sent
else:
return all_invited
Empty file added common/fixtures/__init__.py
Empty file.
1 change: 1 addition & 0 deletions common/fixtures/addresses.json

Large diffs are not rendered by default.

Empty file.
59 changes: 59 additions & 0 deletions common/forms.py
@@ -0,0 +1,59 @@
from django import forms

class ContactUsQueryForm(forms.Form):
name = forms.CharField(max_length=50,required=False,label='Name',initial='',widget=forms.TextInput({'tabindex':'1','size': 20,'style':'font-size:95%;font-family:sans-serif;color:#555;'}))
email = forms.EmailField(required=True, label='Email', initial='',widget=forms.TextInput({'tabindex':'2','size': 20,'style':'font-size:95%;font-family:sans-serif;color:#555;'}))
query = forms.CharField(max_length=1000,required=True,label='Name',initial='',widget=forms.Textarea({'tabindex':'3','rows': 2,'cols':10,'style':'height:100px;font-size:95%;font:bold 1em sans-serif;color:#555;'}))

class ReferFriendForm(forms.Form):
name = forms.CharField(max_length=50,required=False,label='',initial='',widget=forms.TextInput({'tabindex':'1','size': 20,'style':'font-size:95%;font-family:sans-serif;color:#555;'}))
email = forms.EmailField(required=True, label='', initial='',widget=forms.TextInput({'tabindex':'2','size': 20,'style':'font-size:95%;font-family:sans-serif;color:#555;'}))
ref_emails = forms.CharField(max_length=1000,required=False,label='',initial='',widget=forms.Textarea({'tabindex':'3','rows': 2,'cols':19,'style':'height:50px;font-size:95%;font-family: sans-serif;color:#555;'}))
ref_mobiles = forms.CharField(max_length=1000,required=False,label='',initial='',widget=forms.Textarea({'tabindex':'4','rows': 2,'cols':19,'style':'height:50px;font-size:95%;font-family: sans-serif;color:#555;'}))

def clean_name(self):
name = self.cleaned_data.get('name')
return name.strip()

def clean_ref_mobiles(self):
ref_emails = self.cleaned_data.get('ref_emails')
ref_mobiles = self.cleaned_data.get('ref_mobiles')
if not ref_mobiles:
if not ref_emails:
raise forms.ValidationError('Either your friends email id(s) or mobile no(s) are required to provide.')
return ref_mobiles.strip()
list_mobiles = ref_mobiles.strip().lower().split(',')
if list_mobiles:
for mobile in list_mobiles:
if len(mobile) == 10 and mobile.startswith('9'):
try:
if int(mobile) <= 9999999999:
continue
except:
raise forms.ValidationError('Invalid Mobile Number')
else:
raise forms.ValidationError('Invalid Mobile Number')
return ref_mobiles.strip()

def clean_ref_emails(self):
unsuccessful_emails_list, successful_emails_list = [],[]
email = self.cleaned_data.get('email')
ref_emails = self.cleaned_data.get('ref_emails')
ref_mobiles = self.cleaned_data.get('ref_mobiles')
if not ref_emails:
if not ref_mobiles:
raise forms.ValidationError('Either your friends email id(s) or mobile no(s) are required to provide.')
return ref_emails.strip()
all_emails_list = ref_emails.strip().split(',')
from django.forms.fields import email_re
for email_id in all_emails_list:
if email_re.search(email_id.strip().lower()):
if email_id == email:
if all_emails_list.__len__() == 1:
raise forms.ValidationError('You can\'t refer yourself, right!')
else:
successful_emails_list.append(email_id)
else:
unsuccessful_emails_list.append(email_id)
return ",".join(["%s" % (email) for email in successful_emails_list])

1 change: 1 addition & 0 deletions common/models.py
@@ -0,0 +1 @@
from common.common_models import *
Empty file added common/templatetags/__init__.py
Empty file.
1 change: 1 addition & 0 deletions common/views.py
@@ -0,0 +1 @@
from common.common_views import *
104 changes: 104 additions & 0 deletions confs/lighttpd.conf
@@ -0,0 +1,104 @@
server.modules = ("mod_rewrite", "mod_redirect", "mod_alias", "mod_access", "mod_auth", "mod_fastcgi", "mod_expire", "mod_compress", "mod_accesslog")

server.document-root = "/home/nanda/webapps/django/favmeal/site_media/"

server.errorlog = "/home/nanda/webapps/django/lighttpd/logs/error.log"

index-file.names = ( "index.php", "index.html", "index.htm", "default.htm" )

mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jar" => "application/x-java-archive",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
"" => "application/octet-stream",
)

accesslog.filename = "/home/nanda/webapps/django/lighttpd/logs/access.log"

url.access-deny = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

server.port = 80

server.errorfile-prefix = "/home/nanda/webapps/django/lighttpd/status-"

fastcgi.server = (
"/favmeal.fcgi" => (
"main" => (
"host" => "127.0.0.1",
"port" => 3080,
"check-local" => "disable",),
#"fallback" =>("host" => "any fallback load balancing machine","port" => 3033,)
)
)

fastcgi.debug = 3

alias.url = (
"/media/" => "/home/nanda/lib/python2.5/django/contrib/admin/media/",
)
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^/site_media(.*)$" => "$1",
"^/favicon\.ico$" => "/site_media/img/favicon.png",
"^/robots\.txt$" => "/robots.txt",
"^(/.*)$" => "/favmeal.fcgi$1",
)

$HTTP["url"] =~ "^/site_media/" {
expire.url = ( "" => "access 168 hours" )
}

$HTTP["url"] =~ "\.(jpg|gif|png|css|js)$" {
expire.url = ( "" => "access 168 hours" )
}

0 comments on commit 89f1ae9

Please sign in to comment.