Example #1
0
fname = sys.argv[1]
Interface = DisplayModule(fname)

frame = Interface.iFrame(0)
tab = "    "
html = "<section id=\"tralf_data\" hidden>\n"
i = 0
while 1 == 1:
    html_line = (tab + "<div id=\"f" + str(i) + "\"" + "class=\"frame\">\n" +
                 tab + tab + "<div class=\"edit_loc\">" + str(frame[0]) +
                 "</div>\n" + tab + tab + "<div class=\"date\">" +
                 str(frame[2]) + "</div>\n" + tab + tab +
                 "<div class=\"time\">" + str(frame[3]) + "</div>\n")
    cont = frame[1].split('\n')
    html_cont = ""
    for line in cont:
        html_cont += HTML_CONV.plaintext2html(line) + "<br>"
    html_cont += "\n"
    html_line += (tab + tab + "<div class=\"content\">" + html_cont + tab +
                  tab + "</div>\n" + tab + "</div>\n")

    html += html_line
    i += 1
    try:
        frame = Interface.nFrame()
    except EOFError as e:
        break

html += "</section>"
print html
Example #2
0

frame = Interface.iFrame(0)
tab = "    "
html = "<section id=\"tralf_data\" hidden>\n"
i = 0
while 1==1:
    html_line = (tab + "<div id=\"f" + str(i) + "\"" +
                 "class=\"frame\">\n" +
                 tab + tab + "<div class=\"edit_loc\">" +
                 str(frame[0]) + "</div>\n" +
                 tab + tab + "<div class=\"date\">" +
                 str(frame[2]) + "</div>\n" +
                 tab + tab + "<div class=\"time\">" +
                 str(frame[3]) + "</div>\n")
    cont = frame[1].split('\n')
    html_cont = ""
    for line in cont: html_cont += HTML_CONV.plaintext2html(line) + "<br>"
    html_cont += "\n"
    html_line += (tab + tab + "<div class=\"content\">" +
                 html_cont + tab + tab + "</div>\n" +
                 tab + "</div>\n")

    html += html_line
    i += 1
    try: frame = Interface.nFrame()
    except EOFError as e: break

html += "</section>"
print html
def post_upload_callback(sender, **kwargs):
    for key in kwargs.iterkeys():
        print key

    if kwargs['file'].extension == ".zip":
        
        thefile = kwargs['file'] 

        # Convert file and dir into absolute paths
        print settings.MEDIA_ROOT
        print settings.FILEBROWSER_DIRECTORY
        fullpath = os.path.join(settings.MEDIA_ROOT,settings.FILEBROWSER_DIRECTORY,str(thefile))
        print "full path: "+fullpath

        dirname = os.path.dirname(fullpath)
        try:
            # Get a real Python file handle on the uploaded file
            fullpathhandle = open(fullpath, 'r') 
            zfobj = zipfile.ZipFile(fullpathhandle)

            cur_dir = os.getcwd()
            os.chdir(dirname)
            zfobj.extractall()
            os.chdir(cur_dir)

        except:
            e = sys.exc_info()[1] 
            print e

        # Now try and delete the uploaded .zip file  
        try:
            os.remove(fullpath)
        except:
            pass
      
        file_path = os.path.splitext(fullpath)[0]
        file_name = os.path.basename(file_path)
        username = kwargs['request'].META['USER']
        player = Player(username = username, question="Do you like "+file_name+" ?",  pub_date=datetime.now(),  file_name=file_name, frame_num_start=0, frame_num_stop=0)
        player.save() 
        choice1 = Choice(player=player, choice="like", votes=0)
        choice1.save()
   
        player_id = player.id
        try:
            Interface = DjangoInterface(file_path)
        except:
            e = sys.exc_info()[1] 
            print e
      
        mode = 1
        u_input = 0
        print_height = 30
        disp = Interface.refresh()
        frame_id_start = None
        frame_id_stop = None
        count = 0
        temp = None
        while disp != None:
            count += 1
            temp = disp
            frame_line = disp[0]
            frame_text = disp[1]
            frame_dtime = disp[2]
            frame_time = disp[3] 
            [year, month, day] = frame_dtime.split('-')
            [hour, minute, second] = frame_time.split(':')
            frame_text = HTML_CONV.plaintext2html(frame_text)
            print "frame dtime:",frame_dtime
            print "frame time:",frame_time
            print "year:",year
            print "month:", month
            print "day:",day
            print "player?",player_id
           
            frame = Frame(player=player, 
                            line_num_mod=int(frame_line),
                            frame=frame_text,
                            commit_dtime=datetime(int(year), int(month), int(day), int(hour), int(minute), int(second)))
   
            frame.save()    
    
            frame_id_stop = frame.id
            if count == 1:
                frame_id_start = frame.id                
    
            disp = Interface.nFrameButton()
        print "frame start num: ",frame_id_start
        print "frame stop num: ",frame_id_stop 
        player.frame_num_start = frame_id_start
        player.frame_num_stop = frame_id_stop
    
        player.save()
        player_id = player.id
        file_dirname = os.path.dirname(file_path)
        folder_path = file_dirname + "/." + file_name + "/"
        try:
            os.remove(folder_path)
        except:
            pass
        CurrentPlayer.g(player_id)