Beispiel #1
0
    def get(self, user_id):
        # load profile 
        profile =  Profile.objects(user=user_id).first()
        if profile is None:
        	return {}

        return serialize(profile)
    def post(self, user_id):
        """
        Upload user's profile icon
        """
        uploaded_file = request.files['upload']
        filename = "_".join([user_id, uploaded_file.filename])

        # upload the file to S3 server
        conn = boto.connect_s3(os.environ['S3_KEY'], os.environ['S3_SECRET'])
        bucket = conn.get_bucket('profile-icon')
        key = bucket.new_key(filename)
        key.set_contents_from_file(uploaded_file)

        # update the user's profile document
        profile = Profile.objects(user=user_id).first()
        if profile is None:
            profile = Profile(
                user=user_id,
                profile_icon=
                'https://s3-us-west-2.amazonaws.com/profile-icon/%s' %
                filename)
            profile.save()
        else:
            profile.profile_icon = 'https://s3-us-west-2.amazonaws.com/profile-icon/%s' % filename
            profile.save()

        return serialize(profile)
Beispiel #3
0
    def post(self, user_id):
    	args = profileParser.parse_args()
        username = args['username']
        school = args['school']
        intro = args['intro']
        lolID = args['lolID']
        dotaID = args['dotaID']
        hstoneID = args['hstoneID']
        gender = args['gender']

        profile = Profile.objects(user=user_id).first()
        if profile is None:
            profile = Profile(user=user_id)
        profile.username = username
        profile.school = school
        profile.intro = intro
        profile.lolID = lolID
        profile.dotaID = dotaID
        profile.hstoneID = hstoneID
        profile.gender = gender
        profile.save()
        
        rongRefresh(profile.id)

        return serialize(profile)
Beispiel #4
0
 def serialize(self):
     serialized_object = {}
     for attr in self.get_all_attr():
         if attr != 'documentUser':
             serialized_object[attr] = serialize(getattr(self, attr))
     serialized_object['user_id'] = self.owner_id()
     return serialized_object
Beispiel #5
0
    def success(self, result: Any):
        """
        Job has succeeded.

        This method bundles the job result and the log together
        and returns them both as the Celery task result.
        """
        return dict(result=serialize(result), log=self.log_entries)
    def get(self, user_id):
        """
        Load the user's profile
        """
        profile = Profile.objects(user=user_id).first()
        if profile is None:
            return {}

        return serialize(profile)
    def get(self, user_id):
        """
        Load the user's profile
        """
        profile = Profile.objects(user=user_id).first()
        if profile is None:
            return {}

        return serialize(profile)
 def new_function(*args):
     session = Session()
     response = None
     try:
         obj = old_function(session, *args)
         response = serialize(obj)
     except Exception as e:
         info_logger.error(e)
         raise e
     finally:
         session.close()
     return response
Beispiel #9
0
    def get_members(session, *args):
        attributes = {}
        page_number = 0
        page_size = 25

        if len(args) > 0:
            attributes = {
                key: args[0].get(key).lower() if isinstance(
                    args[0].get(key), str) else args[0].get(key)
                for key in args[0].keys()
            }

        if 'pageNumber' in attributes:
            page_number = int(attributes.pop('pageNumber'))

        if 'pageSize' in attributes:
            page_size = int(attributes.pop('pageSize'))

        if 'positionId' in attributes:
            attributes['position_id'] = attributes.pop('positionId')

        positions_params = {
            key: attributes.pop(key)
            for key in {'position_id', 'year'}.intersection(
                set(attributes.keys()))
        }

        members = session.query(Member).filter_by(**attributes)

        if positions_params:
            members = members.join(MemberPosition) \
                .filter_by(**positions_params)

        page = members.limit(page_size).offset(page_number * page_size)

        total_items = members.group_by(Member).count()
        total_page = ceil(total_items / page_size)

        return {
            'content': serialize(page.all()),
            'meta': {
                'page': page_number,
                'totalPages': total_page,
                'totalItems': total_items,
                'itemsPerPage': page_size
            }
        }
Beispiel #10
0
    def post(self, user_id):
        uploaded_file = request.files['upload']
        filename = "_".join([user_id, uploaded_file.filename])

        conn = boto.connect_s3('AKIAJAQHGWIZDOAEQ65A', 'FpmnFv/jte9ral/iXHtL8cDUnuKXAgAqp9aXVQMI')
        bucket = conn.get_bucket('profile-icon')
        key = bucket.new_key(filename)
        key.set_contents_from_file(uploaded_file)

        profile = Profile.objects(user=user_id).first()
        if profile is None:
            profile = Profile(user=user_id, profile_icon='https://s3-us-west-2.amazonaws.com/profile-icon/%s' %filename)
            profile.save()
        else:
            profile.profile_icon = 'https://s3-us-west-2.amazonaws.com/profile-icon/%s' %filename
            profile.save()

        rongRefresh(profile.id)
        
        return serialize(profile)
    def post(self, user_id):
        """
        Edit the user's profile if the profile exists
        Otherwise, create a new profile document
        """
        args = profileParser.parse_args()
        username = args['username']
        school = args['school']
        intro = args['intro']

        profile = Profile.objects(user=user_id).first()
        if profile is None:
            profile = Profile(
                user=user_id, username=username, school=school, intro=intro)
            profile.save()
        else:
            profile.username = username
            profile.school = school
            profile.intro = intro
            profile.save()

        return serialize(profile)
    def post(self, user_id):
        """
        Upload user's profile icon
        """
        uploaded_file = request.files['upload']
        filename = "_".join([user_id, uploaded_file.filename])

        # upload the file to S3 server
        conn = boto.connect_s3(os.environ['S3_KEY'], os.environ['S3_SECRET'])
        bucket = conn.get_bucket('profile-icon')
        key = bucket.new_key(filename)
        key.set_contents_from_file(uploaded_file)

        # update the user's profile document
        profile = Profile.objects(user=user_id).first()
        if profile is None:
            profile = Profile(user=user_id, profile_icon=
                              'https://s3-us-west-2.amazonaws.com/profile-icon/%s' % filename)
            profile.save()
        else:
            profile.profile_icon = 'https://s3-us-west-2.amazonaws.com/profile-icon/%s' % filename
            profile.save()

        return serialize(profile)
    def post(self, user_id):
        """
        Edit the user's profile if the profile exists
        Otherwise, create a new profile document
        """
        args = profileParser.parse_args()
        username = args['username']
        school = args['school']
        intro = args['intro']

        profile = Profile.objects(user=user_id).first()
        if profile is None:
            profile = Profile(user=user_id,
                              username=username,
                              school=school,
                              intro=intro)
            profile.save()
        else:
            profile.username = username
            profile.school = school
            profile.intro = intro
            profile.save()

        return serialize(profile)
Beispiel #14
0
 def serialize(self):
     serialized_object = {}
     for attr in self.get_all_attr():
         if attr != 'password' and attr != 'comments' and attr != 'version' and attr != 'extended_document':
             serialized_object[attr] = serialize(getattr(self, attr))
     return serialized_object
Beispiel #15
0
 def serialize(self):
     serialized_object = {}
     for attr in self.get_all_attr():
         if attr != 'document' and attr != 'user':
             serialized_object[attr] = serialize(getattr(self, attr))
     return serialized_object
Beispiel #16
0
    def get(self, profileID):
        profile = Profile.objects(id=profileID).first()
        if profile is None:
            raise InvalidUsage('Profile not found',404)

        return serialize(profile)
Beispiel #17
0
 def serialize(self):
     serialized_object = {}
     for attr in self.get_all_attr():
         serialized_object[attr] = serialize(getattr(self, attr))
     return serialized_object