Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot Alter authored and Eliot Alter committed Apr 14, 2012
2 parents 97e0b8b + 58632bf commit 35e4665
Show file tree
Hide file tree
Showing 31 changed files with 7,403 additions and 99 deletions.
@@ -0,0 +1,76 @@
# -*- 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 'UserProfile.evernote_shard'
db.add_column('account_userprofile', 'evernote_shard',
self.gf('django.db.models.fields.CharField')(default='', max_length=128, blank=True),
keep_default=False)

# Adding field 'UserProfile.evernote_uid'
db.add_column('account_userprofile', 'evernote_uid',
self.gf('django.db.models.fields.CharField')(default='', max_length=128, blank=True),
keep_default=False)

def backwards(self, orm):
# Deleting field 'UserProfile.evernote_shard'
db.delete_column('account_userprofile', 'evernote_shard')

# Deleting field 'UserProfile.evernote_uid'
db.delete_column('account_userprofile', 'evernote_uid')

models = {
'account.userprofile': {
'Meta': {'object_name': 'UserProfile'},
'evernote_shard': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'evernote_token': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
'evernote_token_expires_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'evernote_uid': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'profile'", 'unique': 'True', 'to': "orm['auth.User']"})
},
'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'})
},
'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 = ['account']
2 changes: 2 additions & 0 deletions evervim/account/models.py
Expand Up @@ -5,3 +5,5 @@ class UserProfile(models.Model):
user = models.OneToOneField(User, related_name="profile")
evernote_token = models.CharField(blank=True, max_length=256)
evernote_token_expires_time = models.DateTimeField(null=True, blank=True)
evernote_shard = models.CharField(blank=True, max_length=128)
evernote_uid = models.CharField(blank=True, max_length=128)
18 changes: 14 additions & 4 deletions evervim/edit/views.py
@@ -1,18 +1,28 @@
from datetime import datetime
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from evernote_api import EvernoteAPI
import logging

def home(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('account.views.login_page', args=[]))
if request.user.profile.evernote_token == "" \
or request.user.profile.evernote_token_expires_time < datetime.now():
profile = request.user.profile
if profile.evernote_token == "" \
or profile.evernote_token_expires_time < datetime.now():
callback_url = request.build_absolute_uri(
reverse('evernote_api.views.get_evernote_token', args=[]))
everAuth = EvernoteAPI()
return everAuth.get_token(request, callback_url)
return render_to_response('home.html', {},
everAPI = EvernoteAPI(profile.evernote_token, profile.evernote_shard)
allnotes = everAPI.get_notes_with_tag("evervim")
allnotes = [{'title': n.title, 'id': n.guid} for n in allnotes]
return render_to_response('home.html', {'notes': allnotes},
context_instance=RequestContext(request))

def edit_note(request, guid=None):
profile = request.user.profile
everAPI = EvernoteAPI(profile.evernote_token, profile.evernote_shard)
return HttpResponse(everAPI.get_note_text(guid))
27 changes: 27 additions & 0 deletions evervim/evernote_api/__init__.py
Expand Up @@ -2,10 +2,15 @@
https://github.com/leehsueh/django-evernote-oauth/. Many many thanks to him
for doing the legwork!
"""
from bs4 import BeautifulSoup
from django.conf import settings
from django.http import HttpResponseRedirect
from evernote.edam.notestore import NoteStore
from evernote.edam.notestore.ttypes import NoteFilter
from time import time
from urllib import urlencode
import thrift.protocol.TBinaryProtocol as TBinaryProtocol
from thrift.transport import THttpClient
import urllib2
import urlparse

Expand Down Expand Up @@ -84,3 +89,25 @@ def get_user_token(self, request):
else:
return None

def _get_note_store(self):
noteStoreUri = self.noteStoreUriBase + self.shard
noteStoreHttpClient = THttpClient.THttpClient(noteStoreUri)
noteStoreProtocol = TBinaryProtocol.TBinaryProtocol(noteStoreHttpClient)
noteStore = NoteStore.Client(noteStoreProtocol)
return noteStore

def get_notes_with_tag(self, tag):
notestore = self._get_note_store()
allTags = notestore.listTags(self.oauth_token)
tag = [x for x in allTags if x.name == tag][0]
nFilter = NoteFilter(tagGuids=[tag.guid])
notes = notestore.findNotes(self.oauth_token, nFilter, 0, 10)
return notes.notes

def get_note_text(self, guid):
notestore = self._get_note_store()
note = notestore.getNote(self.oauth_token, guid, True, False,
False, False)
text = note.content
soup = BeautifulSoup(text)
return soup.find('en-note').get_text()
2 changes: 2 additions & 0 deletions evervim/evernote_api/views.py
Expand Up @@ -20,5 +20,7 @@ def get_evernote_token(request):
expires_time = datetime.now()
profile.evernote_token = credentials['oauth_token']
profile.evernote_token_expires_time = expires_time
profile.evernote_shard = credentials['edam_shard']
profile.evernote_uid = credentials['edam_userId']
profile.save()
return HttpResponseRedirect(reverse('edit.views.home', args=[]))
8 changes: 5 additions & 3 deletions evervim/settings.py
Expand Up @@ -108,6 +108,7 @@

INSTALLED_APPS = (
'account',
'bs4',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
Expand All @@ -120,6 +121,7 @@
'evernote_api',
'gunicorn',
'south',
'thrift',
)

# A sample logging configuration. The only tangible logging
Expand All @@ -145,9 +147,9 @@
}
}

EVERNOTE_HOST = ""
EVERNOTE_KEY = ""
EVERNOTE_SECRET = ""
EVERNOTE_HOST = os.environ['EVERNOTE_HOST']
EVERNOTE_KEY = os.environ['EVERNOTE_KEY']
EVERNOTE_SECRET = os.environ['EVERNOTE_SECRET']
EVERNOTE_OAUTH_TOKEN_VALIDITY = 1 # OAuth token validity in days: 1 for dev,
# 365 for prod after activation

Expand Down
65 changes: 62 additions & 3 deletions evervim/static/css/main.css
@@ -1,4 +1,63 @@
.vimText {
width:100%;
height:100%;
html, body {
font-family: Helvetica;
height: 100%;
margin: 0px;
padding: 0px;
}
#header {
background-color: #610B0B;
color: white;
}
#header div.left {
padding-top: 50px;
margin-left: 250px;
margin-right: auto;
width: 400px;
height: 80px;
font-size: 40px;
letter-spacing: 2px;
float: left;
}

#header div.right {
padding-top: 50px;
width: 300px;
float: right;
}
#wrapper {
margin-left: auto;
margin-right: auto;
width: 900px;
height: 100%;
}

.note {
width: 100px;
min-height: 50px;
padding: 10px;
margin: 5px;
float: left;
background-color: #F8E0E0;
font-size: 20px;
border: 2px solid #F78181;
border-radius: 7px;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
}

div.clearfix {
clear: both;
}

div#all-notes {
margin: 5px;
width: 300px;
float: left;
}

div#text-box {
width: 500px;
padding: 0px;
margin: 5px;
float: left;
}
9 changes: 9 additions & 0 deletions evervim/static/js/magic.js
@@ -0,0 +1,9 @@
function noteClickHandlers(get_url) {
$('.note').click(function() {
var guid = $(this).attr('rel');
$.get(get_url + guid + "/", {}, function(data) {
$('textarea').val(data);
editor($('textarea').get(0));
});
});
}

0 comments on commit 35e4665

Please sign in to comment.