minor changes

This commit is contained in:
Subhodip Biswas 2012-08-19 19:52:27 +05:30
parent 7aae193198
commit 5a3a04157f
11 changed files with 501 additions and 0 deletions

View File

29
chaloBEST/users/forms.py Normal file
View File

@ -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()

60
chaloBEST/users/models.py Normal file
View File

@ -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])

View File

@ -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 %}
<div class="avatar">
{% if profile.avatar %}
{% thumbnail profile.avatar "100x100" crop="center" as im %}
<a href="{% url list_view profile.user.username %}"><img src="{{im.url}}" width="{{im.width}}" height="{{im.height}}" alt="{{profile}}'s avatar image" /></a>
{% endthumbnail %}
{% else %}
{% if profile == user.get_profile %}
<a href="{% url profiles_edit_profile %}"><img src="{{ MEDIA_URL }}images/no-photo.png" width="100" height="100" alt="Please add an avatar to your profile."></a>
{% else %}
<a href="{% url list_view profile.user.username %}"><img src="{{ STATIC_URL }}images/user_default_medium.png" width="100" height="100" alt="Generic avatar"></a>
{% endif %}
{% endif %}
</div>

View File

@ -0,0 +1,35 @@
{% extends "main_template.html" %}
{% block content%}
<script>
$(document).ready(function() {
$("#profile").addClass("active");
});
</script>
<div class="description">
<h2>Create Profile:</h2>
</div>
<h2>{{ user|capfirst }}, before we begin, lets set some of your account preferences. These can be changed at any time.</h2>
<form method="POST" action="">
<p>
Default League to bet: <span class="required">*</span> {{ form.pref_sport }}
{% for error in form.pref_sport.errors %}
{{ error|escape }}
{% endfor %}
</p>
<p>
Default Number of games to bet: <span class="required">*</span> {{ form.pref_num_games }}
{% for error in form.pref_num_games.errors %}
{{ error|escape }}
{% endfor %}
</p>
<input type="submit" name="submit" class="submit" value="Create Profile">
</form>
{% endblock %}

View File

@ -0,0 +1,153 @@
{% extends "base.html" %}
{% load thumbnail %}
{% block title %}Edit Profile{% endblock %}
{% block extrahead %}
{# Bring in jquery-ui and its theme #}
<link type="text/css" href="{{STATIC_URL}}js/jquery-ui/css/eggplant/jquery-ui-1.8rc1.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="{{STATIC_URL}}js/jquery-ui/js/jquery-ui-1.8rc1.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
jQuery("#formatting").dialog({
bgiframe: true, autoOpen: false, height: 570, width: 550, modal: false
});
jQuery("#adding_media").dialog({
bgiframe: true, autoOpen: false, height: 500, width: 650, modal: false
});
});
</script>
{# form.media #} {# -- js for tinymce #}
<script type="text/javascript" src="/static/js/tiny_mce/tiny_mce.js"></script>
{% endblock %}
{% block content %}
{# Hidden divs - revealed by jquery dialog #}
<div id="adding_media" title="Adding images and video">
{% include 'media_instr.html' %}
</div>
{% if form.errors %}
<ul id="messagelist">
<p>The following required fields are missing:</p>
{% for error in form.errors %}
<li class="error">{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{# Reusable avatar code #}
{% if not profile.avatar %}
{% include 'profiles/avatar.html' %}
{% endif %}
<h2>Edit profile for {{ user.first_name }} {{ user.last_name }} ({{user}})</h2>
<div class="clear"></div>
<h1>Tell us about yourself...</h1>
<form enctype="multipart/form-data" method="post" action="" style="margin-top:20px;">
{% csrf_token %}
<div class="fieldWrapper">
{{form.avatar.label_tag}}
{% if profile.avatar %}
{% thumbnail profile.avatar "100x100" crop="center" as im %}
<a href="{% url list_view profile.user.username %}"><img src="{{im.url}}" width="{{im.width}}" height="{{im.height}}" alt="{{profile}}'s avatar image" /></a>
{% endthumbnail %}<br />
{# <img src="{% thumbnail profile.avatar 100x100 quality=70 %}" /> <br /> #}
{% endif %}
{{form.avatar}}<br />
{{form.avatar.help_text|safe}}
</div>
<div class="fieldWrapper">
{{form.about.label_tag}}
{{form.about.help_text|safe}}<br />
<a style="margin-right:30px;" href="#" onclick="jQuery('#adding_media').dialog('open'); return false">&#x238B; You can add images and video to your profile!</a>
{{form.about}}
</div>
<div class="fieldWrapper">
{{form.email.label_tag}}
{{form.email}}<br />
{{form.email.help_text}}
</div>
<div class="fieldWrapper">
{{form.city.label_tag}}
{{form.city}}
</div>
<div class="fieldWrapper">
{{form.state.label_tag}}
{{form.state}}
</div>
<div class="fieldWrapper">
{{form.country.label_tag}}
{{form.country}}
</div>
<div class="fieldWrapper">
{{form.twitter.label_tag}}
{{form.twitter}}<br />
{{form.twitter.help_text|safe}}
</div>
<div class="fieldWrapper">
{{form.facebook.label_tag}}
{{form.facebook}}<br />
{{form.facebook.help_text|safe}}
</div>
<div class="fieldWrapper inline">
{{form.allow_contact}} {{form.allow_contact.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.email_updates}} {{form.email_updates.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.email_on_follow}} {{form.email_on_follow.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.email_site_news}} {{form.email_site_news.label_tag}}
</div>
<p><input class="button blue" type="submit" value="Update profile" /> </p>
<p>
<a href="/accounts/password/change/" class="button small blue">&raquo; Change password &laquo;</a>
<a href="{% url profile_settings %}" class="button small blue">&raquo; Account settings &laquo;</a>
<a href="{% url account_del %}" class="button small blue">&raquo; Delete account &laquo;</a>
</p>
</form>
{% endblock content %}

View File

@ -0,0 +1,72 @@
{% extends "base.html" %}
{% load thumbnail %}
{% block title %}Edit Profile Settings{% endblock %}
{% block content %}
{% if form.errors %}
<ul id="messagelist">
<p>The following required fields are missing:</p>
{% for error in form.errors %}
<li class="error">{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
<h2>Edit settings for {{ user.first_name }} {{ user.last_name }} ({{user}})</h2>
<div class="clear"></div>
<form enctype="multipart/form-data" method="post" action="" style="margin-top:20px;">
{% csrf_token %}
<p>We recommend keeping all of these settings enabled. <br />
Don't worry - none of them will result in a ton of email!</p>
<div class="fieldWrapper inline">
{{form.use_full_name}} {{form.use_full_name.label_tag}}<br />
<span style="margin-left:25px;">{{form.use_full_name.help_text}}</span>
</div>
<div class="fieldWrapper inline">
{{form.email_updates}} {{form.email_updates.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.email_on_follow}} {{form.email_on_follow.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.email_on_copy}} {{form.email_on_copy.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.email_site_news}} {{form.email_site_news.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.allow_contact}} {{form.allow_contact.label_tag}}
</div>
<div class="fieldWrapper inline">
{{form.enable_comments}} {{form.enable_comments.label_tag}}
</div>
<p style="margin-top:30px;"><input class="button blue" type="submit" value="Update settings" /> </p>
<p>
<a href="/accounts/password/change/" class="button medium green">&raquo; Change my password &laquo;</a>
<a href="{% url profiles_edit_profile %}" class="button medium green">&raquo; Update profile &laquo;</a>
</p>
</form>
{% endblock content %}

View File

@ -0,0 +1,91 @@
{% extends "base.html" %}
{% block extrahead %}
<script type="text/javascript" src="http://scripts.embed.ly/embedly.js" ></script>
<script type="text/javascript">
// set custom embedly defaults
// More customizations at http://api.embed.ly/tools/script
var embedly_maxWidth = 600;
var embedly_maxHeight = 600;
</script>
{% endblock %}
{% block title %} {{ user.first_name }} {{ user.last_name }}{% endblock %}
{% block content %}
{{block.super}}
{% ifequal user profile.user %}
<p>
<a href="{% url profiles_edit_profile %}" class="button blue">Edit my profile</a>
<a href="{% url profile_settings %}" class="button blue">Account settings</a>
</p>
{% endifequal %}
{# Reusable avatar code #}
{% include 'profiles/avatar.html' %}
<h2><a href="{% url list_view profile.user.username %}">{{ profile }}</a></h2>
<p class="smalltop" style="float:left;margin-right:70px;">
{% if profile.city %}
{{ profile.city }}, {{ profile.state }}, {{ profile.country }} <br />
{% endif %}
{% if profile.allow_contact %}
<a href="{% url contact_form profile.user %}">Contact {{ profile.user.first_name }} </a>
<br />
{% endif %}
<a href="/feeds/people/{{profile.user}}"><img src="{{STATIC_URL}}images/feed-icon-14x14.png" width="12" height="12" alt="Feed Icon 14x14"> <span class="minor">{{profile.user.first_name}}'s feed</span></a>
</p>
<div class="clear"></div>
{% if profile.about %}
<div id="oembed" class="profile">
{{profile.about|safe}}
</div>
{% else %}
<p style="margin-top:10px;">No profile information available</p>
{% endif %}
</p>
{% if profile.twitter %}
<p><strong>Twitter:</strong>
<a href="http://twitter.com/{{ profile.twitter }}">{{ profile.twitter }}</a>
</p>
{% endif %}
{% if profile.facebook %}
<p><strong>Facebook:</strong>
<a href="http://facebook.com/{{ profile.facebook }}">{{ profile.facebook }}</a>
</p>
{% endif %}
{% if profile.fax %}
<p><strong>Fax:</strong><br>
{{ profile.fax }}
</p>
{% endif %}
{% endblock content %}

View File

@ -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 %}
<a href="{% url profiles_profile_detail p.user %}">{{ p }}</a><br />
{% endfor %}
{% endblock content %}

16
chaloBEST/users/tests.py Normal file
View File

@ -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)

1
chaloBEST/users/views.py Normal file
View File

@ -0,0 +1 @@
# Create your views here.