Пример #1
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
Пример #2
0
def open(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    thread = data['thread']
    sql = "UPDATE Thread set is_closed=0 where id=%s" % thread
    sql_update(sql)
    resp = {"code": 0, "response": {"thread": thread}}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type='application/json')
Пример #3
0
def update(request):
    data = request.body.decode("utf-8")
    data = json.loads(data)
    id = data["post"]
    message = data["message"]
    sql = "UPDATE Post set message = '%s' where id = %d" % (message, id)
    sql_update(sql)
    post = PostManager.get(id)
    resp = {"code": 0, "response": post.serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Пример #4
0
def update(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    slug = data['slug']
    thread = data['thread']
    message = data['message']
    sql = "UPDATE Thread set slug = '%s', message='%s' where id=%s" % (slug, message, thread)
    sql_update(sql)
    thread = ThreadManager.get(thread)
    resp = {"code": 0, "response": thread.serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type='application/json')
Пример #5
0
def remove(request):
    data = request.body.decode("utf-8")
    data = json.loads(data)
    id = data["post"]
    sql = "UPDATE Post set is_deleted = TRUE where id=%d" % id
    sql_update(sql)
    post = PostManager.get(id)
    sql = "UPDATE Thread set posts = posts - 1 where id = %d" % post.thread
    sql_update(sql)
    resp = {"code": 0, "response": {"post": id}}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Пример #6
0
def create(request):
    data = request.body.decode("utf-8")
    data = json.loads(data)
    try:
        post = PostManager.create(data)
        sql = "UPDATE Thread set posts = posts + 1 where id = %d" % post.thread
        sql_update(sql)
        resp = {"code": 0, "response": post.serialize()}
    except:
        resp = {"code": 3, "response": "Incorrect request"}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Пример #7
0
def updateProfile(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    email = data['user']
    about = data['about']
    name = data['name']
    sql = "UPDATE User set about = '%s', name = '%s' where email = '%s'" % (about, name, email)
    sql_update(sql)
    sql = "UPDATE Post set name = %s where user = '******'" % ("'" + name + "'" if name != None else "NULL", email)
    sql_update(sql)
    resp = {"code": 0, "response": UserManager.get(email).serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Пример #8
0
def restore(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    thread = data['thread']
    sql = "UPDATE Post set is_deleted=FALSE where thread=%s" % thread
    sql_update(sql)
    sql = "SELECT COUNT(*) FROM Post where thread=%s" % thread
    result = sql_select(sql, "one")
    count = result[0]
    sql = "UPDATE Thread set is_deleted=FALSE, posts=%d where id=%s" % (count, thread)
    sql_update(sql)
    resp = {"code": 0, "response": {"thread": thread}}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type='application/json')
Пример #9
0
def vote(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    thread = data['thread']
    vote = data['vote']
    if vote == -1:
        sql = "UPDATE Thread set dislikes = dislikes + 1 where id=%s" % thread
    else:
        sql = "UPDATE Thread set likes = likes + 1 where id=%s" % thread
    sql_update(sql)
    thread = ThreadManager.get(thread)
    resp = {"code": 0, "response": thread.serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type='application/json')
Пример #10
0
def vote(request):
    data = request.body.decode("utf-8")
    data = json.loads(data)
    post = data["post"]
    vote = data["vote"]
    if vote == -1:
        sql = "UPDATE Post set dislikes = dislikes + 1 where id=%s" % post
    else:
        sql = "UPDATE Post set likes = likes + 1 where id=%s" % post
    sql_update(sql)
    post = PostManager.get(post)
    resp = {"code": 0, "response": post.serialize()}
    resp = json.dumps(resp)
    return HttpResponse(resp, content_type="application/json")
Пример #11
0
def unsubscribe(request):
    data = request.body.decode('utf-8')
    data = json.loads(data)
    user = data['user']
    thread = data['thread']
    sql = "UPDATE Subscription set is_deleted = 1 where user='******' and thread=%s" % (user, thread)
    try:
        sql_update(sql)
    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')
Пример #12
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