Example #1
0
    def list_files(self):
        # Taken from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/170242
        def caseinsensitive_sort(stringList):
            """case-insensitive string comparison sort
            doesn't do locale-specific compare
            though that would be a nice addition
            usage: stringList = caseinsensitive_sort(stringList)"""

            tupleList = [(x.lower(), x) for x in stringList]
            tupleList.sort()
            return [x[1] for x in tupleList]

        directory = get_path('public_path')
        download_path = get_path('public_html')
        current_path = "/"
        try:
            if request.GET['folder'] is not None:
                directory += request.GET['folder']
                download_path += request.GET['folder']
                current_path = request.GET['folder']
        except KeyError:
            download_path += '/'

        defaults = dict(request.POST)
        if defaults:
            try:
                if request.POST['folder'] is not None:
                    os.mkdir(directory + request.POST['folder'])
            except KeyError:
                h.flash("Error creating folder. Check file permissions.", 'error')
            else:
                h.flash("Folder Created")


        files = []
        folders = []
        for filename in os.listdir(directory):
            if os.path.isdir(directory + "/" + filename):
                folders.append(filename + "/")
            else:
                files.append(filename)

        c.file_list = caseinsensitive_sort(files)
        c.folder_list = caseinsensitive_sort(folders)
        c.current_path = current_path
        c.download_path = download_path
        c.no_theme = False
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = True
        return render('/db_content/list_files.mako')
Example #2
0
    def list_files(self):
        # Taken from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/170242
        def caseinsensitive_sort(stringList):
            """case-insensitive string comparison sort
            doesn't do locale-specific compare
            though that would be a nice addition
            usage: stringList = caseinsensitive_sort(stringList)"""

            tupleList = [(x.lower(), x) for x in stringList]
            tupleList.sort()
            return [x[1] for x in tupleList]

        directory = get_path('public_path')
        download_path = get_path('public_html')
        current_path = "/"
        try:
            if request.GET['folder'] is not None:
                directory += request.GET['folder']
                download_path += request.GET['folder']
                current_path = request.GET['folder']
        except KeyError:
            download_path += '/'

        defaults = dict(request.POST)
        if defaults:
            try:
                if request.POST['folder'] is not None:
                    os.mkdir(directory + request.POST['folder'])
            except KeyError:
                h.flash("Error creating folder. Check file permissions.",
                        'error')
            else:
                h.flash("Folder Created")

        files = []
        folders = []
        for filename in os.listdir(directory):
            if os.path.isdir(directory + "/" + filename):
                folders.append(filename + "/")
            else:
                files.append(filename)

        c.file_list = caseinsensitive_sort(files)
        c.folder_list = caseinsensitive_sort(folders)
        c.current_path = current_path
        c.download_path = download_path
        c.no_theme = False
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = True
        return render('/db_content/list_files.mako')
Example #3
0
    def delete_folder(self):
        try:
            if request.GET['folder'] is not None:
                c.folder += request.GET['folder']
                c.current_folder += request.GET['current_path']
        except KeyError:
            abort(404)

        directory = get_path('public_path')
        defaults = dict(request.POST)
        if defaults:
            c.no_theme = 'false'
            if request.GET.has_key('no_theme'):
                if request.GET['no_theme'] == 'true':
                    c.no_theme = 'true'
            try:
                os.rmdir(directory + c.folder)
            except OSError:
                h.flash("Can not delete. The folder contains items.", 'error')
                redirect_to(action="list_files",
                            folder=c.current_folder,
                            no_theme=c.no_theme)
            h.flash("Folder deleted.")
            redirect_to(action="list_files",
                        folder=c.current_folder,
                        no_theme=c.no_theme)
        c.no_theme = False
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = True
        return render('/db_content/delete_folder.mako')
Example #4
0
    def delete_file(self):
        try:
            if request.GET['file'] is not None:
                c.file += request.GET['file']
                c.current_folder += request.GET['folder']
        except KeyError:
            abort(404)

        directory = get_path('public_path')
        defaults = dict(request.POST)
        if defaults:
            os.remove(directory + c.file)
            h.flash("File Removed")
            c.no_theme = 'false'
            if request.GET.has_key('no_theme'):
                if request.GET['no_theme'] == 'true':
                    c.no_theme = 'true'
            redirect_to(action="list_files",
                        folder=c.current_folder,
                        no_theme=c.no_theme)
        c.no_theme = False
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = True
        return render('/db_content/delete_file.mako')
Example #5
0
    def delete_folder(self):
        try:
            if request.GET['folder'] is not None:
                c.folder += request.GET['folder']
                c.current_folder += request.GET['current_path']
        except KeyError:
           abort(404)

        directory = get_path('public_path')
        defaults = dict(request.POST)
        if defaults:
            c.no_theme = 'false'
            if request.GET.has_key('no_theme'):
                if request.GET['no_theme'] == 'true':
                    c.no_theme = 'true'
            try:
                os.rmdir(directory + c.folder)
            except OSError:
                h.flash("Can not delete. The folder contains items.", 'error')
                redirect_to(action="list_files", folder=c.current_folder, no_theme = c.no_theme)
            h.flash("Folder deleted.")
            redirect_to(action="list_files", folder=c.current_folder, no_theme = c.no_theme)
        c.no_theme = False
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = True
        return render('/db_content/delete_folder.mako')
Example #6
0
    def delete_folder(self):
        try:
            c.folder = request.GET['folder']
            c.current_folder = request.GET['current_path']
        except KeyError:
            abort(404)

        directory = get_path('public_path')
        c.no_theme = request.GET.get('no_theme') == 'true'
        return render('/db_content/delete_folder.mako')
Example #7
0
    def delete_folder(self):
        try:
            c.folder = request.GET['folder']
            c.current_folder = request.GET['current_path']
        except KeyError:
           abort(404)

        directory = get_path('public_path')
        c.no_theme = request.GET.get('no_theme') == 'true'
        return render('/db_content/delete_folder.mako')
Example #8
0
    def _upload(self):
        c.current_folder = request.GET.get('folder', '/')
        directory = get_path('public_path') + c.current_folder

        if hasattr(request.POST['myfile'], 'value'):
            file_data = request.POST['myfile'].value
            fp = open(directory + request.POST['myfile'].filename,'wb')
            fp.write(file_data)
            fp.close()
            h.flash("File Uploaded.")
        c.no_theme = request.GET.get('no_theme') == 'true'
        redirect_to(action="list_files", folder=c.current_folder, no_theme=c.no_theme)
Example #9
0
    def upload(self):
        directory = get_path('public_path')
        try:
            if request.GET['folder'] is not None:
                directory += request.GET['folder']
                c.current_folder = request.GET['folder']
        except KeyError:
            directory = get_path('public_path') + "/"
            c.current_folder = '/'

        if hasattr(request.POST['myfile'], 'value'):
            file_data = request.POST['myfile'].value
            fp = open(directory + request.POST['myfile'].filename,'wb')
            fp.write(file_data)
            fp.close()
            h.flash("File Uploaded.")
        c.no_theme = 'false'
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = 'true'
        redirect_to(action="list_files", folder=c.current_folder, no_theme=c.no_theme)
Example #10
0
    def pdf(self, id):
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())):
            # Raise a no_auth error
            h.auth.no_role()

        c.invoice = Invoice.find_by_id(id, True)
        xml_s = render('/invoice/pdf.mako')

        xsl_f = get_path('zk_root') + '/zkpylons/templates/invoice/pdf.xsl'
        pdf_data = pdfgen.generate_pdf(xml_s, xsl_f)

        filename = Config.get('event_shortname') + '_' + str(c.invoice.id) + '.pdf'
        return pdfgen.wrap_pdf_response(pdf_data, filename)
Example #11
0
    def _upload(self):
        c.current_folder = request.GET.get('folder', '/')
        directory = get_path('public_path') + c.current_folder

        if hasattr(request.POST['myfile'], 'value'):
            file_data = request.POST['myfile'].value
            fp = open(directory + request.POST['myfile'].filename, 'wb')
            fp.write(file_data)
            fp.close()
            h.flash("File Uploaded.")
        c.no_theme = request.GET.get('no_theme') == 'true'
        redirect_to(action="list_files",
                    folder=c.current_folder,
                    no_theme=c.no_theme)
Example #12
0
    def upload(self):
        directory = get_path('public_path')
        try:
            if request.GET['folder'] is not None:
                directory += request.GET['folder']
                c.current_folder = request.GET['folder']
        except KeyError:
            directory = get_path('public_path') + "/"
            c.current_folder = '/'

        if hasattr(request.POST['myfile'], 'value'):
            file_data = request.POST['myfile'].value
            fp = open(directory + request.POST['myfile'].filename, 'wb')
            fp.write(file_data)
            fp.close()
            h.flash("File Uploaded.")
        c.no_theme = 'false'
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = 'true'
        redirect_to(action="list_files",
                    folder=c.current_folder,
                    no_theme=c.no_theme)
Example #13
0
def featured_image(title, big=False):
    """
    Returns img src If an image exists in /public/featured/ with the same
    computer-friendly title as a news item it becomes featured down the left If
    big == True then find a directory
    """

    fileprefix = get_path('news_fileprefix')
    htmlprefix = get_path('news_htmlprefix')

    if big:
        # look for folder feature
        if os.path.isdir(fileprefix + "/" + computer_title(title)):
            return htmlprefix + "/" + computer_title(title) + "/"
        else:
            return False
    else:
        # look for image
        if os.path.isfile(fileprefix + "/" + computer_title(title) + ".png"):
            return htmlprefix + "/" + computer_title(title) + ".png"
        else:
            return False

    return False
Example #14
0
def featured_image(title, big = False):
    """
    Returns img src If an image exists in /public/featured/ with the same
    computer-friendly title as a news item it becomes featured down the left If
    big == True then find a directory
    """

    fileprefix = get_path('news_fileprefix')
    htmlprefix = get_path('news_htmlprefix')

    if big:
        # look for folder feature
        if os.path.isdir(fileprefix + "/" + computer_title(title)):
            return htmlprefix + "/" + computer_title(title) + "/"
        else:
            return False
    else:
        # look for image
        if os.path.isfile(fileprefix + "/" + computer_title(title) + ".png"):
            return htmlprefix + "/" + computer_title(title) + ".png"
        else:
            return False

    return False
Example #15
0
def slideshow(set, small=None):
    """
    Generate a slideshow of a set of images, randomly selecting one to
    show first, unless a file is specified.
    """
    try:
        if small == None or small == "":
            # Randomly select a smaller image, set the width of the div to be
            # the width of image.
            small = random.choice(glob(get_path('public_path') + "/images/" + set + "/small/*"))
        else:
            small = get_path('public_path') + "/images/" + set + "/small/" + small

        output = "<div class=\"slideshow\" id=\"%s\" style=\"width: %dpx\">" % (set, int(Image.open(small).size[0]))
        small = os.path.basename(small)

        # Optionally load up some captions for the images.
        caption = dict()
        caption_file = get_path('public_path') + "/images/" + set + "/captions"
        if os.path.exists(caption_file):
            file = open(caption_file, 'r')
            captions = file.readlines()

            # Assign captions to a lookup table
            for cap in captions:
                str = cap.partition(':')
                caption[str[0]] = str[2]

        # Load up all the images in the set directory.
        files = glob(get_path('public_path') + "/images/" + set + '/*')
        for file in files:
            if os.path.isfile(file):
                short_file = os.path.basename(file)
                if short_file == 'captions':
                    continue

                output += "<a href=\"" + get_path('public_html') + "/images/" + set + "/" + short_file + "\" rel=\"lightbox[" + set + "]\""
                if short_file in caption:
                    output += " title=\"" + caption[short_file] + "\""
                output += ">"

                # If we're looking at the small one we've picked, display
                # it as well.
                if short_file == small:
                    output += "<img src=\"" +  get_path('public_html') + "/images/" + set + "/small/" + short_file + "\">"

                    # If there are more than one image in the slideshow
                    # then also display "more...".
                    if files.__len__() > 1:
                        output += '<div class="more">More images...</div>'
                output += "</a>\n";
        output += "</div>\n"
        return output

    except IndexError:
        return "no images found"
Example #16
0
    def _delete_folder(self):
        try:
            c.folder = request.GET['folder']
            c.current_folder = request.GET['current_path']
        except KeyError:
           abort(404)

        c.no_theme = request.GET.get('no_theme') == 'true'

        try:
            os.rmdir(get_path('public_path') + c.folder)
        except OSError:
            h.flash("Can not delete. The folder contains items.", 'error')
        else:
            h.flash("Folder deleted.")

        redirect_to(action="list_files", folder=c.current_folder, no_theme = c.no_theme)
Example #17
0
    def _delete_file(self):
        try:
            c.file = request.GET['file']
            c.current_folder = request.GET['folder']
        except KeyError:
           abort(404)

        c.no_theme = request.GET.get('no_theme') == 'true'

        try:
            os.remove(get_path('public_path') + c.file)
        except OSError:
            h.flash("Could not delete file")
        else:
            h.flash("File Removed")

        redirect_to(action="list_files", folder=c.current_folder, no_theme = c.no_theme)
Example #18
0
    def _delete_file(self):
        try:
            c.file = request.GET['file']
            c.current_folder = request.GET['folder']
        except KeyError:
            abort(404)

        c.no_theme = request.GET.get('no_theme') == 'true'

        try:
            os.remove(get_path('public_path') + c.file)
        except OSError:
            h.flash("Could not delete file")
        else:
            h.flash("File Removed")

        redirect_to(action="list_files",
                    folder=c.current_folder,
                    no_theme=c.no_theme)
Example #19
0
    def _delete_folder(self):
        try:
            c.folder = request.GET['folder']
            c.current_folder = request.GET['current_path']
        except KeyError:
            abort(404)

        c.no_theme = request.GET.get('no_theme') == 'true'

        try:
            os.rmdir(get_path('public_path') + c.folder)
        except OSError:
            h.flash("Can not delete. The folder contains items.", 'error')
        else:
            h.flash("Folder deleted.")

        redirect_to(action="list_files",
                    folder=c.current_folder,
                    no_theme=c.no_theme)
Example #20
0
    def delete_file(self):
        try:
            if request.GET['file'] is not None:
                c.file += request.GET['file']
                c.current_folder += request.GET['folder']
        except KeyError:
           abort(404)

        directory = get_path('public_path')
        defaults = dict(request.POST)
        if defaults:
            os.remove(directory + c.file)
            h.flash("File Removed")
            c.no_theme = 'false'
            if request.GET.has_key('no_theme'):
                if request.GET['no_theme'] == 'true':
                    c.no_theme = 'true'
            redirect_to(action="list_files", folder=c.current_folder, no_theme = c.no_theme)
        c.no_theme = False
        if request.GET.has_key('no_theme'):
            if request.GET['no_theme'] == 'true':
                c.no_theme = True
        return render('/db_content/delete_file.mako')
Example #21
0
 def get_db_dir(cls):
     db_dir = zkpylons_config.get_path('photocomp_path')
     if not os.path.exists(db_dir):
         os.mkdir(db_dir, 0777)
     return db_dir
Example #22
0
 def get_db_dir(cls):
     db_dir = zkpylons_config.get_path('photocomp_path')
     if not os.path.exists(db_dir):
         os.mkdir(db_dir, 0777)
     return db_dir
Example #23
0
def slideshow(set, small=None):
    """
    Generate a slideshow of a set of images, randomly selecting one to
    show first, unless a file is specified.
    """
    try:
        if small == None or small == "":
            # Randomly select a smaller image, set the width of the div to be
            # the width of image.
            small = random.choice(
                glob(get_path('public_path') + "/images/" + set + "/small/*"))
        else:
            small = get_path(
                'public_path') + "/images/" + set + "/small/" + small

        output = "<div class=\"slideshow\" id=\"%s\" style=\"width: %dpx\">" % (
            set, int(Image.open(small).size[0]))
        small = os.path.basename(small)

        # Optionally load up some captions for the images.
        caption = dict()
        caption_file = get_path('public_path') + "/images/" + set + "/captions"
        if os.path.exists(caption_file):
            file = open(caption_file, 'r')
            captions = file.readlines()

            # Assign captions to a lookup table
            for cap in captions:
                str = cap.partition(':')
                caption[str[0]] = str[2]

        # Load up all the images in the set directory.
        files = glob(get_path('public_path') + "/images/" + set + '/*')
        for file in files:
            if os.path.isfile(file):
                short_file = os.path.basename(file)
                if short_file == 'captions':
                    continue

                output += "<a href=\"" + get_path(
                    'public_html'
                ) + "/images/" + set + "/" + short_file + "\" rel=\"lightbox[" + set + "]\""
                if short_file in caption:
                    output += " title=\"" + caption[short_file] + "\""
                output += ">"

                # If we're looking at the small one we've picked, display
                # it as well.
                if short_file == small:
                    output += "<img src=\"" + get_path(
                        'public_html'
                    ) + "/images/" + set + "/small/" + short_file + "\">"

                    # If there are more than one image in the slideshow
                    # then also display "more...".
                    if files.__len__() > 1:
                        output += '<div class="more">More images...</div>'
                output += "</a>\n"
        output += "</div>\n"
        return output

    except IndexError:
        return "no images found"