コード例 #1
0
 def __init__(self):
     t = datetime.datetime.now() - datetime.timedelta(hours=4)
     s = Subject().get_current().key().id()
     for img in (
         Photo.all().filter("subject_id =", s).filter("is_blocked =", False).filter("date_updated <", t).fetch(10)
     ):
         self.fetch_img(img.instagram_id)
コード例 #2
0
ファイル: dynamic.py プロジェクト: ppalucki/shcms
 def refresh_gallery(self):
     from util import render_template
     xml = render_template('gallery2.xml', photos=Photo.all())
     memcache.set("gallery.xml", xml) #@UndefinedVariable
     return webapp2.Response(xml, content_type='application/xml')
 
                    
コード例 #3
0
ファイル: main.py プロジェクト: ashimali/baltipic
def list_files():
    logger.debug('list files')
    photos = Photo.all()
    logger.debug(photos)
    context = {'photos': photos}
    template = j2env.get_template('templates/list.html')
    return template.render(context)
コード例 #4
0
ファイル: views.py プロジェクト: heracek/quadanimr
def show_public_photo(request, key):
    extra_context = {
        'object_list': Thumbnail.all().order('-photo_date_added'),
        'viewed_username': '******',
    }
    return object_detail(request, Photo.all(), key,
        template_name='photo/public-show.html',
        template_object_name='photo',
        extra_context=extra_context)
コード例 #5
0
    def get(self, *args, **kwargs):
        last_50 = Photo.all().filter('is_active =', True).filter('is_user_active =', True).filter('is_blocked =',
                                                                                                  False).order(
            '-date_added').fetch(limit=20)

        i = 0
        last_50 = [p for p in last_50]
        photos = []
        for x in xrange(0, len(last_50) / 2):
            photos.append([last_50[i], last_50[i + 1]])
            i += 2

        self.render(os.path.join(os.path.dirname(__file__), 'templates/index.html'), photos=photos, submitted=False)
コード例 #6
0
    def get(self, subject_id, username):
        photos = []
        for photo in (
            Photo.all()
            .filter("user ="******"subject_id =", int(subject_id))
            .filter("is_active =", True)
            .filter("is_user_active =", True)
            .filter("is_blocked =", False)
            .order("-total_score")
        ):
            photos.append(photo.to_dict())

        self.response.out.write(json.dumps({"photos": photos}))
コード例 #7
0
ファイル: views.py プロジェクト: heracek/quadanimr
def users_page(request, username):
    viewed_user = User.get_user_by_username_or_404(username)
    
    photo = None
    fetched_photo_list = Photo.all().filter('user', viewed_user).order('-date_added').fetch(1)
    if fetched_photo_list:
        photo = fetched_photo_list[0]
    
    extra_context = {
        'viewed_user': viewed_user,
        'photo': photo,
        'viewed_username': username
    }
    
    return object_list(request,
        queryset=Thumbnail.all().filter('photo_user', viewed_user).order('-photo_date_added'),
        template_name='photo/show.html',
        extra_context=extra_context
    )
コード例 #8
0
    def get(self, username):
        subjects = []

        current_subject = SubjectModel().get_current()
        current_best_photo = (
            Photo.all()
            .filter("user ="******"subject_id =", current_subject.key().id())
            .filter("is_active =", True)
            .filter("is_user_active =", True)
            .filter("is_blocked =", False)
            .order("-total_score")
            .get()
        )
        if current_best_photo:
            current_best_photo = current_best_photo.to_dict()

        subjects.append({"subject": current_subject.to_dict(), "best_photo": current_best_photo, "points": 0})
        for us in UserSubject().get_by_user(username):
            subjects.append(us.to_dict())

        self.response.out.write(json.dumps({"subjects": subjects}))
コード例 #9
0
    def get(self):
        subject = SubjectModel().get_current()

        photos = (
            Photo.all()
            .filter("user ="******"subject_id =", subject.key().id())
            .filter("is_active =", True)
            .order("date_instagram")
        )

        blocked = []
        fetched_ids = []
        ps = {"active": [], "inactive": []}
        for p in photos:
            fetched_ids.append(p.instagram_id)

            if p.is_blocked:
                continue
            if p.is_active and p.is_user_active:
                ps["active"].append(p.to_dict())
            else:
                ps["inactive"].append(p.to_dict())

        # get latest photos from instagram
        url = (
            "https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s&min_timestamp=%s&max_timestamp=%s"
            % (
                self.user.instagram_id,
                self.user.access_token,
                int(time.mktime(subject.active_from.utctimetuple())),
                int(time.mktime(subject.active_to.utctimetuple())),
            )
        )

        f = urlfetch.fetch(url)
        try:
            data = json.loads(f.content)
        except urlfetch.DownloadError:
            return self.response.out.write(json.dumps({"photos": ps}))

        # TODO: pagination

        if not data.has_key("data"):
            logging.error("No data in fetched url: %s" % url)
            return self.response.out.write(json.dumps({"photos": ps}))

        for photo in data["data"]:
            if photo["id"] in fetched_ids:
                continue
            d = datetime.datetime.fromtimestamp(float(photo["created_time"]))
            if d < subject.active_from or d > subject.active_to:
                continue
            # logging.info('%s < %s > %s' % (str(d), str(subject.active_from), str(subject.active_to)))

            p = Photo().to_dict(photo)
            if p["active"] and ["user_active"]:
                Photo().add_or_update(photo)
                ps["active"].append(p)
            else:
                ps["inactive"].append(p)

        self.response.out.write(json.dumps({"photos": ps}))
コード例 #10
0
ファイル: photo.py プロジェクト: takatoshiono/chin-ma-ya.org
 def get(self):
     photo_list = Photo.all().order('-updated_at')
     template_vars = { 'object_list': photo_list }
     self.render_response('photo/photo_list.html', template_vars)