-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
from flask import render_template | ||
from flask import render_template, abort | ||
from . import main | ||
from ..models import User | ||
|
||
|
||
@main.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
|
||
@main.route('/user/<username>') | ||
def user(username): | ||
user = User.query.filter_by(username=username).first_or_404() | ||
return render_template('user.html', user=user) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from datetime import datetime | ||
from werkzeug.security import generate_password_hash, check_password_hash | ||
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer | ||
from flask import current_app | ||
|
@@ -74,6 +75,11 @@ class User(UserMixin, db.Model): | |
role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) | ||
password_hash = db.Column(db.String(128)) | ||
confirmed = db.Column(db.Boolean, default=False) | ||
name = db.Column(db.String(64)) | ||
location = db.Column(db.String(64)) | ||
about_me = db.Column(db.Text()) | ||
member_since = db.Column(db.DateTime(), default=datetime.utcnow) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
miguelgrinberg
Author
Owner
|
||
last_seen = db.Column(db.DateTime(), default=datetime.utcnow) | ||
|
||
def __init__(self, **kwargs): | ||
super(User, self).__init__(**kwargs) | ||
|
@@ -156,6 +162,10 @@ def can(self, perm): | |
def is_administrator(self): | ||
return self.can(Permission.ADMIN) | ||
|
||
def ping(self): | ||
self.last_seen = datetime.utcnow() | ||
db.session.add(self) | ||
This comment has been minimized.
Sorry, something went wrong.
rocadev
|
||
|
||
def __repr__(self): | ||
return '<User %r>' % self.username | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Flasky - {{ user.username }}{% endblock %} | ||
|
||
{% block page_content %} | ||
<div class="page-header"> | ||
<h1>{{ user.username }}</h1> | ||
{% if user.name or user.location %} | ||
<p> | ||
{% if user.name %}{{ user.name }}{% endif %} | ||
{% if user.location %} | ||
from <a href="http://maps.google.com/?q={{ user.location }}">{{ user.location }}</a> | ||
{% endif %} | ||
</p> | ||
{% endif %} | ||
{% if current_user.is_administrator() %} | ||
<p><a href="mailto:{{ user.email }}">{{ user.email }}</a></p> | ||
{% endif %} | ||
{% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %} | ||
<p>Member since {{ moment(user.member_since).format('L') }}. Last seen {{ moment(user.last_seen).fromNow() }}.</p> | ||
</div> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""user information | ||
Revision ID: d66f086b258 | ||
Revises: 56ed7d33de8d | ||
Create Date: 2013-12-29 23:50:49.566954 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'd66f086b258' | ||
down_revision = '56ed7d33de8d' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('users', sa.Column('about_me', sa.Text(), nullable=True)) | ||
op.add_column('users', sa.Column('last_seen', sa.DateTime(), nullable=True)) | ||
op.add_column('users', sa.Column('location', sa.String(length=64), nullable=True)) | ||
op.add_column('users', sa.Column('member_since', sa.DateTime(), nullable=True)) | ||
op.add_column('users', sa.Column('name', sa.String(length=64), nullable=True)) | ||
### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('users', 'name') | ||
op.drop_column('users', 'member_since') | ||
op.drop_column('users', 'location') | ||
op.drop_column('users', 'last_seen') | ||
op.drop_column('users', 'about_me') | ||
### end Alembic commands ### |
I have had to gone back twice to double-check that I didn't miss out on anything. I noticed that the member_since attribute on the user profile always default to the current date. I was wondering if we could have somehow instead stored the datetime of user account creation and then retrieved this for the user profile view?