Ejemplo n.º 1
0
def subscribe(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    user = data['user']
    thread = data['thread']
    sql = "INSERT INTO Subscription(user,thread) VALUES('%s',%s)" % (user, thread)
    try:
        sql_insert(sql, 'User')
    except:
        resp = {"code": 3, "response": "User or thread doesn't exist"}
        resp = json.dumps(resp)
        return HttpResponse(resp, content_type='application/json')
    resp = {"code": 0, "response": {"thread": data['thread'], "user": data['user']}}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type='application/json')
Ejemplo n.º 2
0
    def save(self):
        if self.id == None:

            sql = "INSERT INTO User(username,about,name,email,is_anonymous) VALUES ("
            isAnonymous = 0
            if self.is_anonymous == True:
                isAnonymous = 1
            if self.username == None:
                sql += 'NULL, '
            else:
                sql += "'" + self.username + "', "
            if self.about == None:
                sql += 'NULL, '
            else:
                sql += "'" + self.about + "', "
            if self.name == None:
                sql += 'NULL, '
            else:
                sql += "'" + self.name + "', "
            sql += "'" + self.email + "', "
            sql += "'" + str(isAnonymous) + "')"

            id = sql_insert(sql, 'User')

            self.id = id

            return self
        else:
            sql = "UPDATE User set about = '%s', name = '%s' where email = '%s'" % (self.about,self.name,self.email)
            sql_update(sql)
            return self
Ejemplo n.º 3
0
 def save(self):
     if self.id == None:
         sql = "INSERT INTO Thread(forum,user,title,message,slug,date,is_closed,is_deleted) VALUES("
         sql += "'%s', '%s', '%s', '%s', '%s', '%s', %d, %d)" % (self.forum, self.user, self.title, self.message, self.slug, self.date, self.is_closed, self.is_deleted)
         id = sql_insert(sql, 'User')
         self.id = id
         return self
     else:
         return self
Ejemplo n.º 4
0
    def save(self):
        if self.id == None:
            sql = "INSERT INTO Forum(name,short_name,user) VALUES ("
            if self.name is None:
                sql += "NULL, "
            else:
                sql += "'" + self.name + "', "

            sql += "'" + self.short_name + "', "
            sql += "'" + self.user + "')"
            id = sql_insert(sql, "User")
            self.id = id
            return self
        else:
            return self
Ejemplo n.º 5
0
def unfollow(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    follower = data['follower']
    followee = data['followee']
    sql = "Update Follow set is_deleted=1 where follower='%s' and followee='%s'" % (follower, followee)
    try:
        id = sql_insert(sql, 'Follow')
    except:
        resp = {"code": 3, "response": "One of this users doesn't exist"}
        resp = json.dumps(resp)
        return HttpResponse(resp, content_type="application/json")
    resp = {"code": 0, "response": UserManager.get(follower).serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Ejemplo n.º 6
0
def follow(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    follower = data['follower']
    followee = data['followee']
    sql = 'INSERT INTO Follow(follower,followee,is_deleted) VALUES('
    sql += "'" + follower + "', "
    sql += "'" + followee + "', "
    sql += '0)'
    try:
        id = sql_insert(sql, 'Follow')
    except:
        resp = {"code": 3, "response": "One of this users doesn't exist"}
        resp = json.dumps(resp)
        return HttpResponse(resp, content_type="application/json")
    resp = {"code": 0, "response": UserManager.get(follower).serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Ejemplo n.º 7
0
 def save(self):
     if self.id == None:
         user = UserManager.get(self.user)
         sql = "INSERT INTO Post(user,thread,forum,message,date,is_approved,is_highlighted,is_edited,is_spam,is_deleted,path,user_id,name) VALUES(" \
               "'%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', %d, %s)" % (
                   self.user, self.thread, self.forum, self.message, self.date, self.is_approved,
                   self.is_highlighted,
                   self.is_edited, self.is_spam, self.is_deleted, self.path, user.id,"'" + user.name + "'" if user.name != None else "NULL")
         id = sql_insert(sql, 'User')
         self.id = id
         if self.path == None:
             sql = "UPDATE Post set path = '%s' where id = %s" % (Converter.from_dec_to_hex(int(self.id)), self.id)
             sql_update(sql)
             self.path = self.id
         else:
             sql = "UPDATE Post set path = '%s' where id = %s" % (self.path+Converter.from_dec_to_hex(int(self.id)), self.id)
             sql_update(sql)
             self.path = self.path+str(self.id)
         return self
     else:
         return self