Skip to content

Commit

Permalink
project added
Browse files Browse the repository at this point in the history
  • Loading branch information
KMhook committed Jan 5, 2012
1 parent 0372f74 commit 92913bf
Show file tree
Hide file tree
Showing 527 changed files with 32,917 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
guard 'compass', :configuration_file => 'sass/config.rb' do
watch(%r{sass/.+\.sass})
end

guard 'livereload' do
watch(%r{.+\.html})
watch(%r{assets/css/.+\.css})
end
14 changes: 14 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 部署方法

1. pip install -r requirements.txt 安装依赖的包。
2. 配置数据库(步骤略)
3. python manage.py syncdb
4. python manage.py migrate
5. python manage.py collectstatic
6. 配置 nginx + gunicorn (步骤略)

## 补充说明

1. 本项目的 css 文件全部由 sass 源文件编译生成,如需修改,建议修改 sass 文件后重新编译。
2. Guardfile 文件主要用于 guard-livereload(开发期间使用),部署时不需要用到这个文件。
3. 请保证当前目录以及 uploads/ 目录可写,因为文件上传时会上传到 uploads/。
Empty file added __init__.py
Empty file.
Binary file added assets/images/afterdark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions compilecss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/bash
compass compile -c sass/config.rb
Empty file added contacts/__init__.py
Empty file.
74 changes: 74 additions & 0 deletions contacts/extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# encoding: utf-8
# source: http://github.com/dziegler/excerpt_extractor/tree/master

from BeautifulSoup import BeautifulSoup, Comment, SoupStrainer
import re

CONTACT_INFO_PATTERNS = {
'fullname': (
re.compile(u'姓名[::]?\s*(.*)'),
re.compile(u'全名[::]?\s*(.*)'),
re.compile(r'fullname[:]?\s*(.*)', re.IGNORECASE)
),

'email': (
re.compile(r'([\w\-\.]+@\w[\w\-]+\.+[\w\-]+)'),
),

'phone': (
re.compile(u'电话[::]?\s*(\d+)'),
re.compile(u'手机[::]?\s*(\d+)'),
re.compile(r'phone[::]?\s*(\d+)', re.IGNORECASE),
re.compile(r'mobile[::]?\s*(\d+)', re.IGNORECASE),
),

'qq': (
re.compile(r'qq[::]?\s*(\d+)', re.IGNORECASE),
),
}


def cleanSoup(soup):
# get rid of javascript, noscript and css
[[tree.extract() for tree in soup(elem)] for elem in ('script','noscript','style')]
# get rid of doctype
subtree = soup.findAll(text=re.compile("DOCTYPE"))
[tree.extract() for tree in subtree]
# get rid of comments
comments = soup.findAll(text=lambda text:isinstance(text,Comment))
[comment.extract() for comment in comments]
return soup


def removeHeaders(soup):
[[tree.extract() for tree in soup(elem)] for elem in ('h1','h2','h3','h4','h5','h6')]
return soup


def html2text(content):
soup = removeHeaders(cleanSoup(BeautifulSoup(content, parseOnlyThese=SoupStrainer('body'))))
text = ''.join(soup.findAll(text=True))
return text


def extract_contact_info_from_html(html):
text = html2text(html)
contact = {}

for field, patterns in CONTACT_INFO_PATTERNS.iteritems():
for pattern in patterns:
results = pattern.findall(text)

if len(results) > 0:
contact[field] = results[0]
break

return contact


if __name__ == '__main__':
html = open('./test.html').read()
c = extract_contact_info_from_html(html)

for key, value in c.iteritems():
print('%s: %s' % (key, value))
68 changes: 68 additions & 0 deletions contacts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'Contact'
db.create_table('contacts_contact', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
('html', self.gf('django.db.models.fields.files.FileField')(max_length=100)),
))
db.send_create_signal('contacts', ['Contact'])

def backwards(self, orm):
# Deleting model 'Contact'
db.delete_table('contacts_contact')

models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contacts.contact': {
'Meta': {'object_name': 'Contact'},
'html': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}

complete_apps = ['contacts']
Binary file added contacts/migrations/0001_initial.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'Contact.fullname'
db.add_column('contacts_contact', 'fullname',
self.gf('django.db.models.fields.CharField')(default='', max_length=255),
keep_default=False)

# Adding field 'Contact.email'
db.add_column('contacts_contact', 'email',
self.gf('django.db.models.fields.EmailField')(default='', max_length=75),
keep_default=False)

# Adding field 'Contact.phone'
db.add_column('contacts_contact', 'phone',
self.gf('django.db.models.fields.CharField')(default='', max_length=15),
keep_default=False)

# Adding field 'Contact.qq'
db.add_column('contacts_contact', 'qq',
self.gf('django.db.models.fields.CharField')(default='', max_length=15),
keep_default=False)

def backwards(self, orm):
# Deleting field 'Contact.fullname'
db.delete_column('contacts_contact', 'fullname')

# Deleting field 'Contact.email'
db.delete_column('contacts_contact', 'email')

# Deleting field 'Contact.phone'
db.delete_column('contacts_contact', 'phone')

# Deleting field 'Contact.qq'
db.delete_column('contacts_contact', 'qq')

models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contacts.contact': {
'Meta': {'object_name': 'Contact'},
'email': ('django.db.models.fields.EmailField', [], {'default': "''", 'max_length': '75'}),
'fullname': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
'html': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'phone': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '15'}),
'qq': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '15'}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}

complete_apps = ['contacts']
Binary file not shown.
Empty file added contacts/migrations/__init__.py
Empty file.
Binary file added contacts/migrations/__init__.pyc
Binary file not shown.
42 changes: 42 additions & 0 deletions contacts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# encoding: utf-8

import os
from django.db import models
from django import forms
from django.contrib.auth.models import User
from django.conf import settings

def handle_uploading(instance, filename):
username = instance.user.username
return os.path.join(settings.MEDIA_ROOT, 'contacts', username, 'index.html')


class ContactManager(models.Manager):
def by_user(self, user):
queryset = self.filter(user=user)[:1]

if len(queryset) > 0:
return queryset[0]
else:
return None


class Contact(models.Model):
user = models.OneToOneField(User)
html = models.FileField(upload_to=handle_uploading)
fullname = models.CharField(max_length=255, default='', verbose_name=u'全名')
email = models.EmailField(default='', verbose_name=u'Email')
phone = models.CharField(max_length=15, default='', verbose_name=u'电话号码')
qq = models.CharField(max_length=15, default='', verbose_name=u'QQ 号码')

objects = ContactManager()


class ContactUploadForm(forms.Form):
html = forms.FileField(label=u'个人页面 HTML 文件')


class ContactEditForm(forms.ModelForm):
class Meta:
model = Contact
fields = ('fullname', 'email', 'phone', 'qq')
11 changes: 11 additions & 0 deletions contacts/templates/contacts/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'layout.html' %}

{% block page_title %}更新个人资料{% endblock %}
{% block current_tab %}contacts{% endblock %}

{% block main %}
<form action="{% url contacts_edit %}" method="post">
{% include 'form.html' %}
<input type="submit" value="保存" />
</form>
{% endblock main %}
31 changes: 31 additions & 0 deletions contacts/templates/contacts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends 'layout.html' %}

{% block page_title %}实验室通讯录{% endblock %}
{% block body_class %}contacts{% endblock %}
{% block current_tab %}contacts{% endblock %}

{% block main %}
<table id="contacts">
<thead>
<th>姓名</th>
<th>Email</th>
<th>电话号码</th>
<th>QQ</th>
<th></th>
</thead>

<tbody>
{% for contact in contacts %}
<tr>
<td>{{ contact.fullname|default:"暂无" }}</td>
<td>{{ contact.email|default:"暂无" }}</td>
<td>{{ contact.phone|default:"暂无" }}</td>
<td>{{ contact.qq|default:"暂无" }}</td>
<td>
<a href="{% url contacts_show contact.user.username %}">查看</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock main %}
26 changes: 26 additions & 0 deletions contacts/templates/contacts/me.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends 'layout.html' %}

{% block page_title %}个人资料{% endblock %}
{% block body_class %}contacts-me{% endblock %}
{% block current_tab %}profile{% endblock %}

{% block main %}
<h2>个人资料</h2>
<dl>
<dt>姓名</dt>
<dd>{{ contact.fullname|default:"暂无" }}</dd>
<dt>Email</dt>
<dd>{{ contact.email|default:"暂无" }}</dd>
<dt>电话号码</dt>
<dd>{{ contact.phone|default:"暂无" }}</dd>
<dt>QQ</dt>
<dd>{{ contact.qq|default:"暂无" }}</dd>
</dl>

<div class="clear"></div>

<p id="actions">
<a href="{% url contacts_upload %}">上传个人页面</a>
<a href="{% url contacts_edit %}">编辑个人资料</a>
</p>
{% endblock main %}
11 changes: 11 additions & 0 deletions contacts/templates/contacts/upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'layout.html' %}

{% block page_title %}上传个人资料{% endblock %}
{% block current_tab %}contacts{% endblock %}

{% block main %}
<form action="{% url contacts_upload %}" method="post" enctype="multipart/form-data">
{% include 'form.html' %}
<input type="submit" value="上传" />
</form>
{% endblock main %}
Loading

0 comments on commit 92913bf

Please sign in to comment.