Permalink
Browse files

CLI: Print the 192.x.x.x local IP and not other

  • Loading branch information...
1 parent 803d0a9 commit 6b0885f74473a653ce0a9fdf3c4cae4cd0c06238 @jpscaletti jpscaletti committed Jan 29, 2013
View
@@ -1,6 +1,6 @@
# Legal
2010 by Lúcuma (http://lucumalabs.com).
+© by Lúcuma (http://lucumalabs.com).
MIT License. (http://www.opensource.org/licenses/mit-license.php)
View
@@ -53,5 +53,5 @@ def hello(request):
NotAllowed = Forbidden
redirect_to = redirect
-__version__ = '1.6'
+__version__ = '1.6.1'
View
@@ -317,7 +317,6 @@ def dispatch(self, request):
"""
try:
endpoint, kwargs = self.match_url(request)
- request.view_kwargs = kwargs
resp_value = self.preprocess_request(request, kwargs)
if resp_value is None:
resp_value = endpoint(request, **kwargs)
@@ -454,18 +453,13 @@ def print_welcome_msg(self):
''])
def print_help_msg(self, host, port):
- """Prints a help message.
-
- """
if host == '0.0.0.0':
print ' * Running on http://0.0.0.0:%s' % (port,)
# local IP address for easy debugging.
- ips = [ip
- for ip in socket.gethostbyname_ex(socket.gethostname())[2]
- if not ip.startswith("127.")
- ][:1]
- if ips:
- print ' * Running on http://%s:%s' % (ips[0], port)
+ for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
+ if ip.startswith('192.'):
+ print ' * Running on http://%s:%s' % (ips[0], port)
+ break
print '-- Quit the server with Ctrl+C --'
def run(self, host=None, port=None, debug=None, reloader=None,
View
@@ -294,7 +294,7 @@ def send_file(request, filepath_or_fp, mimetype=None, as_attachment=False,
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.
Used under the modified BSD license.
"""
@@ -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.
--------------------------------
- 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.
Used under the modified BSD license.
"""
@@ -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.
--------------------------------
- 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.
Used under the modified BSD license.
"""
View
@@ -45,9 +45,6 @@ class Render(object):
'link_to': link_to,
'plural': dumb_plural,
-
- # Deprecated. Will go away in v1.3
- 'csrf_secret': LocalProxy(get_csrf),
}
default_extensions = []
@@ -1,65 +1,27 @@
# -*- coding: utf-8 -*-
-"""
- Common models
- -------------------------------
-
-"""
from datetime import datetime
import shake
from shake import url_for, get_csrf, to_unicode
from slugify import slugify # from libs
from sqlalchemy.orm import validates
-from main import app, db
+from main import db
class BaseMixin(object):
id = db.Column(db.Integer, primary_key=True)
-
- @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)
+ deleted = db.Column(db.Boolean, default=False, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow,
nullable=False)
-
modified_at = db.Column(db.DateTime, default=datetime.utcnow,
onupdate=datetime.utcnow, nullable=False)
@classmethod
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):
raise shake.NotFound
return item
@@ -71,25 +33,38 @@ def get_all(cls, deleted=False):
query = query.filter(cls.deleted == deleted)
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
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', 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):
csfr = get_csrf()
data = {
- 'id': self.id,
+ 'item_id': self.id,
csfr.name: csfr.value,
}
return url_for(self.__tablename__ + '.delete', **data)
def get_restore_url(self):
csfr = get_csrf()
data = {
- 'id': self.id,
+ 'item_id': self.id,
csfr.name: csfr.value,
}
return url_for(self.__tablename__ + '.restore', **data)
@@ -105,9 +80,8 @@ def restore(self):
class SluggableMixin(object):
- name = db.Column(db.Unicode(220), default=u''),
-
- slug = db.Column(db.String(220), default=''),
+ name = db.Column(db.Unicode(220), default=u'')
+ slug = db.Column(db.String(220), default='')
def __init__(self, name, *args, **kwargs):
self.name = to_unicode(name)
@@ -119,3 +93,7 @@ def _set_slug(self, key, value):
self.slug = slugify(value)
return value
+ @classmethod
+ def by_slug(cls, slug):
+ return db.query(cls).filter(cls.slug == slug).first()
+
@@ -38,7 +38,7 @@ def __repr__(self):
return '<%s %s>' % (self.__class__.__name__, self.name.encode('utf8'))
-class User(db.Model, AuditableMixin):
+class User(AuditableMixin, db.Model):
__tablename__ = 'users'
Oops, something went wrong.

0 comments on commit 6b0885f

Please sign in to comment.