From 5a3a04157f59d31419df101902f0b910b7e2c044 Mon Sep 17 00:00:00 2001 From: Subhodip Biswas Date: Sun, 19 Aug 2012 19:52:27 +0530 Subject: [PATCH] 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 %} + +{% 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 %} + +{% 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.