Changeset - a7271dbefd96
[Not reviewed]
default
0 3 0
Søren Løvborg - 9 years ago 2017-02-22 21:13:37
sorenl@unity3d.com
gists: simplify expiration checks
3 files changed with 14 insertions and 14 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/gists.py
Show inline comments
 
@@ -72,7 +72,7 @@ class GistsController(BaseController):
 
        c.show_public = request.GET.get('public') and not_default_user
 

	
 
        gists = Gist().query() \
 
            .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time())) \
 
            .filter_by(is_expired=False) \
 
            .order_by(Gist.created_on.desc())
 

	
 
        # MY private
 
@@ -166,12 +166,10 @@ class GistsController(BaseController):
 
    def show(self, gist_id, revision='tip', format='html', f_path=None):
 
        c.gist = Gist.get_or_404(gist_id)
 

	
 
        #check if this gist is not expired
 
        if c.gist.gist_expires != -1:
 
            if time.time() > c.gist.gist_expires:
 
                log.error('Gist expired at %s',
 
                          time_to_datetime(c.gist.gist_expires))
 
                raise HTTPNotFound()
 
        if c.gist.is_expired:
 
            log.error('Gist expired at %s',
 
                      time_to_datetime(c.gist.gist_expires))
 
            raise HTTPNotFound()
 
        try:
 
            c.file_changeset, c.files = GistModel().get_gist_files(gist_id,
 
                                                            revision=revision)
 
@@ -189,12 +187,10 @@ class GistsController(BaseController):
 
    def edit(self, gist_id, format='html'):
 
        c.gist = Gist.get_or_404(gist_id)
 

	
 
        #check if this gist is not expired
 
        if c.gist.gist_expires != -1:
 
            if time.time() > c.gist.gist_expires:
 
                log.error('Gist expired at %s',
 
                          time_to_datetime(c.gist.gist_expires))
 
                raise HTTPNotFound()
 
        if c.gist.is_expired:
 
            log.error('Gist expired at %s',
 
                      time_to_datetime(c.gist.gist_expires))
 
            raise HTTPNotFound()
 
        try:
 
            c.file_changeset, c.files = GistModel().get_gist_files(gist_id)
 
        except VCSError:
kallithea/controllers/api/api.py
Show inline comments
 
@@ -2355,7 +2355,7 @@ class ApiController(JSONRPCController):
 
        return [
 
            gist.get_api_data()
 
            for gist in Gist().query()
 
                .filter(or_(Gist.gist_expires == -1, Gist.gist_expires >= time.time()))
 
                .filter_by(is_expired=False)
 
                .filter(Gist.owner_id == user_id)
 
                .order_by(Gist.created_on.desc())
 
        ]
kallithea/model/db.py
Show inline comments
 
@@ -2533,6 +2533,10 @@ class Gist(Base, BaseDbModel):
 

	
 
    owner = relationship('User')
 

	
 
    @hybrid_property
 
    def is_expired(self):
 
        return (self.gist_expires != -1) & (time.time() > self.gist_expires)
 

	
 
    def __repr__(self):
 
        return '<Gist:[%s]%s>' % (self.gist_type, self.gist_access_id)
 

	
0 comments (0 inline, 0 general)