From f60dee1ee321562e0c21632c55d919f68470ed20 Mon Sep 17 00:00:00 2001 From: Subhodip Biswas Date: Sun, 19 Aug 2012 19:13:23 +0530 Subject: [PATCH 1/3] User registration --- chaloBEST/settings.py | 52 ++++++++++++++++++++++++++-------- chaloBEST/templates/base.html | 6 ++-- chaloBEST/templates/index.html | 6 ++-- chaloBEST/urls.py | 8 +++++- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/chaloBEST/settings.py b/chaloBEST/settings.py index 67b6364..730adc8 100644 --- a/chaloBEST/settings.py +++ b/chaloBEST/settings.py @@ -134,30 +134,58 @@ INSTALLED_APPS = ( #'socialregistration.contrib.facebook', 'emailconfirmation', # 'uni_form', - 'allauth', - 'allauth.account', - 'allauth.socialaccount', - 'allauth.socialaccount.providers.twitter', - 'allauth.socialaccount.providers.openid', - 'allauth.socialaccount.providers.facebook', + # 'allauth', + # 'allauth.account', + # 'allauth.socialaccount', + # 'allauth.socialaccount.providers.twitter', + # 'allauth.socialaccount.providers.openid', + # 'allauth.socialaccount.providers.facebook', #'allauth.socialaccount.providers.google', + 'users', + 'profiles', + 'userena', + 'guardian', + 'easy_thumbnails', + 'south', + 'django_extensions', + 'userena.contrib.umessages', + ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.request', 'django.contrib.auth.context_processors.auth', - "allauth.context_processors.allauth", - "allauth.account.context_processors.account" + #"allauth.context_processors.allauth", + #"allauth.account.context_processors.account", + "django.contrib.messages.context_processors.messages" + ) AUTHENTICATION_BACKENDS = ( - "allauth.account.auth_backends.AuthenticationBackend", +# "allauth.account.auth_backends.AuthenticationBackend", + "userena.backends.UserenaAuthenticationBackend", + "guardian.backends.ObjectPermissionBackend", + "django.contrib.auth.backends.ModelBackend", + ) +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST ='smtp.gmail.com' -EMAIL_HOST_USER = 'subhodipbiswas@gmail.com' -EMAIL_HOST_PASSWORD ='doaxhentai' +EMAIL_HOST_USER = 'abc@abc.com' +EMAIL_HOST_PASSWORD ='somepassword' EMAIL_PORT =587 EMAIL_USE_TLS =True SERVER_EMAIL = EMAIL_HOST_USER -DEFAULT_FROM_EMAIL=EMAIL_HOST_USER +DEFAULT_FROM_EMAIL=EMAIL_HOST_USER +AUTH_PROFILE_MODULE = "users.UserProfile" +#AUTH_PROFILE_MODULE = 'profiles.Profile' +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_MUGSHOT_SIZE = 140 +USERENA_MUGSHOT_GRAVATAR=True +USERENA_MUGSHOT_DEFAULT='monsterid' +ANONYMOUS_USER_ID = -1 + try: from local_settings import * except: diff --git a/chaloBEST/templates/base.html b/chaloBEST/templates/base.html index 2333471..33b4571 100644 --- a/chaloBEST/templates/base.html +++ b/chaloBEST/templates/base.html @@ -42,10 +42,10 @@ body,html { {% block body %} {% block content %} diff --git a/chaloBEST/templates/index.html b/chaloBEST/templates/index.html index 283f0e2..2310d50 100644 --- a/chaloBEST/templates/index.html +++ b/chaloBEST/templates/index.html @@ -11,10 +11,10 @@ {% block body %} {% block content %} diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index a4e43a7..ee53bf0 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -25,7 +25,7 @@ urlpatterns = patterns('', # (r'^stop/(?P.*?)/georss/$', StopFeed()), (r'^buseditor/$', 'mumbai.views.buseditor'), (r'^editstops/$', 'mumbai.views.editstops'), - (r'^accounts/', include('allauth.urls')), + #(r'^accounts/', include('allauth.urls')), (r'^1.0/', include('mumbai.apiurls')), #url(r'^login/', include('socialregistration.urls',namespace='socialregistration')), # Uncomment the admin/doc line below to enable admin documentation: @@ -35,6 +35,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')), + #(r'^accounts/signup/$', 'userena.views.signup', + #{'signup_form': SignupFormExtra}), + + url(r'^messages/',include('userena.contrib.umessages.urls')), + ) From 7aae1931984b907ea95e1eca562fa601da79a424 Mon Sep 17 00:00:00 2001 From: Subhodip Biswas Date: Sun, 19 Aug 2012 19:41:26 +0530 Subject: [PATCH 2/3] some changes --- requirements.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 946c686..1e718e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,7 @@ Django==1.4.1 +PIL==1.1.7 RapidSMS==0.9.6a +South==0.7.5 -e git://github.com/schuyler/arrest.git@0017837a45bcb31786f953fba976d454ae684ecc#egg=arrest-dev chardet==1.0.1 django-allauth==0.5.0 @@ -7,14 +9,18 @@ django-avatar==1.0.5 django-debug-toolbar==0.9.4 django-email-confirmation==0.2 -e git://github.com/bit/django-extensions.git@c495f97a1d37bf5d40508b8e0eb128ae9fa0a6b0#egg=django_extensions-dev +django-grappelli==2.3.8 django-guardian==1.0.4 django-nose==1.1 django-profiles==0.2 +django-registration==0.8 django-sms==0.0.4 +django-socialregistration==0.5.4 +django-userena==1.1.2 djappsettings==0.1.0 djtables==0.1.2 -#facebook-python-sdk==0.1 --e git://github.com/jhaddad/facebook-python-sdk#egg=facebook-python-sdk +easy-thumbnails==1.0.3 +facebook-python-sdk==0.1 facebook-sdk==0.3.1 feedparser==5.1.2 -e git://github.com/seatgeek/fuzzywuzzy.git@c73e3d32e3bb4d31dc38cc64e3a3362855d4d249#egg=fuzzywuzzy-dev @@ -23,6 +29,6 @@ mock==0.8.0 nose==1.1.2 oauth2==1.5.211 -e bzr+http://code.0x2620.org/python-ox/@354#egg=ox-2.0.354-py2.7-dev_r354 -#psycopg2==2.4.5 +psycopg2==2.4.5 python-openid==2.2.5 wsgiref==0.1.2 From 5a3a04157f59d31419df101902f0b910b7e2c044 Mon Sep 17 00:00:00 2001 From: Subhodip Biswas Date: Sun, 19 Aug 2012 19:52:27 +0530 Subject: [PATCH 3/3] minor changes --- chaloBEST/users/__init__.py | 0 chaloBEST/users/forms.py | 29 ++++ chaloBEST/users/models.py | 60 +++++++ .../users/templates/profiles/avatar.html | 29 ++++ .../templates/profiles/create_profile.html | 35 ++++ .../templates/profiles/edit_profile.html | 153 ++++++++++++++++++ .../templates/profiles/edit_settings.html | 72 +++++++++ .../templates/profiles/profile_detail.html | 91 +++++++++++ .../templates/profiles/profile_list.html | 15 ++ chaloBEST/users/tests.py | 16 ++ chaloBEST/users/views.py | 1 + 11 files changed, 501 insertions(+) create mode 100644 chaloBEST/users/__init__.py create mode 100644 chaloBEST/users/forms.py create mode 100644 chaloBEST/users/models.py create mode 100644 chaloBEST/users/templates/profiles/avatar.html create mode 100644 chaloBEST/users/templates/profiles/create_profile.html create mode 100644 chaloBEST/users/templates/profiles/edit_profile.html create mode 100644 chaloBEST/users/templates/profiles/edit_settings.html create mode 100644 chaloBEST/users/templates/profiles/profile_detail.html create mode 100644 chaloBEST/users/templates/profiles/profile_list.html create mode 100644 chaloBEST/users/tests.py create mode 100644 chaloBEST/users/views.py diff --git a/chaloBEST/users/__init__.py b/chaloBEST/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chaloBEST/users/forms.py b/chaloBEST/users/forms.py new file mode 100644 index 0000000..6a867ac --- /dev/null +++ b/chaloBEST/users/forms.py @@ -0,0 +1,29 @@ +from django import forms +from django.utils.translation import ugettext_lazy as _ + +from userena.forms import SignupForm + +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 + 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() diff --git a/chaloBEST/users/models.py b/chaloBEST/users/models.py new file mode 100644 index 0000000..6535d9c --- /dev/null +++ b/chaloBEST/users/models.py @@ -0,0 +1,60 @@ +from django.db import models +from django.contrib.auth.models import User +from userena.models import UserenaBaseProfile +from userena.models import UserenaLanguageBaseProfile +#from django.contrib.auth.models import User +#from django.contrib.auth.models import User +#from django.contrib.auth.models import User +from django.utils.translation import ugettext_lazy as _ +from django.db.models.signals import post_save +import datetime + +# Create your models here. +class UserProfile(UserenaLanguageBaseProfile): + GENDER_CHOICES =( + (1, _('Male')), + (2, _('Female')), + ) + +# user = models.ForeignKey(User, unique=True) +# url - models.URLField("Website", blank=True) +# company = models.CharField(max_length=50, blank=True) + user = models.ForeignKey(User, + unique=True, + verbose_name =('user'), + related_name = 'profile') + gender = models.PositiveSmallIntegerField(_('gender'), + choices=GENDER_CHOICES, + blank = True, + null=True) + 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) + @property + def age(self): + if not self.birth_date: return False + else: + today = datetime.date.today() + try: + birthday = self.birth_date.replace(year=today.year) + except ValueError: + day = today.day -1 if today.day != 1 else today.day + 2 + birthday = self.birth_date.replace(year=today.year, day = day) + if birthday > today: return today.year - self.birth_date.year - 1 + else: return today.year - self.birth_date.year +#def create_user_profile(sender, instance, created, **kwargs): +# if created: +# UserProfile.objects.create(user=instance) + +#post_save.connect(create_user_profile, sender=User) +#def create_profile(sender, **kw): +# user = kw["instance"] +# if kw["created"]: +# up = UserProfile(user=user, gender=1,location="test") +# up.save() +#post_save.connect(create_profile, sender=User) + + +#User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]) + diff --git a/chaloBEST/users/templates/profiles/avatar.html b/chaloBEST/users/templates/profiles/avatar.html new file mode 100644 index 0000000..d3767be --- /dev/null +++ b/chaloBEST/users/templates/profiles/avatar.html @@ -0,0 +1,29 @@ +{% load thumbnail %} + +{% comment %} + If profile has an avatar, show it. + If user is viewing their own list and they don't have an avatar, + show them the Add Photo button. Otherwise show generic avatar. +{% endcomment %} + + + +
+ + {% if profile.avatar %} + + {% thumbnail profile.avatar "100x100" crop="center" as im %} + {{profile}}'s avatar image + {% endthumbnail %} + + + {% else %} + {% if profile == user.get_profile %} + Please add an avatar to your profile. + {% else %} + Generic avatar + {% endif %} + + {% endif %} + +
diff --git a/chaloBEST/users/templates/profiles/create_profile.html b/chaloBEST/users/templates/profiles/create_profile.html new file mode 100644 index 0000000..2accd5d --- /dev/null +++ b/chaloBEST/users/templates/profiles/create_profile.html @@ -0,0 +1,35 @@ +{% extends "main_template.html" %} +{% block content%} + + + +
+

Create Profile:

+
+ + +

{{ user|capfirst }}, before we begin, lets set some of your account preferences. These can be changed at any time.

+ +
+

+ Default League to bet: * {{ form.pref_sport }} + {% for error in form.pref_sport.errors %} + {{ error|escape }} + {% endfor %} +

+ +

+ Default Number of games to bet: * {{ form.pref_num_games }} + {% for error in form.pref_num_games.errors %} + {{ error|escape }} + {% endfor %} +

+ + +
+ +{% endblock %} \ No newline at end of file diff --git a/chaloBEST/users/templates/profiles/edit_profile.html b/chaloBEST/users/templates/profiles/edit_profile.html new file mode 100644 index 0000000..fbd8c8d --- /dev/null +++ b/chaloBEST/users/templates/profiles/edit_profile.html @@ -0,0 +1,153 @@ +{% extends "base.html" %} +{% load thumbnail %} + + +{% block title %}Edit Profile{% endblock %} + +{% block extrahead %} + {# Bring in jquery-ui and its theme #} + + + + + + {# form.media #} {# -- js for tinymce #} + + +{% endblock %} + +{% block content %} + +{# Hidden divs - revealed by jquery dialog #} + +
+ {% include 'media_instr.html' %} +
+ + +{% if form.errors %} +
    +

    The following required fields are missing:

    + {% for error in form.errors %} +
  • {{ error }}
  • + {% endfor %} +
+{% endif %} + + +{# Reusable avatar code #} +{% if not profile.avatar %} + {% include 'profiles/avatar.html' %} +{% endif %} + + + +

Edit profile for {{ user.first_name }} {{ user.last_name }} ({{user}})

+ + + +
+ +

Tell us about yourself...

+ +
+ + {% csrf_token %} + +
+ {{form.avatar.label_tag}} + {% if profile.avatar %} + {% thumbnail profile.avatar "100x100" crop="center" as im %} + {{profile}}'s avatar image + {% endthumbnail %}
+ + {#
#} + {% endif %} + {{form.avatar}}
+ {{form.avatar.help_text|safe}} +
+ +
+ {{form.about.label_tag}} + {{form.about.help_text|safe}}
+ + ⎋ You can add images and video to your profile! + {{form.about}} + +
+ +
+ {{form.email.label_tag}} + {{form.email}}
+ {{form.email.help_text}} +
+ + + +
+ {{form.city.label_tag}} + {{form.city}} +
+ +
+ {{form.state.label_tag}} + {{form.state}} +
+ + +
+ {{form.country.label_tag}} + {{form.country}} +
+ +
+ {{form.twitter.label_tag}} + {{form.twitter}}
+ {{form.twitter.help_text|safe}} +
+ +
+ {{form.facebook.label_tag}} + {{form.facebook}}
+ {{form.facebook.help_text|safe}} +
+ +
+ {{form.allow_contact}} {{form.allow_contact.label_tag}} +
+ +
+ {{form.email_updates}} {{form.email_updates.label_tag}} +
+ +
+ {{form.email_on_follow}} {{form.email_on_follow.label_tag}} +
+ +
+ {{form.email_site_news}} {{form.email_site_news.label_tag}} +
+ +

+ +

+ » Change password « + » Account settings « + » Delete account « +

+ + +
+{% endblock content %} + diff --git a/chaloBEST/users/templates/profiles/edit_settings.html b/chaloBEST/users/templates/profiles/edit_settings.html new file mode 100644 index 0000000..e7a591e --- /dev/null +++ b/chaloBEST/users/templates/profiles/edit_settings.html @@ -0,0 +1,72 @@ +{% extends "base.html" %} +{% load thumbnail %} + + +{% block title %}Edit Profile Settings{% endblock %} + + +{% block content %} + +{% if form.errors %} +
    +

    The following required fields are missing:

    + {% for error in form.errors %} +
  • {{ error }}
  • + {% endfor %} +
+{% endif %} + + +

Edit settings for {{ user.first_name }} {{ user.last_name }} ({{user}})

+ + +
+ +
+ + {% csrf_token %} + +

We recommend keeping all of these settings enabled.
+ Don't worry - none of them will result in a ton of email!

+ +
+ {{form.use_full_name}} {{form.use_full_name.label_tag}}
+ {{form.use_full_name.help_text}} +
+ +
+ {{form.email_updates}} {{form.email_updates.label_tag}} +
+ +
+ {{form.email_on_follow}} {{form.email_on_follow.label_tag}} +
+ +
+ {{form.email_on_copy}} {{form.email_on_copy.label_tag}} +
+ +
+ {{form.email_site_news}} {{form.email_site_news.label_tag}} +
+ +
+ {{form.allow_contact}} {{form.allow_contact.label_tag}} +
+ +
+ {{form.enable_comments}} {{form.enable_comments.label_tag}} +
+ + + +

+ +

+ » Change my password « + » Update profile « +

+ +
+{% endblock content %} + diff --git a/chaloBEST/users/templates/profiles/profile_detail.html b/chaloBEST/users/templates/profiles/profile_detail.html new file mode 100644 index 0000000..6fb660c --- /dev/null +++ b/chaloBEST/users/templates/profiles/profile_detail.html @@ -0,0 +1,91 @@ +{% extends "base.html" %} + +{% block extrahead %} + + + +{% endblock %} + +{% block title %} {{ user.first_name }} {{ user.last_name }}{% endblock %} + + + +{% block content %} + +{{block.super}} + +{% ifequal user profile.user %} +

+ Edit my profile + Account settings +

+{% endifequal %} + + +{# Reusable avatar code #} +{% include 'profiles/avatar.html' %} + + +

{{ profile }}

+ +

+ {% if profile.city %} + {{ profile.city }}, {{ profile.state }}, {{ profile.country }}
+ {% endif %} + + {% if profile.allow_contact %} + Contact {{ profile.user.first_name }} +
+ {% endif %} + + + + Feed Icon 14x14 {{profile.user.first_name}}'s feed +

+ + + + +
+ + +{% if profile.about %} + +
+ {{profile.about|safe}} +
+ +{% else %} +

No profile information available

+{% endif %} +

+ + +{% if profile.twitter %} +

Twitter: + {{ profile.twitter }} +

+{% endif %} + + + +{% if profile.facebook %} +

Facebook: + {{ profile.facebook }} +

+{% endif %} + + +{% if profile.fax %} +

Fax:
+{{ profile.fax }} +

+{% endif %} + +{% endblock content %} + diff --git a/chaloBEST/users/templates/profiles/profile_list.html b/chaloBEST/users/templates/profiles/profile_list.html new file mode 100644 index 0000000..381c0d5 --- /dev/null +++ b/chaloBEST/users/templates/profiles/profile_list.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + + +{% block title %}Contact info for {{ user.first_name }} {{ user.last_name }}{% endblock %} + +{% block content %} + +{{block.super}} + +{% for p in object_list %} + {{ p }}
+{% endfor %} + +{% endblock content %} + diff --git a/chaloBEST/users/tests.py b/chaloBEST/users/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/chaloBEST/users/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/chaloBEST/users/views.py b/chaloBEST/users/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/chaloBEST/users/views.py @@ -0,0 +1 @@ +# Create your views here.