Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
CLI: Print the 192.x.x.x local IP and not other
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Jan 29, 2013
1 parent 803d0a9 commit 6b0885f
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 247 deletions.
2 changes: 1 addition & 1 deletion LEGAL.md
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
# Legal # Legal


© 2010 by Lúcuma (http://lucumalabs.com). © by Lúcuma (http://lucumalabs.com).
MIT License. (http://www.opensource.org/licenses/mit-license.php) MIT License. (http://www.opensource.org/licenses/mit-license.php)




Expand Down
2 changes: 1 addition & 1 deletion shake/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ def hello(request):
NotAllowed = Forbidden NotAllowed = Forbidden
redirect_to = redirect redirect_to = redirect


__version__ = '1.6' __version__ = '1.6.1'


14 changes: 4 additions & 10 deletions shake/app.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ def dispatch(self, request):
""" """
try: try:
endpoint, kwargs = self.match_url(request) endpoint, kwargs = self.match_url(request)
request.view_kwargs = kwargs
resp_value = self.preprocess_request(request, kwargs) resp_value = self.preprocess_request(request, kwargs)
if resp_value is None: if resp_value is None:
resp_value = endpoint(request, **kwargs) resp_value = endpoint(request, **kwargs)
Expand Down Expand Up @@ -454,18 +453,13 @@ def print_welcome_msg(self):
'']) ''])


def print_help_msg(self, host, port): def print_help_msg(self, host, port):
"""Prints a help message.
"""
if host == '0.0.0.0': if host == '0.0.0.0':
print ' * Running on http://0.0.0.0:%s' % (port,) print ' * Running on http://0.0.0.0:%s' % (port,)
# local IP address for easy debugging. # local IP address for easy debugging.
ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
for ip in socket.gethostbyname_ex(socket.gethostname())[2] if ip.startswith('192.'):
if not ip.startswith("127.") print ' * Running on http://%s:%s' % (ips[0], port)
][:1] break
if ips:
print ' * Running on http://%s:%s' % (ips[0], port)
print '-- Quit the server with Ctrl+C --' print '-- Quit the server with Ctrl+C --'


def run(self, host=None, port=None, debug=None, reloader=None, def run(self, host=None, port=None, debug=None, reloader=None,
Expand Down
6 changes: 3 additions & 3 deletions shake/helpers.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def send_file(request, filepath_or_fp, mimetype=None, as_attachment=False,
Set to overwrite the default Response class. Set to overwrite the default Response class.
-------------------------------- --------------------------------
Copied almost unchanged from Flask <http://flask.pocoo.org/> Copied almost verbatim from Flask <http://flask.pocoo.org/>
Copyright © 2010 by Armin Ronacher. Copyright © 2010 by Armin Ronacher.
Used under the modified BSD license. Used under the modified BSD license.
""" """
Expand Down Expand Up @@ -391,7 +391,7 @@ def to_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
If strings_only is True, don't convert (some) non-string-like objects. If strings_only is True, don't convert (some) non-string-like objects.
-------------------------------- --------------------------------
Copied almost unchanged from Django <https://www.djangoproject.com/> Copied almost verbatim from Django <https://www.djangoproject.com/>
Copyright © Django Software Foundation and individual contributors. Copyright © Django Software Foundation and individual contributors.
Used under the modified BSD license. Used under the modified BSD license.
""" """
Expand Down Expand Up @@ -445,7 +445,7 @@ def to_bytestring(s, encoding='utf-8', strings_only=False, errors='strict'):
If strings_only is True, don't convert (some) non-string-like objects. If strings_only is True, don't convert (some) non-string-like objects.
-------------------------------- --------------------------------
Copied almost unchanged from Django <https://www.djangoproject.com/> Copied almost verbatim from Django <https://www.djangoproject.com/>
Copyright © Django Software Foundation and individual contributors. Copyright © Django Software Foundation and individual contributors.
Used under the modified BSD license. Used under the modified BSD license.
""" """
Expand Down
3 changes: 0 additions & 3 deletions shake/render.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class Render(object):


'link_to': link_to, 'link_to': link_to,
'plural': dumb_plural, 'plural': dumb_plural,

# Deprecated. Will go away in v1.3
'csrf_secret': LocalProxy(get_csrf),
} }


default_extensions = [] default_extensions = []
Expand Down
70 changes: 24 additions & 46 deletions shake/skeletons/project/bundles/common/models.py
Original file line number Original file line Diff line number Diff line change
@@ -1,65 +1,27 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
Common models
-------------------------------
"""
from datetime import datetime from datetime import datetime


import shake import shake
from shake import url_for, get_csrf, to_unicode from shake import url_for, get_csrf, to_unicode
from slugify import slugify # from libs from slugify import slugify # from libs
from sqlalchemy.orm import validates from sqlalchemy.orm import validates


from main import app, db from main import db




class BaseMixin(object): class BaseMixin(object):


id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)

deleted = db.Column(db.Boolean, default=False, nullable=False)
@classmethod
def by_id(cls, item_id, deleted=False):
item = db.query(cls).filter(cls.id == item_id).first()
if not item:
raise shake.NotFound
return item

@classmethod
def get_all(cls):
return db.query(cls)

@classmethod
def delete_all(cls, ids):
ids = list(ids)
if not ids:
return
db.query(cls).filter(cls.id.in_(ids)).delete(synchronize_session='fetch')

def get_show_url(self, external=False):
return url_for(self.__tablename__ + '.show', id=self.id, external=external)

def get_edit_url(self):
return url_for(self.__tablename__ + '.edit', id=self.id)

def __repr__(self):
return '<%s %d>' % (self.__class__.__name__, self.id)


class AuditableMixin(object):

deleted = db.Column(db.Boolean, default=False,
nullable=False)


created_at = db.Column(db.DateTime, default=datetime.utcnow, created_at = db.Column(db.DateTime, default=datetime.utcnow,
nullable=False) nullable=False)

modified_at = db.Column(db.DateTime, default=datetime.utcnow, modified_at = db.Column(db.DateTime, default=datetime.utcnow,
onupdate=datetime.utcnow, nullable=False) onupdate=datetime.utcnow, nullable=False)


@classmethod @classmethod
def by_id(cls, item_id, deleted=False): def by_id(cls, item_id, deleted=False):
item = db.query(cls).filter(cls.id == item_id).first() item = db.query(cls).get(item_id)
if not item or (item.deleted and not deleted): if not item or (item.deleted and not deleted):
raise shake.NotFound raise shake.NotFound
return item return item
Expand All @@ -71,25 +33,38 @@ def get_all(cls, deleted=False):
query = query.filter(cls.deleted == deleted) query = query.filter(cls.deleted == deleted)
return query return query


@classmethod
def get_all_in(cls, ids, deleted=False):
query = db.query(cls).filter(cls.id.in_(ids))
if deleted is not None:
query = query.filter(cls.deleted == deleted)
return query

@classmethod @classmethod
def delete_all(cls, ids): def delete_all(cls, ids):
ids = list(ids) ids = list(ids)
if not ids: if not ids:
return return
db.query(cls).filter(cls.id.in_(ids)).delete(synchronize_session='fetch') db.query(cls).filter(cls.id.in_(ids)).delete(synchronize_session='fetch')


def get_show_url(self, external=False):
return url_for(self.__tablename__ + '.show', item_id=self.id, external=external)

def get_edit_url(self):
return url_for(self.__tablename__ + '.edit', item_id=self.id)

def get_delete_url(self): def get_delete_url(self):
csfr = get_csrf() csfr = get_csrf()
data = { data = {
'id': self.id, 'item_id': self.id,
csfr.name: csfr.value, csfr.name: csfr.value,
} }
return url_for(self.__tablename__ + '.delete', **data) return url_for(self.__tablename__ + '.delete', **data)


def get_restore_url(self): def get_restore_url(self):
csfr = get_csrf() csfr = get_csrf()
data = { data = {
'id': self.id, 'item_id': self.id,
csfr.name: csfr.value, csfr.name: csfr.value,
} }
return url_for(self.__tablename__ + '.restore', **data) return url_for(self.__tablename__ + '.restore', **data)
Expand All @@ -105,9 +80,8 @@ def restore(self):


class SluggableMixin(object): class SluggableMixin(object):


name = db.Column(db.Unicode(220), default=u''), name = db.Column(db.Unicode(220), default=u'')

slug = db.Column(db.String(220), default='')
slug = db.Column(db.String(220), default=''),


def __init__(self, name, *args, **kwargs): def __init__(self, name, *args, **kwargs):
self.name = to_unicode(name) self.name = to_unicode(name)
Expand All @@ -119,3 +93,7 @@ def _set_slug(self, key, value):
self.slug = slugify(value) self.slug = slugify(value)
return value return value


@classmethod
def by_slug(cls, slug):
return db.query(cls).filter(cls.slug == slug).first()

2 changes: 1 addition & 1 deletion shake/skeletons/project/bundles/users/models.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __repr__(self):
return '<%s %s>' % (self.__class__.__name__, self.name.encode('utf8')) return '<%s %s>' % (self.__class__.__name__, self.name.encode('utf8'))




class User(db.Model, AuditableMixin): class User(AuditableMixin, db.Model):


__tablename__ = 'users' __tablename__ = 'users'


Expand Down
Loading

0 comments on commit 6b0885f

Please sign in to comment.