示例#1
0
    def delete_borrower_post(self, id):
        record = meta.find(model.Borrower, id)
        meta.Session.delete(record)
        meta.Session.commit()

        h.flash(_("deleted: '%s %s'") % (record.first_name, record.last_name))
        return redirect(url(controller='borrow', action='list_borrowers'))
示例#2
0
    def query_images(self, id):
        """ show the user a selection of available images """

        query = meta.Session.query(model.MediaToAsin).filter(model.MediaToAsin.media_id == id)

        c.items = []
        asins = map(lambda item: item.asin, query.all())
        if len(asins) > 10:
            log.warn("number of asins is greater 10")
        node = self.api.item_lookup(",".join(asins), ResponseGroup="Images")
        c.items = node.Items.Item
        if len(c.items) == 1:
            image_url = None
            try:
                image_url = c.items[0].LargeImage.URL
                h.flash(_("Only one image available. It was automatically choosen."))
            except:
                h.flash(_("No image available"))

            if image_url:
                self.__query_images_post__(id, str(image_url))
            return redirect(url(controller="medium", action="edit", id=id))

        c.media_id = id
        return render("amazon/image_list.mako")
示例#3
0
    def scanner_post(self):
        c.available = []
        c.borrowed = []
        for line in request.params.get('isbns').split('\n'):
            line = line.strip()
            if line:
                medium = meta.Session\
                             .query(model.Medium)\
                             .filter(model.Medium.isbn == line)\
                             .first()

                if not medium:
                    h.flash(_("Isbn '%s' not found") % line)
                else:
                    borrow_act = meta.Session\
                                     .query(model.BorrowAct)\
                                     .filter(model.BorrowAct.media_id == medium.id)\
                                     .filter(model.BorrowAct.returned_ts == None)\
                                     .first()
                    if borrow_act:
                        c.borrowed.append(borrow_act)
                    else:
                        c.available.append(medium)

        c.borrowers = meta.Session.query(model.Borrower).all()
        return render('borrow/scanner_post.mako')
示例#4
0
    def __checkout_post__(self, media_id, borrower):
        log.debug("")
        log.debug("media_id: %s" % media_id)
        log.debug("borrower_id: %s" % borrower.id)

        log.debug("FOLLOW ME, too, too")
        record = model.BorrowAct()
        record.media_id = media_id
        #~ record.borrower_id = borrower_id
        record.borrowed_ts = datetime.now()
        #~ meta.Session.add(record)

        borrower.acts.append(record)

        medium = meta.Session.query(model.Medium).get(media_id)
        if not medium:
            raise Exception("could not find medium: %s" % media_id)

        borrower_link = h.tmpl('borrow/snippets.mako', 'link_to_borrower')\
                         .render_unicode(item=borrower, h=h)
        medium_link = h.tmpl('medium/snippets.mako', 'link_to_medium')\
                       .render_unicode(item=medium, h=h)
        h.flash(_("%(medium)s borrowed to %(to)s") % {'medium':medium_link,
                                                      'to':borrower_link},
                escape=False)
示例#5
0
    def add_to_medium_post(self, id):
        medium = meta.Session.query(model.Medium).get(id)
        name = request.params.get('name')
        if len(name.strip()) == 0:
            h.flash(_("Please enter the persons name"))
            return redirect(url(controller='medium', action='edit', id=id))

        person = meta.Session.query(model.Person)\
                             .filter(model.Person.name == name)\
                             .first()

        relation = meta.Session.query(model.RelationType)\
                       .filter(model.RelationType.name == request.params.get('role'))\
                       .first()
        if not relation:
            return "unknown relation: %s" % relation
            
        if not person:
            person = model.Person()
            person.name = name
            meta.Session.add(person)

        media2person = model.PersonToMedia()
        medium.persons_to_media.append(media2person)
        person.persons_to_media.append(media2person)
        relation.persons_to_media.append(media2person)
        meta.Session.add(media2person)
        meta.Session.commit()

        h.flash(_("added: %(person)s to %(medium)s") % {'person':person.name,
                                                        'medium':medium.title})
        return redirect(url(controller='medium', action='edit', id=id))
示例#6
0
    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))
示例#7
0
    def remove_from_media(self, id):
        item = meta.Session.query(model.PersonToMedia).get(id)
        meta.Session.delete(item)

        h.flash(_("removed: %(person)s from %(medium)s") % {'person':item.person.name,
                                                            'medium':item.medium.title})
        meta.Session.commit()
        return redirect(url(controller='medium', action='edit', id=item.medium.id))
示例#8
0
    def delete_many(self):
        for item in h.checkboxes(request, 'item_id_'):
            db_item = meta.find(model.Medium, item)
            meta.Session.delete(db_item)
            h.flash(_("deleted: %s") % db_item.title)

        meta.Session.commit()

        return redirect(url(controller='medium', action='index'))
示例#9
0
    def clear_persons(self, id):
        item = meta.find(model.Medium, id)
        cnt = 0
        for person2media in item.persons_to_media:
            meta.Session.delete(person2media)
            cnt += 1

        meta.Session.commit()
        h.flash(ungettext("removed %d person", "removed %d persons", cnt) % cnt)
        return redirect(url(controller="medium", action="edit", id=id))
示例#10
0
 def __query_actors__(self, id):
     """ id = media.id """
     query = meta.Session.query(model.MediaToAsin).filter(model.MediaToAsin.media_id == id)
     asins = map(lambda item: item.asin, query.all())
     log.debug("asins: %s" % asins)
     try:
         node = self.api.item_lookup(",".join(asins), ResponseGroup="Images,ItemAttributes")
     except Exception, ex:
         h.flash("%s: %s" % (type(ex), ex))
         return redirect(url(controller="medium", action="edit", id=id))
示例#11
0
    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))
示例#12
0
    def edit_borrower_post(self, id):
        record = meta.find(model.Borrower, id)
        record.first_name = request.params.get('first_name')
        record.last_name = request.params.get('last_name')
        record.email = request.params.get('email')
        record.updated_ts = datetime.now()
        meta.Session.add(record)
        meta.Session.commit()

        h.flash(_("updated: %s") % record)
        return redirect(url(controller='borrow', action='edit_borrower', id=id))
示例#13
0
 def edit_post(self, id):
     item = meta.Session.query(model.Person).get(id)
     if request.params.get("create_alias"):
         alias = model.PersonAlias()
         alias.name = item.name
         item.aliases.append(alias)
         
     item.name = request.params.get("name")
     
     meta.Session.commit()
     h.flash(_("updated: '%s'") % item.name)
     return redirect(url(controller='person', action='edit', id=id))
示例#14
0
 def delete_one(self, id):
     log.debug("delete_one(%s)" % id)
     db_item = meta.find(model.Medium, id)
     meta.Session.delete(db_item)
     meta.Session.commit()
     h.flash(_("deleted: %s") % db_item.title)
     ret_to = request.params.get('return_to')
     log.debug("ret_to: %s" % ret_to)
     if ret_to and ret_to != None:
         return redirect(str(request.params.get('return_to')))
     else:
         return redirect(url(controller='medium', action='index'))
示例#15
0
    def download_post(self, id):
        image_url = request.params.get('url')
        webFile = urllib.urlopen(image_url)
        buffer = StringIO()
        buffer.write(webFile.read())

        record = meta.Session.query(model.Medium).get(id)
        record.set_image_buffer(buffer)
        meta.Session.add(record)
        meta.Session.commit()
        
        h.flash(_("added image (%d bytes)") % buffer.len)
        return redirect(url(controller='medium', action='edit', id=id))
示例#16
0
    def set_view_options(self, type=None, tag=None):
        items_per_page = request.params.get('items_per_page')
        if not items_per_page or int(items_per_page) <= 0:
            h.flash(_("'Number of images' must be greater then null"))
            return redirect(url(controller='medium', action='list_gallery', type=type, tag=tag))

        items_per_page = int(items_per_page)
        h.flash(_("%d images will be display for now on") % items_per_page)
        session['items_per_page'] = items_per_page
        session.save()

        #~ h.flash("session, items_per_page: %s" % session['items_per_page'])
        return redirect(url(controller='medium', action='list_gallery', type=type, tag=tag))
示例#17
0
    def upload_post(self, id):
        myfile = request.POST['myfile']

        buffer = StringIO()
        buffer.write(myfile.file.read())

        record = meta.Session.query(model.Medium).get(id)
        record.set_image_buffer(buffer)
        
        meta.Session.add(record)
        meta.Session.commit()
        
        h.flash(_("added image (%d bytes)") % buffer.len)
        return redirect(url(controller='medium', action='edit', id=id))
示例#18
0
    def edit_post(self):
        id = request.params.get('id')
        item = meta.find(model.Medium, id)
        item.title = request.params.get('title')
        item.image_url = request.params.get('image_url')
        item.updated_ts = datetime.now()
        item.set_tagstring(request.params.get('tags'))
        meta.Session.add(item)
        meta.Session.commit()
        h.flash(_("updated: '%s'") % item.title)

        return_to = request.params.get('return_to')
        log.debug("return_to: %s" % return_to)
        if return_to:
            return redirect(str(return_to))
        else:
            return redirect(url(controller='medium', action='edit', id=id))
示例#19
0
    def next_without_image(self, id):
        query = meta.Session\
            .query(model.Medium)\
            .filter(model.Medium.image_data == None)\
            .filter(model.Medium.id < id)\
            .order_by(model.Medium.id.desc())

        medium = query.first()
        if not medium:
            h.flash(_("all media after this have an image"))
            return redirect(url(controller='medium', action='edit', id=id))

        return_to=request.params.get('return_to')
        if return_to:
            return redirect(url(controller='medium', action='edit', id=medium.id, return_to=request.params.get('return_to')))
        else:
            return redirect(url(controller='medium', action='edit', id=medium.id))
示例#20
0
    def checkin_post(self):
        #~ id = request.params.get('id')
        #~ borrower = meta.find(model.Borrower, id)
        for item in h.checkboxes(request, 'item_id_'):
            record = meta.Session.query(model.BorrowAct).get(item)
            if not record:
                raise Exception("could not find BorrowAct '%s'" % item)

            record.returned_ts = datetime.now()
            meta.Session.add(record)
            borrower_link = h.tmpl('borrow/snippets.mako', 'link_to_borrower')\
                             .render_unicode(item=record.borrower, h=h)
            medium_link = h.tmpl('medium/snippets.mako', 'link_to_medium')\
                           .render_unicode(item=record.medium, h=h)
            h.flash(_("%s has returned medium '%s'") % (borrower_link, medium_link),
                    escape=False)

        meta.Session.commit()
        return redirect(url(controller='borrow', action='index'))
示例#21
0
    def crop_image_post(self, id):
        crop = (int(request.params.get('x')),
                int(request.params.get('y')),
                int(request.params.get('x2')),
                int(request.params.get('y2')))

        item = meta.find(model.Medium, id)
        item.image_crop = crop
        item.updated_ts = datetime.now()
        meta.Session.add(item)
        meta.Session.commit()
        h.flash(_("updated: '%s'") % h.html_escape(item.title))

        return_to = request.params.get('return_to')
        log.debug("return_to: %s" % return_to)
        if return_to:
            return redirect(str(return_to))
        else:
            return redirect(url(controller='medium', action='edit', id=id))
示例#22
0
    def __query_images_post__(self, id, image_url):
        webFile = urllib.urlopen(image_url)
        buffer = StringIO()
        buffer.write(webFile.read())

        log.debug("id: %s" % id)
        item = meta.find(model.Medium, id)
        item.set_image_buffer(buffer)

        if item.image_data.len >= 65536:
            # 69198 defenitly fails. if the size is to blame.
            # i dont know :(
            h.flash(_("image is to big."))

            # dont do this, might be an infinite loop
            # ~ return redirect_to(controller='amazon', action='query_images')
            return redirect(url(controller="medium", action="edit", id=id))

        meta.Session.add(item)
        meta.Session.commit()
示例#23
0
    def search_post(self):
        query = request.params.get('query')
        if not query:
            h.flash(_("please enter search query"))
            return redirect(url(controller='search', action='index'))

        like_query = "%%%s%%" % query
        c.query = query

        media_query = meta.Session\
                          .query(model.Medium)\
                          .filter(or_(model.Medium.title.like(like_query),
                                      model.Medium.isbn.like(like_query)))
        c.media_page = paginate.Page(media_query)


        persons_query = meta.Session\
                          .query(model.Person)\
                          .filter(model.Person.name.like(like_query))
        c.persons_result = persons_query.all()
        return render('search/results.mako')
示例#24
0
    def map_to_medium_post(self):
        media_id = request.params.get("media_id", None)

        if request.params.get("next_page", None):
            page = int(request.params.get("page", 1))
            log.debug("page: %s" % page)

            selected_asins = ",".join(h.checkboxes(request, "item_id_"))
            log.debug("selected_asins: %s" % selected_asins)

            query = request.params.get("query")
            log.debug("query: %s" % query)

            return redirect(
                url(
                    controller="amazon",
                    action="map_to_medium",
                    id=media_id,
                    page=page + 1,
                    selected_asins=selected_asins,
                    query=query,
                )
            )

        medium = meta.Session.query(model.Medium).get(media_id)
        asins = []
        for item in h.checkboxes(request, "item_id_"):
            record = model.MediaToAsin()
            record.asin = item
            asins.append(item)
            medium.asins.append(record)

        h.flash(_("attached %s amazon ids to media id %s: %s") % (len(asins), media_id, ", ".join(asins)))

        meta.Session.commit()
        self.__query_actors__(media_id)
        if not medium.image_data:
            return redirect(url(controller="amazon", action="query_images", id=media_id, page=None))
        else:
            return redirect(url(controller="medium", action="edit", id=media_id, page=None))
示例#25
0
 def debug(self):
     log.debug("START DEBUG")
     #~ h.flash(u"testing \xc3\xa4")
     h.flash("<i>blah</i>", False)
     return redirect(url(controller='medium', action='index'))
示例#26
0
    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'))
示例#27
0
            add_persons(item, "Creator", medium, added_persons, meta.Session)
            add_persons(item, "Director", medium, added_persons, meta.Session)
            add_persons(item, "Manufacturer", medium, added_persons, meta.Session)

        meta.Session.commit()

        from pylons import config

        template_name = "person/snippets.mako"
        def_name = "link_to_person"
        template = config["pylons.app_globals"].mako_lookup.get_template(template_name).get_def(def_name)

        if len(added_persons) > 0:
            person_list = map(lambda item: template.render_unicode(item=item, h=h, c=c), added_persons)
            person_list = ", ".join(person_list)
            h.flash(_("added persons: %s") % person_list, escape=False)
        else:
            h.flash(_("no person added"))

    def query_images(self, id):
        """ show the user a selection of available images """

        query = meta.Session.query(model.MediaToAsin).filter(model.MediaToAsin.media_id == id)

        c.items = []
        asins = map(lambda item: item.asin, query.all())
        if len(asins) > 10:
            log.warn("number of asins is greater 10")
        node = self.api.item_lookup(",".join(asins), ResponseGroup="Images")
        c.items = node.Items.Item
        if len(c.items) == 1: