From f673ad41c053e7c7458c9429ea771e3355a304c3 Mon Sep 17 00:00:00 2001 From: Subhodip Biswas Date: Mon, 22 Oct 2012 14:41:18 +0530 Subject: [PATCH] field for mobile number added --- chaloBEST/settings.py | 22 ++++++++- chaloBEST/urls.py | 9 ++-- chaloBEST/users/forms.py | 48 ++++++++++--------- chaloBEST/users/models.py | 3 ++ .../templates/profiles/profile_detail.html | 1 + chaloBEST/users/views.py | 43 +++++++++++++++++ 6 files changed, 100 insertions(+), 26 deletions(-) diff --git a/chaloBEST/settings.py b/chaloBEST/settings.py index 9fc15ca..b0a104a 100644 --- a/chaloBEST/settings.py +++ b/chaloBEST/settings.py @@ -63,6 +63,22 @@ MEDIA_URL = '/media/' STATIC_URL = '/static/' STATIC_ROOT = join(PROJECT_ROOT, 'static') +# Additional locations of static files +STATICFILES_DIRS = ( + # Put strings here, like "/home/html/static" or "C:/www/django/static". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. + os.path.join(PROJECT_ROOT, 'mumbai/static'), +) + +# List of finder classes that know how to find static files in +# various locations. +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +# 'django.contrib.staticfiles.finders.DefaultStorageFinder', +) + # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. @@ -101,6 +117,8 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'userena.middleware.UserenaLocaleMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware' ) @@ -180,9 +198,11 @@ LOGIN_REDIRECT_URL ='/accounts/%(username)s/' LOGIN_URL = '/accounts/signin/' LOGOUT_URL = '/accounts/signout/' #LOGIN_REDIRECT_URL = '/profiles/profile/' -USERENA_DISABLE_PROFILE_LIST = False +#USERENA_DISABLE_PROFILE_LIST = False +USERENA_DISABLE_PROFILE_LIST = True USERENA_MUGSHOT_SIZE = 140 USERENA_MUGSHOT_GRAVATAR=True +USERENA_USE_MESSAGES = True USERENA_MUGSHOT_DEFAULT='monsterid' ANONYMOUS_USER_ID = -1 diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index a19027c..dd653ec 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -7,6 +7,7 @@ admin.autodiscover() from feeds import RouteFeed #import ox.django.api.urls #import mumbai +from users.forms import SignupFormExtra urlpatterns = patterns('', @@ -43,10 +44,12 @@ urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^matchstops/$', 'mumbai.views.fuzzystops'), (r'^fuzzystops_edit/$', 'mumbai.views.fuzzystops_edit'), +# url(r'^accounts/', include('userena.urls')), + url(r'^accounts/signup/$', + 'userena.views.signup', + {'signup_form': SignupFormExtra}), url(r'^accounts/', include('userena.urls')), - #(r'^accounts/signup/$', 'userena.views.signup', - #{'signup_form': SignupFormExtra}), - + url(r'^messages/',include('userena.contrib.umessages.urls')), diff --git a/chaloBEST/users/forms.py b/chaloBEST/users/forms.py index 6a867ac..68ca1bf 100644 --- a/chaloBEST/users/forms.py +++ b/chaloBEST/users/forms.py @@ -2,28 +2,32 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from userena.forms import SignupForm +from users.models import UserProfile class SignupFormExtra(SignupForm): - first_name = forms.CharField(label = _(u'First name'), - max_length =30, - required=False) - last_name = forms.CharField(label = _(u'Last name'), - max_length = 30, - required=False) - mobile_number = forms.IntegerField(label = _(u'Mobile number'), - max_value =9999999999, - required=False) - def __init__(self, *args, **kw): - super(SignupFormExtra, self).__init__(*args, **kw) - new_order = self.fields.keyOrder[:-3] - new_order.insert(0, 'first_name') - new_order.insert(1, 'last_name') - new_order.insert(2, 'mobile_number') - self.fields.KeyOrder = new_order + #first_name = forms.CharField(label = _(u'First name'), + # max_length =30, + # required=False) + #last_name = forms.CharField(label = _(u'Last name'), + # max_length = 30, + # required=False) + mobile_number = forms.CharField(label = _(u'mobile number'), + max_length =10, + required=True) +# def __init__(self, *args, **kw): +# super(SignupFormExtra, self).__init__(*args, **kw) +# new_order = self.fields.keyOrder[:-3] +# new_order.insert(0, 'first_name') +# new_order.insert(1, 'last_name') +# new_order.insert(2, 'mobile_number') +# self.fields.KeyOrder = new_order def save(self): - new_user = super(SignupFormExtra, self).save() - new_user.first_name = self.cleaned_data['first_name'] - new_user.last_name = self.cleaned_data['last_name'] - new_user.mobile_number = self.cleaned_data['mobile_number'] - new_user.save() - return new_user() + new_user= super(SignupFormExtra, self).save() + user_profile = new_user.get_profile() + #user_profile.first_name = self.cleaned_data['first_name'] + #user_profile.last_name = self.cleaned_data['last_name'] + user_profile.mobile_number = self.cleaned_data['mobile_number'] + #user_profile.mobile_number = UserProfile.objects.get_or_create(name=user_profile.mobile_number) + + user_profile.save() + return new_user diff --git a/chaloBEST/users/models.py b/chaloBEST/users/models.py index 6535d9c..ecaa409 100644 --- a/chaloBEST/users/models.py +++ b/chaloBEST/users/models.py @@ -30,7 +30,10 @@ class UserProfile(UserenaLanguageBaseProfile): website = models.URLField(_('website'), blank=True, verify_exists=True) location = models.CharField(_('location'), max_length=255, blank=True) birth_date = models.DateField(_('birth date'), blank=True, null=True) +# about_me = models.TextField(_('about me'), blank = True) + mobile_number = models.CharField(_('mobile number'), blank = True, max_length=10) about_me = models.TextField(_('about me'), blank = True) + @property def age(self): if not self.birth_date: return False diff --git a/chaloBEST/users/templates/profiles/profile_detail.html b/chaloBEST/users/templates/profiles/profile_detail.html index 6fb660c..cd9ed56 100644 --- a/chaloBEST/users/templates/profiles/profile_detail.html +++ b/chaloBEST/users/templates/profiles/profile_detail.html @@ -85,6 +85,7 @@

Fax:
{{ profile.fax }}

+

Hello!!

{% endif %} {% endblock content %} diff --git a/chaloBEST/users/views.py b/chaloBEST/users/views.py index 60f00ef..e0494a8 100644 --- a/chaloBEST/users/views.py +++ b/chaloBEST/users/views.py @@ -1 +1,44 @@ # Create your views here. +from django.core.management import setup_environ +import settings +setup_environ(settings) +from users.models import UserProfile +from django.shortcuts import redirect +from django.shortcuts import render_to_response +from django.shortcuts import get_object_or_404 +from django.http import HttpResponse +from django.template import RequestContext +import django.utils.simplejson as json +import os +import urllib2 +#from users.models import * +from StringIO import StringIO +#from django.http import HttpResponse +from django.contrib.auth.models import User + + +def getsmsfeed(request): + current_user = request.user + print current_user + users = user.objects.all() + + apireq = urllib2.Request('http://sms.chalobest.in/messages_json/?phone_no='+mobilenumber) + apires = urllib2.urlopen(apireq) + try: + #jsonres = json.dumps(apires,sort_keys=True) + ##print jsonres.__class__ + #print apires + jstr = json.load(apires) + l = (json.dumps(jstr,sort_keys=True)).split("}") + #print l + sjstr = sorted(l, key=lambda l:l[0]) + #print sjstr[0]['datetime'] + #k = [i for i, j, k in jstr[1]] + print sjstr[-5:] + + #print jstr.get('text') + #print l.__class__ + except ValueError,e: + print e + +