示例#1
0
    def index(self):
        c.has_fb_account = bool(self.logged_in_user.fb_uid)
        if c.has_fb_account:
            c.fb_privacy_setting = self.settings.get(
                UserSettingConst.FB_PRIVACY, 'FB_DEFAULT')
            c.fb_privacy_options = fb.get_privacy_options()
        else:
            c.fb_connect_url = fb.get_authorization_url()

        c.has_flickr_account = bool(self.logged_in_user.flickr_token)

        if c.has_flickr_account:
            flickr_settings = self.settings.get(UserSettingConst.FLICKR_SET_SYNCING, {})
            c.select_sets = flickr_settings.get('select_sets', False)
            selected_sets = flickr_settings.get('selected_sets', [])

            c.all_sets = []

            fk = flickr.FlickrAPI(self.logged_in_user.flickr_token)
            photosets = fk.photosets_getList()[0]
            for photoset in photosets:
                id = photoset.get('id')
                title = photoset.find('title').text
                c.all_sets.append({'id':id,
                                   'title':title,
                                   'checked':id in selected_sets})
        else:
            c.flickr_connect_url = flickr.get_authorization_url()


        return render('/settings.mako')
示例#2
0
    def index(self):
        c.has_fb_account = bool(self.logged_in_user.fb_uid)
        if c.has_fb_account:
            c.fb_privacy_setting = self.settings.get(
                UserSettingConst.FB_PRIVACY, 'FB_DEFAULT')
            c.fb_privacy_options = fb.get_privacy_options()
        else:
            c.fb_connect_url = fb.get_authorization_url()

        c.has_flickr_account = bool(self.logged_in_user.flickr_token)

        if c.has_flickr_account:
            flickr_settings = self.settings.get(
                UserSettingConst.FLICKR_SET_SYNCING, {})
            c.select_sets = flickr_settings.get('select_sets', False)
            selected_sets = flickr_settings.get('selected_sets', [])

            c.all_sets = []

            fk = flickr.FlickrAPI(self.logged_in_user.flickr_token)
            photosets = fk.photosets_getList()[0]
            for photoset in photosets:
                id = photoset.get('id')
                title = photoset.find('title').text
                c.all_sets.append({
                    'id': id,
                    'title': title,
                    'checked': id in selected_sets
                })
        else:
            c.flickr_connect_url = flickr.get_authorization_url()

        return render('/settings.mako')
示例#3
0
    def index(self):
        c.user = self.logged_in_user
        c.fb_connect_url = fb.get_authorization_url()
        c.flickr_connect_url = flickr.get_authorization_url()
        if self.logged_in_user:
            if self.logged_in_user.fb_access_token:
                c.fb_user = fb.GraphUser(
                    id=self.logged_in_user.fb_uid,
                    access_token=self.logged_in_user.fb_access_token)
            if self.logged_in_user.flickr_token:
                c.flickr_user = flickr.FlickrUser(
                    token=self.logged_in_user.flickr_token)
            if self.logged_in_user.flickr_token and self.logged_in_user.fb_access_token:
                c.tasks = AsyncTask.get_for_user(
                    limit=2,
                    type=FullSync.get_type()).all()
                c.sync_url = '/sync/full_sync'
                for task in c.tasks:
                    if task.is_completed:
                        c.last_task = task
                    elif task.time_left:
                        c.next_task = task
                    else:
                        c.current_task = task

            bytes_in, bytes_out = SyncRecord.get_bytes_transfered_by_user(self.logged_in_user.id)
            c.bytes_transferred = bytes_in/1024.**2

            # cost is $0.10 per GB transferred in and
            # $0.15 per GB transferred out
            c.cost = bytes_in/1024.**3 * 0.1 + bytes_out/1024.**3 * 0.15

        if c.tasks:
            return render('/homepage.mako')

        return render('/frontpage.mako')

        if session.get('user_id'):
            return self.home()
        else:
            c.fb_connect_url = fb.get_authorization_url([
                'user_photos',
                'publish_stream',
                'offline_access',
                ])
            # Return a rendered template
            return render('/frontpage.mako')
示例#4
0
    def document(self):
        """Render the error document"""

        request = self._py_object.request
        resp = request.environ.get('pylons.original_response')
        c.error_code = cgi.escape(request.GET.get('code', str(resp.status_int)))
        c.error_message = literal(resp.body) or cgi.escape(request.GET.get('message', ''))

        return render('/error.mako')

        request = self._py_object.request
        resp = request.environ.get('pylons.original_response')
        content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
        c.error_code = cgi.escape(request.GET.get('code', str(resp.status_int)))
        c.error_message = content
        page = error_document_template % \
            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
                 message=content)
        return page
示例#5
0
    def home(self):
        c.picasa_connect_url = picasa.get_authorization_url()
        c.flickr_connect_url = flickr.get_authorization_url()
        c.fb_connect_url = fb.get_authorization_url()
        c.fbuser = fb.GraphUser()
        c.picasa_user = None
        if session.get('picasa_token'):
            c.picasa_user = gdata.photos.service.PhotosService()
        c.flickr_user = None
        if session.get('flickr_token'):
            c.flickr_user = flickr.FlickrUser()

        tasks = AsyncTask.get_for_user(limit=2, type=FullSync.get_type()).all()
        c.tasks = tasks
        for task in reversed(tasks):
            if task.is_completed:
                c.last_task = task
            elif task.time_left:
                c.next_task = task
            else:
                c.current_task = task

        return render('/homepage.mako')
示例#6
0
    def stats(self):
        c.user_count = Session.query(User).count()
        c.sync_count = Session.query(SyncRecord).count()
        c.async_tasks_count = Session.query(AsyncTask).count()


        data = Session.query(SyncRecord.user_id,
                             func.count(1),
                             func.sum(SyncRecord.transfer_in),
                             func.sum(SyncRecord.transfer_out))\
            .filter(SyncRecord.type == SyncRecord.TYPE_PHOTO)\
            .group_by(SyncRecord.user_id).all()

        c.user_stats = []
        c.total_count = 0
        c.total_cost = 0
        c.total_tin = 0
        c.total_tout = 0
        for user_id, count, tin, tout in data:
            tin = tin or 0
            tout = tout or 0
            bandwidth_cost = cost.get_bandwidth_cost(tin, tout)
            c.total_cost += bandwidth_cost
            c.total_tout += int(tout)
            c.total_tin += int(tin)
            c.total_count += count
            c.user_stats.append([
                User.get_by_id(user_id), count,
                round(tin / 1024 / 1024, 2),
                round(tout / 1024 / 1024, 2), bandwidth_cost
            ])
        c.total_tout = round(c.total_tout / 1024. / 1024, 2)
        c.total_tin = round(c.total_tin / 1024. / 1024, 2)

        order_by = int(request.GET.get('order_by', 4))
        c.user_stats.sort(key=lambda d: d[order_by], reverse=True)
        return render('/admin/stats.mako')
示例#7
0
    def stats(self):
        c.user_count = Session.query(User).count()
        c.sync_count = Session.query(SyncRecord).count()
        c.async_tasks_count = Session.query(AsyncTask).count()


        data = Session.query(SyncRecord.user_id,
                             func.count(1),
                             func.sum(SyncRecord.transfer_in),
                             func.sum(SyncRecord.transfer_out))\
            .filter(SyncRecord.type == SyncRecord.TYPE_PHOTO)\
            .group_by(SyncRecord.user_id).all()

        c.user_stats = []
        c.total_count = 0
        c.total_cost = 0
        c.total_tin = 0
        c.total_tout = 0
        for user_id, count, tin, tout in data:
            tin = tin or 0
            tout = tout or 0
            bandwidth_cost = cost.get_bandwidth_cost(tin,tout)
            c.total_cost += bandwidth_cost
            c.total_tout += int(tout)
            c.total_tin += int(tin)
            c.total_count += count
            c.user_stats.append([User.get_by_id(user_id),
                                 count,
                                 round(tin/1024/1024, 2),
                                 round(tout/1024/1024, 2),
                                 bandwidth_cost])
        c.total_tout = round(c.total_tout/1024./1024, 2)
        c.total_tin = round(c.total_tin/1024./1024, 2)

        order_by = int(request.GET.get('order_by', 4))
        c.user_stats.sort(key=lambda d: d[order_by], reverse=True)
        return render('/admin/stats.mako')
示例#8
0
    def document(self):
        """Render the error document"""

        request = self._py_object.request
        resp = request.environ.get('pylons.original_response')
        c.error_code = cgi.escape(request.GET.get('code',
                                                  str(resp.status_int)))
        c.error_message = literal(resp.body) or cgi.escape(
            request.GET.get('message', ''))

        return render('/error.mako')

        request = self._py_object.request
        resp = request.environ.get('pylons.original_response')
        content = literal(resp.body) or cgi.escape(
            request.GET.get('message', ''))
        c.error_code = cgi.escape(request.GET.get('code',
                                                  str(resp.status_int)))
        c.error_message = content
        page = error_document_template % \
            dict(prefix=request.environ.get('SCRIPT_NAME', ''),
                 code=cgi.escape(request.GET.get('code', str(resp.status_int))),
                 message=content)
        return page
示例#9
0
 def index(self):
     return render('/admin/index.mako')
示例#10
0
 def index(self):
     return render('/admin/index.mako')