コード例 #1
0
ファイル: medium.py プロジェクト: dummy3k/medienverwaltung
    def __create_feed__(self, query, title, key_field):
        myItems = []
        base_url = config.get('base_url', 'http://127.0.0.1:5000')
        query = query.limit(10)


        template = h.tmpl('/medium/rss_item.mako', 'description')

        for item in query.all():
            newItem = PyRSS2Gen.RSSItem(
                title = item.title,
                link = base_url + h.url_for(controller='/medium', action="edit", id=item.id),
                description = template.render_unicode(item, h, base_url),
                #~ guid = PyRSS2Gen.Guid(str(item.id)),
                guid = PyRSS2Gen.Guid("%s, %s" % (item.id, item.__dict__[key_field])),
                pubDate = item.__dict__[key_field])

            myItems.append(newItem)


        rss = PyRSS2Gen.RSS2(
            title = title,
            link = base_url + h.url_for(controller='/medium', action='list'),
            description = _("New Media"),
            lastBuildDate = datetime.now(),
            items = myItems)

        return rss.to_xml(encoding="utf-8")
コード例 #2
0
ファイル: borrow.py プロジェクト: dummy3k/medienverwaltung
    def add_borrower_post(self):
        log.debug("add_borrower_post")

        record = model.Borrower()
        record.first_name = request.params.get('first_name')
        record.last_name = request.params.get('last_name')
        record.email = request.params.get('email')
        record.created_ts = datetime.now()
        record.updated_ts = datetime.now()
        meta.Session.add(record)
        #~ meta.Session.commit()
        log.debug("record.id: %s" % record.id)

        h.flash(_("added: '%s %s'") % (record.first_name, record.last_name))
        media_ids = request.params.get('media_ids')
        log.debug("media_ids %s "% media_ids)
        if not media_ids:
            meta.Session.commit()
            return redirect(url(controller='borrow', action='list_borrowers'))
        else:
            log.debug("FOLLOW ME, media_id: %s" % media_ids)
            log.debug("url: %s" % h.url_for(controller='borrow', action='edit_borrower', id=record.id))
            for item in request.params.get('media_ids').split(','):
                log.debug("checkout: %s" % item)
                self.__checkout_post__(item, record)

            meta.Session.commit()
            return redirect(url(controller='borrow', action='edit_borrower', id=record.id))
コード例 #3
0
ファイル: person.py プロジェクト: dummy3k/medienverwaltung
    def merge_post(self):
        primary_id = int(request.params.get('primary_id'))
        primary = meta.Session.query(model.Person).get(primary_id)
        log.debug("primary: %s" % primary)

        primary_media = map(lambda x: x.medium, primary.persons_to_media)
        log.debug("primary_media: %s" % primary_media)

        person_ids = request.params.get('person_ids_str')
        person_ids = person_ids.split(',')
        person_ids = map(lambda x: int(x), person_ids)
        person_ids.remove(primary_id)
        log.debug("person_ids: %s" % person_ids)

        remap_cnt = 0
        for secondary_id in person_ids:
            secondary = meta.Session.query(model.Person).get(secondary_id)
            log.debug("secondary: %s" % secondary)
            for item in secondary.persons_to_media:
                if item.medium in primary_media:
                    log.debug("medium already exists: %s" % item.medium)
                else:
                    log.debug("medium does not exists: %s" % item.medium)
                    #~ item.person_id = primary.id
                    #~ meta.Session.update(item)
                    record = model.PersonToMedia()
                    record.type_id = item.type_id
                    item.medium.persons_to_media.append(record)
                    primary.persons_to_media.append(record)
                    
                    remap_cnt += 1

            alias = model.PersonAlias()
            alias.name = secondary.name
            primary.aliases.append(alias)
            meta.Session.delete(secondary)

        meta.Session.commit()
        #~ h.flash(_("Removed %(person_cnt)d, added %(media_cnt)d media") %\
                #~ {'person_cnt':len(person_ids), 'media_cnt':remap_cnt})

        h.flash(ungettext("Removed %d person",
                          "Removed %d persons",
                          len(person_ids)) % len(person_ids))
                          
        h.flash(ungettext("Added %(cnt)d medium to '%(person)s'",
                          "Added %(cnt)d media to '%(person)s'",
                          remap_cnt) % {'cnt':remap_cnt,
                                             'person':primary.name})
                          
        return_to = request.params.get('return_to',
                                       h.url_for(controller='person',
                                                 action='edit',
                                                 id=primary.id))
        return redirect(str(return_to))
コード例 #4
0
ファイル: medium.py プロジェクト: dummy3k/medienverwaltung
    def list_gallery(self, type=None, page=1, tag=None):
        if type == 'books':
            c.title = _("Books Gallery")
        elif type == 'dvds':
            c.title = _("DVDs Gallery")
        elif type:
            c.title = _("Gallery of unknown type '%s'") % type
        else:
            c.title = _("All Media Gallery")

        self.__prepare_list__(True, type, page, tag)

        c.pager_action = "list_gallery"
        c.rss_feeds = [{'title':_("New Media"),
                        'link':h.url_for(controller='medium', action='new_media_rss')},
                       {'title':_("Updated Media"),
                        'link':h.url_for(controller='medium', action='updated_media_rss')}]

        if c.mobile:
            return render('mobile/medium/list_gallery.mako')
        else:
            return render('medium/list_gallery.mako')
コード例 #5
0
ファイル: medium.py プロジェクト: dummy3k/medienverwaltung
    def list(self, type=None, page=1, tag=None):
        if type == 'books':
            c.title = _("Books List")
        elif type == 'dvds':
            c.title = _("DVDs List")
        elif type:
            c.title = _("List of unknown type '%s'") % type
        else:
            c.title = _("All Media List")



        self.__prepare_list__(False, type, page, tag)

        c.pager_action = "list"
        c.return_to = h.url_for(controller='medium', action='list', order=c.order)

        c.rss_feeds = [{'title':_("New Media"),
                        'link':h.url_for(controller='medium', action='new_media_rss')},
                       {'title':_("Updated Media"),
                        'link':h.url_for(controller='medium', action='updated_media_rss')}]
        return render('medium/list.mako')
コード例 #6
0
ファイル: amazon.py プロジェクト: dummy3k/medienverwaltung
def AddMediumByISBN(isbn, search_index):
    """
        id_type: ISBN,
        search_index: Books, DVD
    """
    response = {'input_isbn':isbn}
    try:
        api = amazonproduct.API(config['Amazon.AccessKeyID'],
                                config['Amazon.SecretAccessKey'])

        #~ log.debug("FOLLOW ME FOLLOW ME FOLLOW ME")
        #~ # Valid Values: SKU | UPC | EAN | ISBN (US only, when search
        #~ # index is Books) | JAN. UPC is not valid in the CA locale
        #~ id_type = 'SKU'
        #~ log.debug("id_type: %s" % id_type)

        #~ search_index = 'DVD'
        if search_index == 'Books':
            id_type = 'ISBN'
        elif search_index == 'DVD':
            id_type = 'EAN'
        else:
            raise Exception("unknown search_index: '%s'" % search_index)
            
        node = api.item_lookup(isbn,
                               IdType=id_type,
                               SearchIndex=search_index,
                                ResponseGroup="Images,ItemAttributes")
        item = node.Items.Item
        title = unicode(item.ItemAttributes.Title)
        response['title'] = title
        log.info("title: %s" % title)

        media_type = meta.Session\
                         .query(model.MediaType)\
                         .filter(model.MediaType.name == 'book')\
                         .first()

        medium = model.Medium()
        medium.title = title
        medium.created_ts = datetime.now()
        medium.updated_ts = datetime.now()
        log.debug("medium.title: %s" % medium.title)
        medium.media_type_id = media_type.id
        medium.isbn = isbn

        try:
            url = str(item.LargeImage.URL)
        except:
            url = None
            log.warn("%s has no image" % medium)

        if url:
            print url
            webFile = urllib.urlopen(url)
            buffer = StringIO()
            buffer.write(webFile.read())
            if buffer.len > 65536:
                log.warn("image is too big")
            else:
                medium.image_data = buffer
        else:
            url = ""

        response['image_url'] = url

        meta.Session.add(medium)
        #~ session.commit()

        asin = model.MediaToAsin()
        asin.media_id = medium.id
        asin.asin = item.ASIN
        #~ session.add(asin)
        medium.asins.append(asin)

        added_persons = []
        add_persons(item, 'Author', medium, added_persons, meta.Session)
        add_persons(item, 'Creator', medium, added_persons, meta.Session)
        add_persons(item, 'Manufacturer', medium, added_persons, meta.Session)

        response['persons'] = map(lambda x: x.name, added_persons)

        meta.Session.commit()

        response['medium_url'] = h.url_for(controller='medium', action='edit', id=medium.id)
        response['success'] = True
        response['medium_id'] = medium.id
        response['message'] = "Successfully added '%s'" % isbn
    except Exception, ex:
        log.error("AddMediumByISBN: %s" % ex)
        response['success'] = False
        response['message'] = str(ex)
コード例 #7
0
ファイル: medium.py プロジェクト: dummy3k/medienverwaltung
    def mass_add_post(self):
        if not request.params.get('title'):
            h.flash(_("please specify name"))
            return redirect(url(controller='medium', action='mass_add'))

        if int(request.params.get('media_type', -1)) < 0:
            h.flash(_("please specify media type"))
            return self.mass_add()

        media_type_obj = meta.Session.query(model.MediaType).get(request.params.get('media_type', -1))
        
        
        count = 0
        new_media = []
        failed = []
        for item in request.params.get('title').split('\n'):
            if not item.strip():
                continue

            query = meta.Session\
                .query(model.Medium)\
                .filter(or_(model.Medium.title==item,
                            model.Medium.isbn==item))
            if query.first() != None:
                first_item = query.first()
                h.flash(_("medium already exists: %s") %\
                    anchor_tmpl.render_unicode(url=h.url_for(controller='medium', action='edit', id=first_item.id),
                                       text=h.html_escape(first_item.title)), escape=False)
                continue

            log.debug("!!!item: %s" % item)
            if re.match('^\d+\s*$', item):
                #~ log.info("@@@@@@@@@@@@@@@@@@ treat input as isbn: %s" % item)
                import medienverwaltungweb.lib.amazon as amazon
                result = amazon.AddMediumByISBN(item, media_type_obj.amzon_search_index)
                if not result:
                    #~ h.flash(_("I tried to use '%s' as an isbn, but amazon didn't find it.") % item)
                    h.flash(_("Amzon does not knwo what '%s' is.") % item)
                    failed.append(item)
                    continue

                elif not result['success']:
                    h.flash(_("Amazon Lookup failed with the following error: %s") % result['message'])
                    failed.append(item)
                    continue

                medium_id = result['medium_id']
                record = meta.Session.query(model.Medium).get(medium_id)
                new_media.append(record)
                continue

            record = model.Medium()
            record.title = item.strip()
            record.created_ts = datetime.now()
            record.updated_ts = datetime.now()
            record.media_type_id = request.params.get('media_type')
            meta.Session.add(record)
            count += 1
            new_media.append(record)

        if len(new_media) > 0:
            meta.Session.commit()
            log.debug("new_media: %s" % unicode(new_media[0].title))
            log.debug("type new_media: %s" % type(new_media[0].title))
            link_list = map(lambda x: anchor_tmpl.render_unicode(url=h.url_for(controller='medium', action='edit', id=x.id), text=x.title), new_media)
            link_list = ", ".join(link_list)
            msg = ungettext("added medium %(media)s",
                            "added %(num)d media: %(media)s",
                            len(new_media)) % {'num':len(new_media),
                                               'media':link_list}
            h.flash(msg, escape=False)
            #~ h.flash(UnsafeString(msg))

        if len(new_media) == 1:
            return redirect(url(controller='medium', action='edit', id=new_media[0].id))
        else:
            return redirect(url(controller='medium', action='index'))