Commits

Brendan Howell  committed fcc0480

adding edit vs new chunk bits

  • Participants
  • Parent commits 045acf6

Comments (0)

Files changed (3)

File src/excode.db

Binary file modified.
         rnd = corp.current_round_index
         round = sqlsession.query(Round).filter(
             and_(Round.corpus==corp, Round.round_index==rnd)).first()
+
+        #TODO: is this an edit or a new chunk
         
         if chunkid:
             chunk = sqlsession.query(Chunk).filter(Chunk.id==chunkid).first()
         else:
-            #TODO: create new chunk and pass the id 
-            chunk = Chunk("", author, corp, rnd)
+            ant = sqlsession.query(Chunk).filter(Chunk.antecedent == None).first()
+            name = cherrypy.session.get(USER_KEY)
+            author = sqlsession.query(User).filter(User.name==name).first()
+            chunk = Chunk("", author, corp, round)
+
+            if ant:
+                chunk.antecedent = ant
+
             sqlsession.add(chunk)
             sqlsession.flush()
-            #TODO: set lastchunk to query antecedent
-            pass
 
         if corp.current_round_index < 2:
             lasttext = "no text written yet"
         else:
-            lastround = sqlsession.query(Round).filter(
-                and_(Round.session==sess, Round.round_index==(
-                sess.current_round_index-1))).first()
-
-            lastchunk = sqlsession.query(Chunk).filter(
-                and_(Chunk.round==lastround, Chunk.selected==True)).first()
-
+            lasttext = chunk.antecedent.text
             
         page = Template(file=template)
         page.corpus = corp
         #TODO: find next chunk based on descendent
         page.nextchunk = None
         
+        sqlsession.commit()
+
         return unicode(page)
 
 
     def addchunk(self, text, cid, chunkid):
 
         #TODO: add logic to stop naughty hackers from submitting twice/round
-        #TODO: add refs to antecedent
-        #TODO: add git tracking of chunk revisions
+        #      also don't allow edits outside of current round participants
         sqlsession = self.SqlSession()
         corpus = sqlsession.query(Corpus).filter(Corpus.id==cid).first()
         rnd = corpus.current_round_index
         name = cherrypy.session.get(USER_KEY)
         author = sqlsession.query(User).filter(User.name==name).first()
         
-        chunk = Chunk(text, author, corpus, round)
+        chunk = sqlsession.query(Chunk).filter(Chunk.id==chunkid).first()
+        chunk.text = text
+        #TODO: add git tracking of chunk revisions
+        #chunk = Chunk(text, author, corpus, round)
         
-        sqlsession.add(chunk)
+        #sqlsession.add(chunk)
         sqlsession.commit()
 
         raise cherrypy.HTTPRedirect("/wait?cid="+cid+"&round="+str(rnd))

File src/templates/corpus.tmpl

         <textarea name="text" style="width:100%">
         </textarea>
         <input type="hidden" name="cid" value="$corpus.id" />
+        <input type="hidden" name="chunkid" value="$chunkid" />
         <input type="submit" value="Submit" />
     </form>
     #if $nextchunk