Esempio n. 1
0
 def validate(self, data):
     token = data.get("token", None)
     id = data.get("id", None)
     action = data.get("action", "view")
     status, user = authenticateUser(token)
     if status:
         tag = Tags.objects.filter(id=id, created_by=user).first()
         if tag:
             response = success_response()
             if action == "view":
                 response['id'] = tag.id
                 response['tag_string'] = tag.tag_string
                 response["message"] = "successfull"
             elif action == "update":
                 tag_string = data.get("tag_string")
                 if tag_string:
                     tag.tag_string = tag_string
                     tag.save()
                 else:
                     response = no_success_response()
                     response["message"] = "Not valid tag string provided for updating the tag"
             else:
                 response = no_success_response()
                 response["message"] = "Not valid action given"
         else:
             response = no_success_response()
             response['message'] = "Not Valid Tag Found"
     else:
         response = no_success_response()
         response['message'] = "Login into the account to view Tag List"
     response['action'] = action
     response['token'] = token
     response['id'] = id
     return response
Esempio n. 2
0
 def validate(self, data):
     token = data.get("token", None)
     status, user = authenticateUser(token)
     if status:
         tags = []
         for p in Tags.objects.filter(created_by=user):
             tags.append(p.embed())
         response = success_response()
         response['results'] = tags
     else:
         response = no_success_response()
         response['message'] = "Login into the account to view Tag List"
     response['token'] = token
     return response
Esempio n. 3
0
 def validate(self, data):
     token = data.get("token", None)
     user = None
     #validate token
     status, user = authenticateUser(token)
     if status:
         user.ifLogged = False
         user.token = ""
         user.save()
         data = success_response()
         data['message'] = "User is logged out successfully"
         data['token'] = ""
         return data
     else:
         user['message'] = "Not a valid token found"
         user['token'] = ""
         return user
Esempio n. 4
0
    def validate(self, data):
        token = data.get("token")
        post_message = data.get("post_message", None)
        post_image = data.get("post_image", None)
        post_tag = data.get("post_tag", None)
        # validate the user detail
        status, user = authenticateUser(token)
        if status:
            valid_tags = True
            valid_tags_obj = []
            if post_tag:
                for tag in post_tag.split(","):
                    tag = Tags.objects.filter(tag_string=tag,
                                              created_by=user).first()
                    if not tag:
                        valid_tags = False
                        break
                    else:
                        valid_tags_obj.append(tag)

                if not valid_tags:
                    # implies not valid tag has been used and break the loop and reject the post creating
                    response = no_success_response()
                    response['message'] = "Not valid tag has been used"
                    response['token'] = token
                    response['post_tag'] = post_tag
                    response['post_message'] = post_tag
                    response['post_image'] = post_image
                    return response

            post = Posts()
            post.create(post_message, post_image, user)
            for tag in valid_tags_obj:
                tag_m = TagManager()
                tag_m.create(tag, post)
            response = success_response()
        else:
            response = user

        response['post_tag'] = post_tag
        response['post_message'] = post_message
        response['post_image'] = post_image
        response['token'] = token
        return response
Esempio n. 5
0
 def validate(self, data):
     token = data.get("token", None)
     id = data.get("id", None)
     status, user = authenticateUser(token)
     if status:
         tag = Tags.objects.filter(id=id, created_by=user).first()
         if tag:
             tag.delete()
             response = success_response()
             response['message'] = "Deleted Tag successfully"
         else:
             response = no_success_response()
             response['message'] = "Not Valid Tag Found"
     else:
         response = no_success_response()
         response['message'] = "Login into the account to delete the Tag"
     response['token'] = token
     response['id'] = id
     return response
Esempio n. 6
0
 def validate(self, data):
     tag_string = data.get("tag_string", None)
     token = data.get("token", None)
     # validate user
     status, user = authenticateUser(token)
     if status:
         tag = Tags()
         try:
             tag.create(tag_string=tag_string, user=user)
             response = success_response()
             response['message'] = "Tags has been saved successfully"
         except IntegrityError:
             response = no_success_response()
             response['message'] = "Tag '%s' already exists" % (tag_string)
     else:
         response = user
         response['token'] = token
     response['tag_string'] = tag_string
     response['token'] = token
     return response
Esempio n. 7
0
 def validate(self, data):
     token = data.get("token", None)
     id = data.get("id", None)
     action = data.get("action", "view")
     status, user = authenticateUser(token)
     if status:
         post = Posts.objects.filter(id=id, created_by=user).first()
         if post:
             if action == "view":
                 response = success_response()
                 response['post_message'] = post.post_message
                 tag_m = TagManager.objects.filter(post_id=post)
                 tags = [tag.tag_id.tag_string for tag in tag_m]
                 response['post_tags'] = ",".join(tags)
             elif action == "update":
                 response = success_response()
                 post_message = data.get("post_message")
                 if post_message:
                     post.post_message = post_message
                     post.save()
                 else:
                     response = no_success_response()
                     response["message"] = "Not valid post message given"
             else:
                 response = no_success_response()
                 response["message"] = "Not valid action given"
         else:
             response = no_success_response()
             response['message'] = "Not valid post found"
     else:
         response = no_success_response()
         response['message'] = "Login into the account to view user Post"
     response['action'] = action
     response['token'] = token
     response['id'] = id
     return response