-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodels.py
39 lines (33 loc) · 1.12 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from django.db import models
from oauth import oauth
import re, httplib, simplejson
from utils import *
class User(models.Model):
username = models.CharField(max_length=40)
email = models.EmailField()
oauth_token = models.CharField(max_length=200)
oauth_token_secret = models.CharField(max_length=200)
def validate(self):
errors = []
if self.username and not re.compile('^[a-zA-Z0-9_]{1,40}$').match( \
self.username):
errors += ['username']
if self.email and not re.compile( \
'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$').match( \
self.email):
errors += ['email']
return errors
# django.core.context_processors.auth assumes that an object attached
# to request.user is always a django.contrib.auth.models.User, which
# is completely broken but easy to work around
def get_and_delete_messages(self): pass
def token(self):
return oauth.OAuthToken(self.oauth_token, self.oauth_token_secret)
def is_authorized(self): return is_authorized(self.token())
def tweet(self, status):
return api(
'https://twitter.com/statuses/update.json',
self.token(),
http_method='POST',
status=status
)