Added:
trunk/misc/patrick/pytranslate/
trunk/misc/patrick/pytranslate/.hgignore (contents, props changed)
trunk/misc/patrick/pytranslate/__init__.py
trunk/misc/patrick/pytranslate/manage.py
trunk/misc/patrick/pytranslate/screenshot.jpg (contents, props changed)
trunk/misc/patrick/pytranslate/settings.py
trunk/misc/patrick/pytranslate/templates/
trunk/misc/patrick/pytranslate/templates/main_page.html
trunk/misc/patrick/pytranslate/translate/
trunk/misc/patrick/pytranslate/translate/__init__.py
trunk/misc/patrick/pytranslate/translate/forms.py
trunk/misc/patrick/pytranslate/translate/models.py
trunk/misc/patrick/pytranslate/translate/monty_process.py (contents,
props changed)
trunk/misc/patrick/pytranslate/translate/views.py (contents, props
changed)
trunk/misc/patrick/pytranslate/urls.py
Modified:
trunk/misc/patrick/django_bookmarks/bookmarks/forms.py
trunk/misc/patrick/django_bookmarks/bookmarks/models.py
trunk/misc/patrick/django_bookmarks/bookmarks/views.py
trunk/misc/patrick/django_bookmarks/settings.py
trunk/misc/patrick/django_bookmarks/site_media/search.js
trunk/misc/patrick/django_bookmarks/site_media/style.css
trunk/misc/patrick/django_bookmarks/sqlite3
trunk/misc/patrick/django_bookmarks/templates/bookmark_list.html
trunk/misc/patrick/django_bookmarks/templates/bookmark_save.html
trunk/misc/patrick/django_bookmarks/templates/main_page.html
trunk/misc/patrick/django_bookmarks/templates/user_page.html
trunk/misc/patrick/django_bookmarks/urls.py
trunk/misc/patrick/wjContact/computers/models.py
trunk/misc/patrick/wjContact/contacts/models.py
trunk/misc/patrick/wjContact/patrick_local_settings.py
trunk/misc/patrick/wjContact/settings.py
Log:
translate program for maurice
Modified: trunk/misc/patrick/django_bookmarks/bookmarks/forms.py
==============================================================================
--- trunk/misc/patrick/django_bookmarks/bookmarks/forms.py (original)
+++ trunk/misc/patrick/django_bookmarks/bookmarks/forms.py Sun Jun 28
21:58:40 2009
@@ -6,6 +6,7 @@
url = forms.URLField(label=u'URL',
widget=forms.TextInput(attrs={'size': 64}))
tags = forms.CharField(label=u'Tags', required=False,
widget=forms.TextInput(attrs={'size': 64}))
title = forms.CharField(label=u'Title',
widget=forms.TextInput(attrs={'size': 64}))
+ share = forms.BooleanField(label=u'Share on the main page',
required=False)
class RegistrationForm(forms.Form):
username = forms.CharField(label=u'Username', max_length=30)
Modified: trunk/misc/patrick/django_bookmarks/bookmarks/models.py
==============================================================================
--- trunk/misc/patrick/django_bookmarks/bookmarks/models.py (original)
+++ trunk/misc/patrick/django_bookmarks/bookmarks/models.py Sun Jun 28
21:58:40 2009
@@ -17,8 +17,30 @@
def __unicode__(self):
return u'%s %s'% (self.user.username, self.link.url)
+ def get_absolute_url(self):
+ return self.link.url
+
class Tag(models.Model):
name = models.CharField(max_length=64, unique=True)
bookmarks = models.ManyToManyField(Bookmark)
def __unicode__(self):
return self.name
+
+class SharedBookmark(models.Model):
+ bookmark = models.ForeignKey(Bookmark, unique=True)
+ date = models.DateTimeField(auto_now_add=True)
+ votes = models.IntegerField(default=1)
+ users_voted = models.ManyToManyField(User)
+
+ def __unicode__(self):
+ return u'%s, %s' % (self.bookmark, self.votes)
+
+class Friendship(models.Model):
+ from_friend = models.ForeignKey( User, related_name='friend_set')
+ to_friend = models.ForeignKey( User, related_name='to_friend_set')
+
+ def __unicode__(self):
+ return u'%s, %s' % (self.from_friend.username,
self.to_friend.username)
+
+ class Meta:
+ unique_together = (('to_friend', 'from_friend'), )
Modified: trunk/misc/patrick/django_bookmarks/bookmarks/views.py
==============================================================================
--- trunk/misc/patrick/django_bookmarks/bookmarks/views.py (original)
+++ trunk/misc/patrick/django_bookmarks/bookmarks/views.py Sun Jun 28
21:58:40 2009
@@ -1,3 +1,5 @@
+from datetime import datetime, timedelta
+
from django.http import HttpResponse, Http404
from django.contrib.auth.models import User
from django.template import Context
@@ -8,10 +10,14 @@
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
+from django.db.models import Q
+from django.core.paginator import Paginator, InvalidPage
+ITEMS_PER_PAGE = 10
from bookmarks.forms import *
from bookmarks.models import *
+
"""
def main_page(request):
output = '''
@@ -41,9 +47,15 @@
return HttpResponse(output)
"""
+"""
def main_page(request):
return render_to_response( 'main_page.html', RequestContext(request))
+"""
+def main_page(request):
+ shared_bookmarks = SharedBookmark.objects.order_by('-date')[:10]
+ variables = RequestContext(request, { 'shared_bookmarks':
shared_bookmarks} )
+ return render_to_response( 'main_page.html', variables)
"""
def user_page(request, username):
@@ -76,6 +88,41 @@
'show_edit': username == request.user.username,
})
return render_to_response('user_page.html', variables)
+def user_page(request, username):
+ """Has pagination too"""
+ #user = User.objects.get(username=username)
+ user = get_object_or_404(User, username=username)
+
+ query_set = user.bookmark_set.order_by('-id')
+ paginator = Paginator(query_set, ITEMS_PER_PAGE)
+ is_friend = Friendship.objects.filter(
+ from_friend = request.user,
+ to_friend = user)
+ try:
+ page_number = int(request.GET['page'])
+ except (KeyError, ValueError):
+ page_number = 1
+ try:
+ page = paginator.page(page_number)
+ except InvalidPage:
+ raise Http404
+ bookmarks = page.object_list
+
+ variables = RequestContext(request, {
+ 'username': username,
+ 'bookmarks': bookmarks,
+ 'show_tags': True,
+ 'show_edit': username == request.user.username,
+ 'show_paginator': paginator.num_pages > 1,
+ 'has_prev': page.has_previous(),
+ 'has_next': page.has_next(),
+ 'page': page_number,
+ 'pages': paginator.num_pages,
+ 'next_page': page_number + 1,
+ 'prev_page': page_number - 1,
+ 'is_friend': is_friend,
+ })
+ return render_to_response('user_page.html', variables)
def logout_page(request):
logout(request)
@@ -87,7 +134,7 @@
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
- password=form.cleaned_data['password'],
+ password=form.cleaned_data['password1'],
email=form.cleaned_data['email']
)
return HttpResponseRedirect('/register/success/')
@@ -97,12 +144,44 @@
return render_to_response( 'registration/register.html', variables)
@login_required
+def bookmark_vote_page(request):
+ if 'id' in request.GET:
+ try:
+ id = request.GET['id']
+ shared_bookmark = SharedBookmark.objects.get(id=id)
+ user_voted = shared_bookmark.users_voted.filter(
+ username=request.user.username
+ )
+ if not user_voted:
+ shared_bookmark.votes += 1
+ shared_bookmark.users_voted.add(request.user)
+ shared_bookmark.save()
+ except SharedBookmark.DoesNotExist:
+ raise Http404('Bookmark not found.')
+ if 'HTTP_REFERER' in request.META:
+ return HttpResponseRedirect(request.META['HTTP_REFERER'])
+ return HttpResponseRedirect('/')
+
+@login_required
def bookmark_save_page(request):
+ ajax = 'ajax' in request.GET
+
if request.method == 'POST':
form = BookmarkSaveForm(request.POST)
if form.is_valid():
bookmark = _bookmark_save(request, form)
- return HttpResponseRedirect( '/user/%s/' %
request.user.username)
+ if ajax:
+ variables = RequestContext(request, {
+ 'bookmarks': [bookmark],
+ 'show_edit': True,
+ 'show_tags': True,
+ })
+ return render_to_response('bookmark_list.html', variables)
+ else:
+ return HttpResponseRedirect('/user/%s/' %
request.user.username)
+ else:
+ if ajax:
+ return HttpResponse(u'failure')
elif 'url' in request.GET:
url = request.GET['url']
title = ''
@@ -121,8 +200,14 @@
else:
form = BookmarkSaveForm()
- variables = RequestContext(request, { 'form': form, })
- return render_to_response('bookmark_save.html', variables)
+ variables = RequestContext(request, {
+ 'form': form
+ })
+ if ajax:
+ return render_to_response('bookmark_save_form.html', variables)
+ else:
+ #variables = RequestContext(request, { 'form': form, })
+ return render_to_response('bookmark_save.html', variables)
def _bookmark_save(request, form):
# Create or get link.
@@ -146,10 +231,29 @@
tag, dummy = Tag.objects.get_or_create(name=tag_name)
bookmark.tag_set.add(tag)
+ #s Share on the main page if requested
+ if form.cleaned_data['share']:
+ shared, created = SharedBookmark.objects.get_or_create(
bookmark=bookmark )
+ if created:
+ shared.users_voted.add(request.user)
+ shared.save()
+
# Save bookmark to database.
bookmark.save()
return bookmark
+def bookmark_page(request, bookmark_id):
+ shared_bookmark = get_object_or_404(
+ SharedBookmark,
+ id=bookmark_id
+ )
+ variables = RequestContext(request,
+ {
+ 'shared_bookmark': shared_bookmark
+ })
+ return render_to_response('bookmark_page.html', variables)
+
+
def tag_page(request, tag_name):
tag = get_object_or_404(Tag, name=tag_name)
bookmarks = tag.bookmarks.order_by('-id')
@@ -190,8 +294,16 @@
show_results = True
query = request.GET['query'].strip()
if query:
- form = SearchForm( {'query':query})
- bookmarks =
Bookmark.objects.filter(title__icontains=query)[:10]
+ #form = SearchForm( {'query':query})
+ #bookmarks =
Bookmark.objects.filter(title__icontains=query)[:10]
+ keywords = query.split()
+ q = Q()
+ for keyword in keywords:
+ q = q & Q(title__icontains=keyword)
+ form=SearchForm( {'query' : query})
+ bookmarks = Bookmark.objects.filter(q)[:10]
+
+
variables = RequestContext(request, {
'form': form,
'bookmarks': bookmarks,
@@ -204,3 +316,35 @@
else:
return render_to_response('search.html', variables)
+def popular_page(request):
+ today = datetime.today()
+ yesterday = today - timedelta(1)
+ shared_bookmarks = SharedBookmark.objects.filter( date__gt = yesterday
)
+ shared_bookmarks = shared_bookmarks.order_by ( '-votes' )[:10]
+ variables = RequestContext(request, { 'shared_bookmarks':
shared_bookmarks })
+ return render_to_response('popular_page.html', variables)
+
+def friends_page(request, username):
+ user = get_object_or_404(User, username=username)
+ friends = [ friendship.to_friend for friendship in
user.friend_set.all() ]
+ friend_bookmarks = Bookmark.objects.filter( user__in =
friends).order_by('-id')
+ variables = RequestContext(request, {
+ 'username' : username,
+ 'friends' : friends,
+ 'bookmarks': friend_bookmarks[:10],
+ 'show_tags': True,
+ 'show_user': True
+ })
+ return render_to_response('friends_page.html', variables)
+
+@login_required
+def friend_add(request):
+ if 'username' in request.GET:
+ friend = get_object_or_404( User, username=request.GET['username'])
+ friendship = Friendship(
+ from_friend=request.user,
+ to_friend=friend)
+ friendship.save()
+ return HttpResponseRedirect( '/friends/%s/' %
request.user.username)
+ else:
+ raise Http404
Modified: trunk/misc/patrick/django_bookmarks/settings.py
==============================================================================
--- trunk/misc/patrick/django_bookmarks/settings.py (original)
+++ trunk/misc/patrick/django_bookmarks/settings.py Sun Jun 28 21:58:40 2009
@@ -79,6 +79,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
+ 'django.contrib.comments',
'django_bookmarks.bookmarks',
#'django_extensions.graph_models',
'django_extensions',
Modified: trunk/misc/patrick/django_bookmarks/site_media/search.js
==============================================================================
--- trunk/misc/patrick/django_bookmarks/site_media/search.js (original)
+++ trunk/misc/patrick/django_bookmarks/site_media/search.js Sun Jun 28
21:58:40 2009
@@ -1,5 +1,4 @@
-function search_submit()
-{
+function search_submit() {
var query = $("#id_query").val();
$("#search-results").load(
"/search/?ajax&query=" + encodeURIComponent(query)
@@ -7,7 +6,6 @@
return false;
}
-$(document).ready(function()
-{
+$(document).ready(function() {
$("#search-form").submit(search_submit);
});
Modified: trunk/misc/patrick/django_bookmarks/site_media/style.css
==============================================================================
--- trunk/misc/patrick/django_bookmarks/site_media/style.css (original)
+++ trunk/misc/patrick/django_bookmarks/site_media/style.css Sun Jun 28
21:58:40 2009
@@ -25,9 +25,17 @@
.tag-cloud-4 { font-size: 180%; }
.tag-cloud-5 { font-size: 200%; }
-ul.bookmarks .edit
-{
+ul.bookmarks .edit {
font-size: 70%;
}
+
+textarea {
+ display: block;
+}
+.comment {
+ margin: 1em;
+ padding: 5px;
+ border: 1px solid #000;
+}
Modified: trunk/misc/patrick/django_bookmarks/sqlite3
==============================================================================
Binary files. No diff available.
Modified: trunk/misc/patrick/django_bookmarks/templates/bookmark_list.html
==============================================================================
--- trunk/misc/patrick/django_bookmarks/templates/bookmark_list.html
(original)
+++ trunk/misc/patrick/django_bookmarks/templates/bookmark_list.html Sun
Jun 28 21:58:40 2009
@@ -29,6 +29,20 @@
</li>
{% endfor %}
</ul>
+
+ {% if show_paginator %}
+ <div class="paginator">
+ {% if has_prev %}
+ <a href="?page={{ prev_page }}">« Previous</a>
+ {% endif %}
+ {% if has_next %}
+ <a href="?page={{ next_page }}">Next »</a>
+ {% endif %}
+ (Page {{ page }} of {{ pages }})
+ </div>
+ {% endif %}
+
+
{% else %}
<p>No bookmarks found.</p>
{% endif %}
Modified: trunk/misc/patrick/django_bookmarks/templates/bookmark_save.html
==============================================================================
--- trunk/misc/patrick/django_bookmarks/templates/bookmark_save.html
(original)
+++ trunk/misc/patrick/django_bookmarks/templates/bookmark_save.html Sun
Jun 28 21:58:40 2009
@@ -2,8 +2,5 @@
{% block title %}Save Bookmark{% endblock %}
{% block head %}Save Bookmark{% endblock %}
{% block content %}
-<form method="post" action=".">
- {{ form.as_p }}
- <input type="submit" value="save" />
-</form>
+ {% include "bookmark_save_form.html" %}
{% endblock %}
Modified: trunk/misc/patrick/django_bookmarks/templates/main_page.html
==============================================================================
--- trunk/misc/patrick/django_bookmarks/templates/main_page.html (original)
+++ trunk/misc/patrick/django_bookmarks/templates/main_page.html Sun Jun 28
21:58:40 2009
@@ -1,6 +1,13 @@
{% extends "base.html" %}
{% block title %}Welcome to Django Bookmarks{% endblock %}
{% block head %}Welcome to Django Bookmarks{% endblock %}
+
+{% block external %}
+ <link rel="alternate" type="application/rss+xml"
+ title="Django Bookmarks | Recent Bookmarks"
+ href="/feeds/recent/" />
+{% endblock %}
+
{% block content %}
{% if user.username %}
<p>Welcome {{ user.username }}!
@@ -10,4 +17,7 @@
You need to <a href="/login/">login</a>
before you can store and share bookmarks.</p>
{% endif %}
+ <h2> Bookmarks Shared by Users </h2>
+ {% include "shared_bookmark_list.html" %}
+
{% endblock %}
Modified: trunk/misc/patrick/django_bookmarks/templates/user_page.html
==============================================================================
--- trunk/misc/patrick/django_bookmarks/templates/user_page.html (original)
+++ trunk/misc/patrick/django_bookmarks/templates/user_page.html Sun Jun 28
21:58:40 2009
@@ -1,6 +1,24 @@
{% extends "base.html" %}
+{% block external %}
+ <script type="text/javascript"
src="/site_media/bookmark_edit.js"></script>
+ <link rel="alternate" type="application/rss+xml"
+ title="Django Bookmarks | Bookmarks for {{ username }}"
+ href="/feeds/user/{{ username }}" />
+{% endblock %}
{% block title %}{{ username }}{% endblock %}
{% block head %}Bookmarks for {{ username }}{% endblock %}
+
{% block content %}
+ {% ifequal user.username username %}
+ <a href="/friends/{{ username }}/">view your friends</a>
+ {% else %}
+ {% if is_friend %}
+ <a href="/friends/{{ user.username }}/"> {{ username }} is a friend
of yours</a>
+ {% else %}
+ <a href="/friend/add/?username={{ username }}"> add {{ username }}
to your friends</a>
+ {% endif %}
+ - <a href="/friends/{{ username }}/"> view {{username }}'s friends</a>
+ {% endifequal %}
+
{% include "bookmark_list.html" %}
{% endblock %}
Modified: trunk/misc/patrick/django_bookmarks/urls.py
==============================================================================
--- trunk/misc/patrick/django_bookmarks/urls.py (original)
+++ trunk/misc/patrick/django_bookmarks/urls.py Sun Jun 28 21:58:40 2009
@@ -4,10 +4,17 @@
from bookmarks.views import *
+from bookmarks.feeds import *
site_media = os.path.join(os.path.dirname(__file__), 'site_media')
+feeds = {
+ 'recent': RecentBookmarks,
+ 'user': UserBookmarks,
+}
+
+
# Uncomment the next two lines to enable the admin
from django.contrib import admin
@@ -33,6 +40,12 @@
(r'^tag/$', tag_cloud_page),
(r'^user/(\w+)/$', user_page),
(r'^search/$', search_page),
+ (r'^bookmark/(\d+)/$', bookmark_page),
+ (r'^popular/$', popular_page),
+
+ # Friends
+ (r'^friends/(\w+)/$', friends_page),
+ (r'^friend/add/$', friend_add),
#session management
(r'^login/$', 'django.contrib.auth.views.login'),
@@ -42,9 +55,19 @@
#account management
(r'^save/$', bookmark_save_page),
+ (r'^vote/$', bookmark_vote_page),
+
+ # Comments
+ (r'^comments/', include('django.contrib.comments.urls')),
+ #
+
+ # Feeds
+ (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
{ 'feed_dict': feeds }),
+
+
#sitemedia
- (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': site_media}),
+ #(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': site_media}),
(r'^admin/(.*)', admin.site.root),
)
Added: trunk/misc/patrick/pytranslate/.hgignore
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/.hgignore Sun Jun 28 21:58:40 2009
@@ -0,0 +1,15 @@
+# use glob syntax.
+syntax: glob
+
+*.a
+*.o
+*.py[co]
+*.so
+*.sw[nop]
+*~
+.#*
+[#]*#
+
+# switch to regexp syntax.
+syntax: regexp
+^\.pc/
Added: trunk/misc/patrick/pytranslate/__init__.py
==============================================================================
Added: trunk/misc/patrick/pytranslate/manage.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/manage.py Sun Jun 28 21:58:40 2009
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+ import settings # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the
directory containing %r. It appears you've customized things.\nYou'll have
to run django-admin.py, passing it your settings module.\n(If the file
settings.py does indeed exist, it's causing an ImportError somehow.)\n" %
__file__)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
Added: trunk/misc/patrick/pytranslate/screenshot.jpg
==============================================================================
Binary file. No diff available.
Added: trunk/misc/patrick/pytranslate/settings.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/settings.py Sun Jun 28 21:58:40 2009
@@ -0,0 +1,82 @@
+# Django settings for pytranslate project.
+import os
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_...@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = ''
# 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = '' # Or path to database file if using sqlite3.
+DATABASE_USER = '' # Not used with sqlite3.
+DATABASE_PASSWORD = '' # Not used with sqlite3.
+DATABASE_HOST = '' # Set to empty string for localhost. Not
used with sqlite3.
+DATABASE_PORT = '' # Set to empty string for default. Not used
with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to
use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'b%@8z!$0x_ei@d#=3f1syq(74@+q8hxgq1&mcq%m!wxejm3&xh'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.load_template_source',
+ 'django.template.loaders.app_directories.load_template_source',
+# 'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+ROOT_URLCONF = 'pytranslate.urls'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates"
or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+
+ os.path.join(os.path.dirname(__file__), 'templates')
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+)
Added: trunk/misc/patrick/pytranslate/templates/main_page.html
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/templates/main_page.html Sun Jun 28
21:58:40 2009
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>Pytranslate</title>
+ </head>
+
+ <body>
+ <form method="post" action=".">
+ {{ form.inputtext }}
+ <input type="submit" value="submit" />
+ </form>
+
+ <h2> List of sentences </h2>
+ {% for sentence in output_sentences %}
+ <li> {{ sentence }} </li>
+ {% endfor %}
+
+
+ <h2> List of words tagged with Penn Treebank Tagset </h2>
+ {% for token in output_tags %}
+ <li> {{ token }} </li>
+ {% endfor %}
+ </body>
+</html>
Added: trunk/misc/patrick/pytranslate/translate/__init__.py
==============================================================================
Added: trunk/misc/patrick/pytranslate/translate/forms.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/translate/forms.py Sun Jun 28 21:58:40
2009
@@ -0,0 +1,27 @@
+import re
+from django.contrib.auth.models import User
+from django import forms
+
+class InputForm(forms.Form):
+ inputtext = forms.CharField(label=u'Inputtext', max_length=9000,
widget=forms.Textarea)
+
+ """
+ def clean_password2(self):
+ if 'password1' in self.cleaned_data:
+ password1 = self.cleaned_data['password1']
+ password2 = self.cleaned_data['password2']
+ if password1 == password2:
+ return password2
+ raise forms.ValidationError('Passwords do not match.')
+
+ def clean_username(self):
+ username = self.cleaned_data['username']
+ if not re.search(r'^\w+$', username):
+ raise forms.ValidationError('Username can only contain '
+ 'alphanumeric characters and the underscore.')
+ try:
+ User.objects.get(username=username)
+ except User.DoesNotExist:
+ return username
+ raise forms.ValidationError('Username is already taken.')
+ """
Added: trunk/misc/patrick/pytranslate/translate/models.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/translate/models.py Sun Jun 28 21:58:40
2009
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
Added: trunk/misc/patrick/pytranslate/translate/monty_process.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/translate/monty_process.py Sun Jun 28
21:58:40 2009
@@ -0,0 +1,21 @@
+import montylingua3
+import string
+
+global m #a monty lingua instance.
+m = montylingua3.MontyLingua() #we only have to instantiate it once
(...takes around 5 secs!)
+
+
+def process_text(inputtext):
+ """Given an input text, returns a sentence and tagged sentence tuple
using monty lingua"""
+ global m
+
+ sentences = m.split_sentences(inputtext)
+ tokenized = map(m.tokenize,sentences)
+ tagged = map(m.tag_tokenized,tokenized)
+
+ #print "tagged: " + string.join(tagged,'\n ')
+ #chunked = map(m.chunk_tagged,tagged)
+ #print "CHUNKED: " + string.join(chunked,'\n ')
+ #extracted = map(m.extract_info,chunked)
+
+ return [sentences, tagged]
Added: trunk/misc/patrick/pytranslate/translate/views.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/translate/views.py Sun Jun 28 21:58:40
2009
@@ -0,0 +1,39 @@
+# Create your views here.
+from translate.forms import *
+
+
+from django.http import HttpResponse
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
+
+
+import monty_process
+import string
+import unicodedata
+
+
+def main_page(request):
+
+
+
+ output_sentences = []
+ output_tags = []
+
+ if request.method == 'POST':
+ form = InputForm(request.POST)
+ if form.is_valid():
+ inputtext=form.cleaned_data['inputtext']
+
+ [output_sentences, output_tags] =
monty_process.process_text(inputtext)
+
+ else:
+ form = InputForm()
+
+ variables = RequestContext(request, {
+ 'form': form,
+ 'output_sentences': output_sentences,
+ 'output_tags': output_tags,
+ })
+ return render_to_response( 'main_page.html', variables)
+
Added: trunk/misc/patrick/pytranslate/urls.py
==============================================================================
--- (empty file)
+++ trunk/misc/patrick/pytranslate/urls.py Sun Jun 28 21:58:40 2009
@@ -0,0 +1,23 @@
+from django.conf.urls.defaults import *
+from translate.views import *
+
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+ # Example:
+ # (r'^pytranslate/', include('pytranslate.foo.urls')),
+
+ (r'^$', main_page),
+
+
+ # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
+ # to INSTALLED_APPS to enable admin documentation:
+ # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ #Uncomment the next line to enable the admin:
+ #(r'^admin/(.*)', admin.site.root),
+
+)
Modified: trunk/misc/patrick/wjContact/computers/models.py
==============================================================================
--- trunk/misc/patrick/wjContact/computers/models.py (original)
+++ trunk/misc/patrick/wjContact/computers/models.py Sun Jun 28 21:58:40
2009
@@ -81,20 +81,20 @@
('testing', 'Being Tested'),
)
cbv_no = models.AutoField(primary_key=True)
- cpu_type = models.CharField(maxlength=3, choices = CPU_TYPES)
- cpu_speed = models.CharField(maxlength=4, choices = CPU_SPEEDS)
- case_type = models.CharField(maxlength=6, choices = CASE_TYPES)
- ram = models.CharField(maxlength=3, choices = RAM_AMOUNTS)
- hard_drive_size = models.CharField(maxlength=3, choices =
HARD_DRIVE_SIZES)
- optical_device1 = models.CharField(maxlength=50)
- optical_device2 = models.CharField(maxlength=50)
- monitor_type = models.CharField(maxlength=50)
- monitor_size = models.CharField(maxlength=50)
- modem_type = models.CharField(maxlength=50)
- usb = models.CharField(maxlength=50)
- usb_ports = models.CharField(maxlength=50)
- distroversion = models.CharField(maxlength=50)
- computer_status = models.CharField(maxlength=12, choices =
STATUS_CHOICES,
+ cpu_type = models.CharField(max_length=3, choices = CPU_TYPES)
+ cpu_speed = models.CharField(max_length=4, choices = CPU_SPEEDS)
+ case_type = models.CharField(max_length=6, choices = CASE_TYPES)
+ ram = models.CharField(max_length=3, choices = RAM_AMOUNTS)
+ hard_drive_size = models.CharField(max_length=3, choices =
HARD_DRIVE_SIZES)
+ optical_device1 = models.CharField(max_length=50)
+ optical_device2 = models.CharField(max_length=50)
+ monitor_type = models.CharField(max_length=50)
+ monitor_size = models.CharField(max_length=50)
+ modem_type = models.CharField(max_length=50)
+ usb = models.CharField(max_length=50)
+ usb_ports = models.CharField(max_length=50)
+ distroversion = models.CharField(max_length=50)
+ computer_status = models.CharField(max_length=12, choices =
STATUS_CHOICES,
default = "in_shop")
def __str__(self):
@@ -113,26 +113,26 @@
## can be flagged as basic, standard, or upgrade.
##class ComputerType(models.Model):
## computer_type_id = models.AutoField(primary_key=True)
-## cpu_type = models.CharField(maxlength=50)
-## cpu_speed = models.CharField(maxlength=50)
-## case_type = models.CharField(maxlength=50)
-## ram = models.CharField(maxlength=50)
-## hard_drive_size = models.CharField(maxlength=50)
-## optical_device1 = models.CharField(maxlength=50)
-## optical_device2 = models.CharField(maxlength=50)
-##
-## monitor_type = models.CharField(maxlength=50)
-## monitor_size = models.CharField(maxlength=50)
-##
-## modem_type = models.CharField(maxlength=50)
-## usb = models.CharField(maxlength=50)
-## usb_ports = models.CharField(maxlength=50)
+## cpu_type = models.CharField(max_length=50)
+## cpu_speed = models.CharField(max_length=50)
+## case_type = models.CharField(max_length=50)
+## ram = models.CharField(max_length=50)
+## hard_drive_size = models.CharField(max_length=50)
+## optical_device1 = models.CharField(max_length=50)
+## optical_device2 = models.CharField(max_length=50)
+##
+## monitor_type = models.CharField(max_length=50)
+## monitor_size = models.CharField(max_length=50)
+##
+## modem_type = models.CharField(max_length=50)
+## usb = models.CharField(max_length=50)
+## usb_ports = models.CharField(max_length=50)
##
##
##
-## distroversion = models.CharField(maxlength=50)
-## computer_status = models.CharField(maxlength=50)
-## computer_description = models.CharField(maxlength=50)#not in final
version
+## distroversion = models.CharField(max_length=50)
+## computer_status = models.CharField(max_length=50)
+## computer_description = models.CharField(max_length=50)#not in final
version
## def __str__(self):
## return self.computer_description
## # Give the computer_class model an "Admin Interface" so that staff
users
@@ -144,10 +144,10 @@
##class ActualComputer(models.Model):
## cbvid = models.AutoField(primary_key=True)
## computer_type = models.ForeignKey(ComputerType)
-## status = models.CharField(maxlength=50)
-## description = models.CharField(maxlength=50)#not in final version
-## user_pwd = models.CharField(maxlength=50, default = 'cbvsys')
-## dialup_pwd = models.CharField(maxlength=50)
+## status = models.CharField(max_length=50)
+## description = models.CharField(max_length=50)#not in final version
+## user_pwd = models.CharField(max_length=50, default = 'cbvsys')
+## dialup_pwd = models.CharField(max_length=50)
## qa_date = models.DateTimeField()
## from wjContact.contacts.models import Contact
## qa_by = models.ForeignKey(Contact)
@@ -162,12 +162,12 @@
## Lists the components that go into a computer or class of computer
##class Component(models.Model):
## component_id = models.AutoField(primary_key=True)
-## componentclass = models.CharField(maxlength=50)
-## componenttype = models.CharField(maxlength=50)
-## component_price = models.CharField(maxlength=50)
+## componentclass = models.CharField(max_length=50)
+## componenttype = models.CharField(max_length=50)
+## component_price = models.CharField(max_length=50)
## def __str__(self):
## return self.componenttype
## # Give the computer_components model an "Admin Interface" so that
staff users
## # can add new computer components if they wish.
## class Admin:
-## pass
\ No newline at end of file
+## pass
Modified: trunk/misc/patrick/wjContact/contacts/models.py
==============================================================================
--- trunk/misc/patrick/wjContact/contacts/models.py (original)
+++ trunk/misc/patrick/wjContact/contacts/models.py Sun Jun 28 21:58:40 2009
@@ -4,12 +4,12 @@
class Contact(models.Model):
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=20)
- address = models.CharField(maxlength=200)
- postcode = models.CharField(maxlength=40)
- state = models.USStateField()
- country = models.CharField(maxlength=40)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=20)
+ address = models.CharField(max_length=200)
+ postcode = models.CharField(max_length=40)
+ state = models.CharField(max_length=40)
+ country = models.CharField(max_length=40)
email = models.EmailField()
date_added = models.DateTimeField()
def __str__(self):
@@ -130,25 +130,25 @@
('linux', 'Linux'),
('windows', 'Windows'),
)
- group_name = models.CharField(maxlength=100)
+ group_name = models.CharField(max_length=100)
contact_person = models.ForeignKey(Contact)
- contact_position_in_organisation = models.CharField(maxlength=50)
+ contact_position_in_organisation = models.CharField(max_length=50)
## Consider using DecimalField if we upgrade to more modern version of
## Django.
- financial_position = models.FloatField(max_digits=10, decimal_places=2)
+ financial_position = models.FloatField( )
staff_numbers = models.IntegerField()
volunteer_numbers = models.IntegerField()
- who_will_use_computers = models.CharField(maxlength=50)
- computers_used_for = models.CharField(maxlength=50)
+ who_will_use_computers = models.CharField(max_length=50)
+ computers_used_for = models.CharField(max_length=50)
need_network = models.BooleanField()
- linux_or_windows = models.CharField(maxlength=7, choices=OS_CHOICES)
+ linux_or_windows = models.CharField(max_length=7, choices=OS_CHOICES)
training_needed = models.BooleanField()
#person_in_charge_of_computers = models.ForeignKey(Contact)
feedback_yes_no = models.BooleanField()
## Consider using DecimalField if we upgrade to more modern version of
## Django.
- installation_charge = models.FloatField(max_digits=10,
decimal_places=2)
- cost_of_request = models.FloatField(max_digits=10, decimal_places=2)
+ installation_charge = models.FloatField( )
+ cost_of_request = models.FloatField( )
def __str__(self):
"""
@@ -173,8 +173,8 @@
('other', 'Other'),
)
group = models.ForeignKey(Group)
- service_name = models.CharField(maxlength=20)
- service_type = models.CharField(maxlength=11, choices=SERVICE_TYPES)
+ service_name = models.CharField(max_length=20)
+ service_type = models.CharField(max_length=11, choices=SERVICE_TYPES)
def __str__(self):
"""
This is what will be shown in the Admin interface, amongst other
@@ -193,7 +193,7 @@
pass
class Language(models.Model):
- language_name = models.CharField(maxlength=50)
+ language_name = models.CharField(max_length=50)
def __str__(self):
"""
This is what will be shown in the Admin interface, amongst other
@@ -223,9 +223,9 @@
)
contact = models.ForeignKey(Contact)
language_name = models.ForeignKey(Language)
- language_usage = models.CharField(maxlength=7,
+ language_usage = models.CharField(max_length=7,
choices=LANGUAGE_USE_CHOICES)
- language_preference = models.CharField(maxlength=9,
+ language_preference = models.CharField(max_length=9,
choices=LANGUAGE_PREFERENCE_CHOICES)
def __str__(self):
"""
@@ -268,8 +268,8 @@
('other', 'Other'),
)
contact = models.ForeignKey(Contact)
- hours = models.CharField(maxlength=10, choices=HOURS_CHOICES)
- interests = models.CharField(maxlength=20, choices=INTERESTS)
+ hours = models.CharField(max_length=10, choices=HOURS_CHOICES)
+ interests = models.CharField(max_length=20, choices=INTERESTS)
def __str__(self):
"""
@@ -310,7 +310,7 @@
('dialup', 'Dialup'),
)
contact = models.ForeignKey(Contact)
- concession_type = models.CharField(maxlength=10,
choices=CONCESSION_TYPES)
+ concession_type = models.CharField(max_length=10,
choices=CONCESSION_TYPES)
concession_checked_by = models.ForeignKey(Volunteer)
#referring_org = models.ForeignKey(Group)
install_windows = models.BooleanField()
@@ -322,7 +322,7 @@
can_use_email = models.BooleanField()
can_use_internet = models.BooleanField()
has_attended_training = models.BooleanField()
- internet_type = models.CharField(maxlength=9, choices=INTERNET_TYPES)
+ internet_type = models.CharField(max_length=9, choices=INTERNET_TYPES)
def __str__(self):
"""
@@ -349,10 +349,10 @@
('landline-other', 'Other'),
)
contact = models.ForeignKey(Contact)
- phone_number = models.PhoneNumberField()
+ phone_number = models.CharField(max_length=50)
## 'landline-other' is longest option needed to be stored at present,
with
## a length of 14 characters.
- phone_type = models.CharField(maxlength=14, choices=PHONE_CHOICES)
+ phone_type = models.CharField(max_length=14, choices=PHONE_CHOICES)
def __str__(self):
"""
This is what will be shown in the Admin interface, amongst other
Modified: trunk/misc/patrick/wjContact/patrick_local_settings.py
==============================================================================
--- trunk/misc/patrick/wjContact/patrick_local_settings.py (original)
+++ trunk/misc/patrick/wjContact/patrick_local_settings.py Sun Jun 28
21:58:40 2009
@@ -123,3 +123,4 @@
)
+ROOT_URLCONF = 'wjContact.urls'
Modified: trunk/misc/patrick/wjContact/settings.py
==============================================================================
--- trunk/misc/patrick/wjContact/settings.py (original)
+++ trunk/misc/patrick/wjContact/settings.py Sun Jun 28 21:58:40 2009
@@ -103,13 +103,14 @@
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
#"C:\Documents and
Settings\wendy_admin\src\eclipse_workspace\djangodb\misc\wendy\wjContact\contacts\templates"
- os.path.join( os.path.dirname(__file__), 'templates'),
- os.path.join( os.path.dirname(__file__), 'contacts/templates'),
- os.path.join( os.path.dirname(__file__), 'computers/templates'),
- os.path.join( os.path.dirname(__file__), 'sales/templates'),
+ os.path.join( os.path.dirname(__file__), 'templates'),
+ os.path.join( os.path.dirname(__file__), 'contacts/templates'),
+ os.path.join( os.path.dirname(__file__), 'computers/templates'),
+ os.path.join( os.path.dirname(__file__), 'sales/templates'),
)
INSTALLED_APPS = (
+ #'django_extensions',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',