Esempio n. 1
0
 def post(self):
     branchname = self.request.get('branch_name')
     edit_type = self.request.get('e_type')
     premise_type = self.request.get('p_type')
     content = self.request.get('form_content_0')
     ss = int(self.request.get('sscore_slider'))
     logging.info(self.request.POST)
     picture_url_0 = self.request.get('picture_url_0')
     if  picture_url_0 :
         field_storage = self.request.POST.multi['picture_url_0']
         mimetype = field_storage.type
         logging.info("Mimetype: {}".format(mimetype))
     user = self.current_user
     #branch_q = Branch.query(Branch.branch==branchname).fetch(1)
     #branch_key = branch_q.key()
     #branch_key = branch('key')
     #branch = Branch(parent=branch_key('Business'))
     #branch_key = branch.Key().
     #b_key = db.Key.from_path('Branch', branch)
     #tag_list1 = split(self.request.get('form_content_0'))
     tag_list=['one','two','three']
     step=0
     if premise_type == "contention":
         if edit_type == "" or edit_type == "0":  
             if self.logged_in:  
                 c = Contention()#branch_key=branch_q.key.get(), tags=tag_list )
                 c.content = content
                 c.sure_score = ss
                 c.branch_name = branchname
                 logging.info('Checking currently logged in user')
                 logging.info(self.current_user.name)
                 sessiony = self.auth.get_user_by_session()
                 c.author = self.current_user.name
                 c.author_id = sessiony['user_id']
                 c.put() 
                 user_ID = sessiony['user_id']
                 user_name = self.current_user.name
                 cid = c.key.id()
                 ## use gpoints function:
                 ## update_gpoints(user_id,user_name, branch_name,con_id,elem_id,elem_type,content,reply_user_id,reply_user_name,reply_elem_id,reply_elem_type,reply_content,category)
                 ## 
                 update_gpoints(user_ID,user_name, branchname,cid,"00","Contention",content,user_ID,user_name,"none","Con","none",1)
         elif edit_type == "1":
             contention_ID = self.request.get('c_id')
             c = Contention.get_by_id(int(contention_ID))
             if c.g_frames:
                 step = c.g_frames
             else:
                 step = 0                
             c.content = content
             c.g_frames = step + 1
             c.put()      
     self.redirect('/cv?con_id=%s' % c.key.id())
Esempio n. 2
0
    def post(self):
        branch_name = self.request.get('branch_name')
        edit_type = self.request.get('e_type')
        premise_type = self.request.get('p_type')
        logging.info(self.request.POST)
        picture_url_0 = self.request.get('picture_url_0')
        if picture_url_0:
            field_storage = self.request.POST.multi['picture_url_0']
            mimetype = field_storage.type
            logging.info("Mimetype: {}".format(mimetype))
        user = self.current_user
        branch_q = db.GqlQuery("SELECT * FROM Branch WHERE branch = :1",
                               branch_name)
        branch = branch_q.get()
        #branch = Branch(parent=branch_key('Business'))
        #branch_key = branch.Key().id()
        #b_key = db.Key.from_path('Branch', branch)
        #tag_list1 = split(self.request.get('form_content_0'))
        tag_list = ['one', 'two', 'three']
        step = 0
        if premise_type == "contention":
            if edit_type == "0":
                c = Contention(branch_key=branch, tags=tag_list)
                c.content = self.request.get('form_content_0')
                c.branch_name = branch_name
                if self.logged_in:
                    logging.info('Checking currently logged in user')
                    logging.info(self.current_user.name)
                    sessiony = self.auth.get_user_by_session()
                    c.author = self.current_user.name
                    c.author_id = sessiony['user_id']
                c.put()
                if picture_url_0 != '':
                    i = Images(branch_key=branch, contention_key=c)
                    i.image = db.Blob(picture_url_0)
                    i.element_type = "contention"
                    i.description = self.request.get('image_description_0')
                    if self.logged_in:
                        i.author = self.current_user.name
                        i.author_id = sessiony['user_id']
                    i.put()
                    c.image_id = i.key().id()
                    c.put()
            elif edit_type == "1":
                contention_ID = self.request.get('c_id')
                con = Contention.get_by_id(int(contention_ID))
                if con.g_frames:
                    step = con.g_frames
                else:
                    step = 0
                gframe = Elements(contention_key=con,
                                  element_type="contention",
                                  gframe=step,
                                  image_id=con.image_id,
                                  author=con.author,
                                  author_id=con.author_id,
                                  content=con.content)
                gframe.put()
                con.content = self.request.get('form_content_0')
                con.g_frames = step + 1
                if picture_url_0 != '':
                    i = Images(branch_key=branch, contention_key=c)
                    i.image = db.Blob(picture_url_0)
                    i.element_type = "contention"
                    i.description = self.request.get('image_description_0')
                    if self.logged_in:
                        sessiony = self.auth.get_user_by_session()
                        i.author = self.current_user.name
                        i.author_id = sessiony['user_id']
                    i.put()
                    con.image_id = i.key().id()
                con.put()
        if premise_type == "element":
            contention_ID = self.request.get('c_id')
            con = Contention.get_by_id(int(contention_ID))
            if edit_type == "0":
                c = Elements(contention_key=con, gframe=step)
                c.content = self.request.get('form_content_0')
                c.branch_name = branch_name
                if self.logged_in:
                    logging.info('Checking currently logged in user')
                    logging.info(self.current_user.name)
                    sessiony = self.auth.get_user_by_session()
                    c.author = self.current_user.name
                    c.author_id = sessiony['user_id']
                c.put()
                if picture_url_0 != '':
                    i = Images(branch_key=branch, contention_key=con)
                    i.image = db.Blob(picture_url_0)
                    i.element_type = "contention"
                    i.description = self.request.get('image_description_0')
                    if self.logged_in:
                        i.author = self.current_user.name
                        i.author_id = sessiony['user_id']
                    i.put()
                    c.image_id = i.key().id()
                    c.put()
                    con.g_frames = step + 1
                    con.put()
            elif edit_type == "1":
                contention_ID = self.request.get('c_id')
                con = Contention.get_by_id(int(contention_ID))
                gframe = Elements(contention_key=con,
                                  element_type="contention",
                                  gframe=step,
                                  image_id=con.image_id,
                                  author=con.author,
                                  author_id=con.author_id,
                                  content=con.content)
                gframe.put()
                con.content = self.request.get('form_content_0')
                con.g_frames = step + 1
                if picture_url_0 != '':
                    i = Images(branch_key=branch, contention_key=c)
                    i.image = db.Blob(picture_url_0)
                    i.element_type = "contention"
                    i.description = self.request.get('image_description_0')
                    if self.logged_in:
                        sessiony = self.auth.get_user_by_session()
                        i.author = self.current_user.name
                        i.author_id = sessiony['user_id']
                    i.put()
                    con.image_id = i.key().id()
                con.put()

        reasons = int(self.request.get('_reasons'))
        objections = int(self.request.get('_objections'))
        if reasons > 0:
            if edit_type == "0":
                for reas in range(1, reasons + 1):
                    pic = 'picture_url_' + str(reas)
                    pict = self.request.get(pic)
                    if premise_type == "contention":
                        r = Elements(contention_key=c,
                                     top_level=1,
                                     gframe=step)
                    if premise_type == "element":
                        r = Elements(contention_key=con,
                                     top_level=0,
                                     gframe=step,
                                     parent_id=c.key().id())
                    r.element_type = 'reason'
                    if pict != '':
                        i = Images(branch_key=branch, contention_key=c)
                        i.image = db.Blob(picture_url_0)
                        i.element_type = "contention"
                        i.description = self.request.get('image_description_0')
                        if self.logged_in:
                            sessiony = self.auth.get_user_by_session()
                            i.author = self.current_user.name
                            i.author_id = sessiony['user_id']
                        i.put()
                    #r.image_id=i.key().id()
                    rcon = 'form_reason_' + str(reas)
                    r.content = self.request.get(rcon)
                    r.branch_name = branch_name
                    if self.logged_in:
                        sessiony = self.auth.get_user_by_session()
                        r.author = self.current_user.name
                        r.author_id = sessiony['user_id']
                    r.put()

            elif edit_type == "1":
                for reas in range(1, reasons + 1):
                    pic = 'picture_url_' + str(reas)
                    pict = self.request.get(pic)
                    el_id = 'form_reason_' + str(reas) + '_'
                    e_id = self.request.get(el_id)
                    rcon = 'form_reason_' + str(reas)
                    r_content = self.request.get(rcon)
                    logging.info("this is test")
                    logging.info('form_reason_' + str(reas) + '_')
                    r = Elements.get_by_id(int(e_id))
                    if r_content != r.content:
                        if premise_type == "contention":
                            gframe = Elements(contention_key=con,
                                              element_type="reason",
                                              gframe=step,
                                              image_id=r.image_id,
                                              author=r.author,
                                              author_id=r.author_id,
                                              content=r.content)
                            gframe.put()
                            r.content = r_content
                            r.g_frame = con.g_frames
                        if premise_type == "element":
                            r = Elements(contention_key=con,
                                         parent_id=c.key().id())
                            r.top_level = 0
                        r.element_type = 'reason'
                        if pict != '':
                            i = Images(branch_key=branch, contention_key=c)
                            i.image = db.Blob(picture_url_0)
                            i.element_type = "contention"
                            i.description = self.request.get(
                                'image_description_0')
                            if self.logged_in:
                                sessiony = self.auth.get_user_by_session()
                                i.author = self.current_user.name
                                i.author_id = sessiony['user_id']
                            i.put()
                        #r.image_id=i.key().id()
                        rcon = 'form_reason_' + str(reas)
                        r.content = self.request.get(rcon)
                        r.branch_name = branch_name
                        if self.logged_in:
                            sessiony = self.auth.get_user_by_session()
                            r.author = self.current_user.name
                            r.author_id = sessiony['user_id']
                        r.put()
        if objections > 0:
            for objs in range(1, objections + 1):
                picobjs = objs + 5
                pic = 'picture_url_' + str(picobjs)
                pict = self.request.get(pic)
                o = Elements(contention_key=c)
                if premise_type == "contention":
                    o = Elements(contention_key=c)
                    o.top_level = 1
                if premise_type == "element":
                    o = Elements(contention_key=con, parent_id=c)
                    o.top_level = 0
                if pict != '':
                    o.image = db.Blob(urlfetch.Fetch(pict).content)
                ocon = 'form_objection_' + str(objs)
                o.content = self.request.get(ocon)
                o.branch_name = branch_name
                if self.logged_in:
                    sessiony = self.auth.get_user_by_session()
                    o.author = self.current_user.name
                    o.author_id = sessiony['user_id']
                o.put()

        self.redirect('/conv?con_id=%s' % c.key().id())