Skip to content

Commit

Permalink
#165 Reorganising some code and imports, removing models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Hallvord R. M. Steen committed Oct 29, 2015
1 parent 941c158 commit dc04359
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
51 changes: 48 additions & 3 deletions webcompat/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
from hashlib import sha512
from uuid import uuid4

from webcompat import app

Expand All @@ -17,9 +24,47 @@
session_db = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=session_engine))
issues_engine = create_engine('sqlite:///' + os.path.join(app.config['BASE_DIR'],
issue_engine = create_engine('sqlite:///' + os.path.join(app.config['BASE_DIR'],
'issues.db'))

issues_db = scoped_session(sessionmaker(autocommit=False,
issue_db = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=issues_engine))
bind=issue_engine))
Base = declarative_base()
Base.query = issue_db.query_property()

class WCIssue(Base):
__tablename__ = 'webcompat_issues'

id = Column(String(128), unique=True, primary_key=True)
summary = Column(String(256))
url = Column(String(1024))
body = Column(String(2048))

def __init__(self, id, summary, url, body):
self.id = id
self.summary = summary
self.url = url
self.body = body

Base.metadata.create_all(bind=issue_engine)

Base = declarative_base()
Base.query = session_db.query_property()


class User(Base):
__tablename__ = 'users'

user_id = Column(String(128), unique=True, primary_key=True)
access_token = Column(String(128), unique=True)

def __init__(self, access_token):
self.access_token = access_token
# We use the user_id in the session cookie to identify auth'd users.
# Here we salt and hash the GitHub access token so you can't get
# back to the auth token if the session cookie was ever compromised.
self.user_id = sha512(access_token + uuid4().hex).hexdigest()[0:128]


Base.metadata.create_all(bind=session_engine)
34 changes: 0 additions & 34 deletions webcompat/models.py

This file was deleted.

4 changes: 2 additions & 2 deletions webcompat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from helpers import get_user_info
from helpers import set_referer
from issues import report_issue
from models import session_db
from models import User
from webcompat.db import session_db
from webcompat.db import User

from webcompat import app
from webcompat import github
Expand Down
4 changes: 2 additions & 2 deletions webcompat/webhooks/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import re
import requests

from db import issue_db
from db import WCIssue
from webcompat import app
from webcompat.helpers import extract_url
from webcompat.db import issue_db
from webcompat.db import WCIssue


def api_post(endpoint, payload, issue):
Expand Down

0 comments on commit dc04359

Please sign in to comment.