Skip to content

Commit

Permalink
did alot of stuff all around
Browse files Browse the repository at this point in the history
  • Loading branch information
Jpadilla1 committed Apr 29, 2014
1 parent 4b05370 commit 721bdd2
Show file tree
Hide file tree
Showing 66 changed files with 1,037 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
venv
*.sqlite3
*.pyc
*.pyc
6 changes: 4 additions & 2 deletions apps/chats/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class Meta:

helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Create', 'Create', css_class='btn-lg btn-primary'))
helper.add_input(Submit(
'Create', 'Create', css_class='btn-lg btn-primary pull-right'))


class EnrollRoomForm(forms.Form):
key = forms.CharField(max_length=15, required=True,
validators=[MinLengthValidator(6), ])
helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Enroll', 'Enroll', css_class='btn-lg btn-primary'))
helper.add_input(Submit(
'Enroll', 'Enroll', css_class='btn-lg btn-primary pull-right'))
11 changes: 9 additions & 2 deletions apps/chats/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from django.views.generic import ListView, CreateView, DetailView
from django.shortcuts import redirect, get_object_or_404
from django.views.generic.edit import FormMixin
Expand All @@ -6,7 +8,7 @@

from ..messages.forms import CreateMessageForm
from ..messages.models import Message

from ..users.models import User
from .models import ChatRoom
from .forms import CreateRoomForm, EnrollRoomForm

Expand Down Expand Up @@ -49,6 +51,10 @@ def get_context_data(self, **kwargs):
context['form'] = self.get_form(self.get_form_class())
context['room'] = get_object_or_404(ChatRoom, slug=self.kwargs['slug'])
context['room_messages'] = Message.objects.filter(room=context['room'])
users = User.objects.filter(
last_login__gt=self.request.user.last_logged_out,
is_active__exact=1, ).order_by('-last_login')
context['online_users'] = users
return context

def post(self, request, *args, **kwargs):
Expand All @@ -61,7 +67,8 @@ def post(self, request, *args, **kwargs):
return self.form_invalid(form)

def form_valid(self, form):
form.instance.user = self.request.user
form.instance.created_by = self.request.user
form.instance.created_at = datetime.datetime.now()
form.instance.room = get_object_or_404(
ChatRoom, slug=self.kwargs['slug'])
form.save()
Expand Down
3 changes: 2 additions & 1 deletion apps/messages/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ class Meta:

helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Post', 'Post', css_class='btn-lg btn-primary'))
helper.add_input(Submit(
'Send', 'Send', css_class='btn-lg btn-primary pull-right'))
4 changes: 2 additions & 2 deletions apps/messages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Message(models.Model):
created_by = models.ForeignKey(User)
room = models.ForeignKey(ChatRoom)
created_at = models.DateTimeField(auto_now=False)
body = models.CharField(max_length=140,
help_text='Max characters is 140.')
body = models.CharField(max_length=400,
help_text='Max characters is 400.')

def __unicode__(self):
return self.body
10 changes: 8 additions & 2 deletions apps/users/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django import forms
from django.contrib.auth.forms import ReadOnlyPasswordHashField

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit

from .models import User


Expand Down Expand Up @@ -45,8 +48,11 @@ class Meta:
model = User
fields = ('username', 'email')

helper = FormHelper()
helper.form_method = 'POST'
helper.add_input(Submit('Create', 'Create', css_class='btn-lg btn-primary'))

def signup(self, request, user):
email = self.cleaned_data['email']
user.email = email
user.email = self.cleaned_data['email']
user.username = self.cleaned_data['username']
user.save()
10 changes: 10 additions & 0 deletions apps/users/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import datetime

from django.db import models
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser
from django.contrib.auth.signals import user_logged_out


class MyUserManager(BaseUserManager):
Expand Down Expand Up @@ -32,6 +35,7 @@ class User(AbstractBaseUser):
username = models.CharField(max_length=30, unique=True)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
last_logged_out = models.DateTimeField(auto_now=True)

objects = MyUserManager()

Expand All @@ -56,3 +60,9 @@ def has_module_perms(self, app_label):
@property
def is_staff(self):
return self.is_admin


def update_logged_out(sender, user, request, **kwargs):
user.last_logged_out = datetime.datetime.now()

user_logged_out.connect(update_logged_out)
2 changes: 2 additions & 0 deletions chatrooms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@
)

CRISPY_TEMPLATE_PACK = 'bootstrap3'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
9 changes: 9 additions & 0 deletions chatrooms/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns(
'',
url(r'^$',
TemplateView.as_view(template_name='static/index.html'),
name='home'),

url(r'^about/$',
TemplateView.as_view(template_name='static/about.html'),
name='about'),

url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('allauth.urls')),
url(r'^accounts/', include('apps.users.urls', namespace="users")),
Expand Down
37 changes: 36 additions & 1 deletion static/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@
position: relative;
}
.message {
font-size: 16px;
}
p {
#get-started {
background: url('../img/ocean.jpg') no-repeat;
background-size: cover;
display: block;
height: 93vh;
max-height: 93vh;
}
#greeting {
padding: 15px;
background-color: rgba(255, 255, 255, 0.6);
margin-top: 25vh;
}
.navbar {
margin-bottom: 0;
}
.btn-transparent {
padding: 11px 17px;
font-size: 20px;
letter-spacing: 0.15em;
color: #999;
background-color: rgba(255, 255, 255, 0);
border-color: #999;
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
-moz-transition: all 0.6s ease;
-o-transition: all 0.6s ease;
}
.btn-transparent:hover, .btn-transparent:focus {
color: #fff;
background-color: #428bca;
border-color: #fff;
}
ul {
list-style-type: none;
padding-left: 0;
}
Binary file added static/img/ocean.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions templates/account/account_inactive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "account/base.html" %}

{% load i18n %}

{% block head_title %}{% trans "Account Inactive" %}{% endblock %}

{% block content %}
<h1>{% trans "Account Inactive" %}</h1>

<p>{% trans "This account is inactive." %}</p>
{% endblock %}
3 changes: 3 additions & 0 deletions templates/account/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "base.html" %}


88 changes: 88 additions & 0 deletions templates/account/email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{% extends "account/base.html" %}
{% load i18n %}
{% load url from future %}
{% block title %}{% trans "Email" %}{% endblock %}

{% block content %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tags}} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
{{message}}
</div>
{% endfor %}
{% endif %}
<div class="email-setting-wrapper">
<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<h1>{% trans "Direcciones de E-mail" %}</h1>
{% if user.emailaddress_set.all %}
<p>{% trans 'Estas direcciones de email están asociadas a tu cuenta:' %}</p>

<form action="{% url 'account_email' %}" class="email_list" method="post">
{% csrf_token %}
<div class="form-group">
{% for emailaddress in user.emailaddress_set.all %}
<div class="radio">
<label for="email_radio_{{forloop.counter}}" class="{% if emailaddress.primary %}primary_email{%endif%}">

<input id="email_radio_{{forloop.counter}}" type="radio" name="email" {% if emailaddress.primary %}checked="checked" {%endif %} value="{{emailaddress.email}}" />
<span class="{% if emailaddress.primary %}primary-email{% endif %}">{{ emailaddress.email }}</span> {% if emailaddress.verified %}
<span class="verified">{% trans "Verified" %}</span>
{% else %}
<small class="text-muted">{% trans "Unverified" %}</small>
{% endif %} {% if emailaddress.primary %}
<small class="text-muted">{% trans "Primary" %}</small>{% endif %}
</label>
</div>

{% endfor %}
<hr>
<div class="buttonHolder">
<button class="btn btn-default" type="submit" name="action_primary">{% trans 'Hacer primario' %}</button>
<button class="btn btn-primary" type="submit" name="action_send">{% trans 'Re-enviar verificación' %}</button>
<button class="btn btn-danger" type="submit" name="action_remove">{% trans 'Remover' %}</button>
</div>
</div>
</form>
<hr>
{% else %}
<p>
<strong>{% trans 'Warning:'%}</strong>{% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}</p>

{% endif %}


<h2>{% trans "Añadir direcciones de email" %}</h2>

<form method="post" action="{% url 'account_email' %}" class="add_email">
{% csrf_token %}
<div class="form-group">
<label for="id_email">E-mail:</label>
<input id="id_email" class="form-control" name="email" size="30" type="text">
</div>
<div class="form-group">
<button name="action_add" class="btn btn-primary" type="submit">{% trans "Añadir email" %}</button>
<a href="{% url 'users:settings' %}" class="btn btn-link">Volver a configuración</a>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %} {% block extra_bottom %}
<script type="text/javascript">
(function() {
var message = "{% trans 'Do you really want to remove the selected e-mail address?' %}";
var actions = document.getElementsByName('action_remove');
if (actions.length) {
actions[0].addEventListener("click", function(e) {
if (!confirm(message)) {
e.preventDefault();
}
});
}
})();
</script>
{% endblock %}
4 changes: 4 additions & 0 deletions templates/account/email/email_confirmation_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with current_site.name as site_name %}User {{ user_display }} at {{ site_name }} has given this as an email address.

To confirm this is correct, go to {{ activate_url }}
{% endblocktrans %}{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "account/email/email_confirmation_message.txt" %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "account/email/email_confirmation_subject.txt" %}
4 changes: 4 additions & 0 deletions templates/account/email/email_confirmation_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Confirm E-mail Address{% endblocktrans %}
{% endautoescape %}
9 changes: 9 additions & 0 deletions templates/account/email/password_reset_key_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% load i18n %}{% blocktrans with site.domain as site_domain and user.username as username %}You're receiving this e-mail because you or someone else has requested a password for your user account at {{site_domain}}.
It can be safely ignored if you did not request a password reset. Click the link below to reset your password.

{{password_reset_url}}

In case you forgot, your username is {{username}}.

Thanks for using our site!
{% endblocktrans %}
4 changes: 4 additions & 0 deletions templates/account/email/password_reset_key_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Password Reset E-mail{% endblocktrans %}
{% endautoescape %}
31 changes: 31 additions & 0 deletions templates/account/email_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "account/base.html" %}
{% load url from future %}
{% load i18n %}
{% load account %}

{% block head_title %}{% trans "Confirm E-mail Address" %}{% endblock %}


{% block content %}
<h1>{% trans "Confirm E-mail Address" %}</h1>

{% if confirmation %}

{% user_display confirmation.email_address.user as user_display %}

<p>{% blocktrans with confirmation.email_address.email as email %}Please confirm that <a href="mailto:{{email}}">{{ email }}</a> is an e-mail address for user {{ user_display }}.{% endblocktrans %}</p>

<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">
{% csrf_token %}
<button type="submit">{% trans 'Confirm' %}</button>
</form>

{% else %}

{% url 'account_email' as email_url %}

<p>{% blocktrans %}This e-mail confirmation link expired or is invalid. Please <a href="{{ email_url}}">issue a new e-mail confirmation request</a>.{% endblocktrans %}</p>

{% endif %}

{% endblock %}
17 changes: 17 additions & 0 deletions templates/account/email_confirmed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "account/base.html" %}

{% load i18n %}
{% load account %}

{% block head_title %}{% trans "Confirm E-mail Address" %}{% endblock %}


{% block content %}

<h1>{% trans "Confirm E-mail Address" %}</h1>

{% user_display email_address.user as user_display %}

<p>{% blocktrans with email_address.email as email %}You have confirmed that <a href="mailto:{{email}}">{{ email }}</a> is an e-mail address for user {{ user_display }}.{% endblocktrans %}</p>

{% endblock %}
Loading

0 comments on commit 721bdd2

Please sign in to comment.