Exemple #1
0
    def new(self, event_id):
        event_node = self._get_row(model.Event, event_id)
        self._check_access(event_node)

        fs = AlbumForm('album-new')

        if request.POST and fs.fields.cancel.id in request.POST:
            return redirect_to(event_node.url())

        if request.POST and fs.is_valid(request.POST):
            node = model.Album()
            node.settings = picasa.photos(
                fs.fields.user.value, fs.fields.albumid.value, limit=30
            )
            node.node_user_id = current_user().id

            meta.Session.add(node)
            event_node.albums.append(node)
            meta.Session.commit()
            flash(u'Альбом успешно добавлен')
            if self.back_page():
                return redirect_to(**self.back_page())
            return redirect_to(event_node.url())

        c.form = fs
        c.fs = fs.fields

        if is_ajax():
            result = render('/album/new_partial.html')
        else:
            result = render('/album/new.html')
        if request.POST:
            result = fs.htmlfill(result)
        return result
Exemple #2
0
    def demo_up(self):
        event = meta.Session.query(model.Event).filter(
            model.Event.id == 1
        ).one()

        user = meta.Session.query(model.User).filter(
            model.User.nickname == 'demo'
        ).one()

        for node in event.persons: meta.Session.delete(node)
        for node in event.reports: meta.Session.delete(node)
        for node in event.albums: meta.Session.delete(node)

        meta.Session.commit()

        dir = config['demo_dir']

        info_file = os.path.join(dir, 'info.yml')
        info = codecs.open(info_file, 'r', 'utf-8')
        info = yaml.load(info)

        event.title = info['title']
        if 'summary' in info:
            event.summary = info['summary']
        if 'start' in info:
            event.start = info['start']
        if 'finish' in info:
            event.finish = info['finish']
        event.node_user = user
        event.created = datetime.now()

        if 'albums' in info:
            for album in info['albums']:
                node = model.Album()
                node.settings = picasa.photos(album['user'], album['albumid'], 15)
                node.node_user = user
                node.event = event
                meta.Session.add(node)


        persons_dir = os.path.join(dir, u'persons')
        for file in os.listdir(persons_dir):
            path =  os.path.join(persons_dir, file)
            if os.path.isfile(path):
                node = model.Person()
                node.fullname = file.split('.')[0]
                node.avatar = avatar_prepare(open(path, 'r'))
                node.node_user = user
                node.event = event
                meta.Session.add(node)

        reports_dir = os.path.join(dir, u'reports')
        for file in os.listdir(reports_dir):
            path =  os.path.join(reports_dir, file)
            if os.path.isfile(path):
                text = codecs.open(path, 'r', 'utf-8').read()
                node = model.Report()
                node.title = file.split('.')[0]
                node.content = text
                node.node_user = user
                node.event = event
                meta.Session.add(node)

        meta.Session.commit()

        flash(u'Демонстрация обновлена')
        return redirect_to('demo')