示例#1
0
def upload_event_image(request):
    photo = request.FILES.get(PHOTO, '')
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        event = request.event
        user = request.user
        try:
            EventUser.objects.get(event=event, user=user, joined=True)
        except EventUser.DoesNotExist:
            response_data[ERROR_CODE] = NO_PERMISSION
            response_data[ERROR_MESSAGE] = NO_PERMISSION_MESSAGE
            return  json_http(response_data)
        photo_url = save_file(file=photo, upload_to='event')
        image = Image(event_id=event.id, owner_id=user.id)
        image.source = photo_url
        image.save()
        event.num_images += 1
        event.save()
        user.num_photo += 1
        user.save()
        response_data[IMAGE_ID] = image.id
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
    return  json_http(response_data)
示例#2
0
def edit_event(request):
    title = request.POST.get(TITLE,'')
    description = request.POST.get(DESCRIPTION,'')
    if not title or not description:
        return json_http(None)

    response_data = {ERROR_CODE:NO_ERROR}

    try:
        event = request.event
        user = request.user
        if event.created_by_id != user.id:
            response_data[ERROR_CODE] = NO_PERMISSION
            response_data[ERROR_MESSAGE] = NO_PERMISSION_MESSAGE
            return  json_http(response_data)
        event.description = description
        event.title = title

        event.save()

        response_data[EVENT_ID] = event.id
        response_data[TITLE] = event.title
        response_data[DESCRIPTION] = event.description
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
    return  json_http(response_data)
示例#3
0
def register(request):
    email = request.POST.get(EMAIL, '')
    password = request.POST.get(PASSWORD, '')
    if not email or not password:
        return json_http(None)
    first_name = request.POST.get(FIRST_NAME, '')
    last_name = request.POST.get(LAST_NAME, '')
    phone = request.POST.get(PHONE, '')
    photo = request.FILES.get(PHOTO, '')
    device_token = request.POST.get(DEVICE_TOKEN, '')

    response_data = {ERROR_CODE:NO_ERROR}

    try:
        users = User.objects.filter(email=email)
        for user in users:
            if user.social_id:
                continue
            response_data[ERROR_CODE] = EMAIL_EXISTED
            response_data[ERROR_MESSAGE] = EMAIL_EXISTED_MESSAGE
            return  json_http(response_data)

        user = User.objects.create(email=email)

        user.set_password(password)
        user.first_name = first_name
        user.last_name = last_name
        user.phone = phone
        photo_url = save_file(file=photo, upload_to='user')
        user.photo = photo_url or IMAGE_DEFAULT
        user.device_token = device_token
        user_token = default_token_generator.make_token(user)
        user.user_token = user_token
        user.save()

        user_login = gauth.authenticate(email=email, password=password)
        gauth.login(request, user_login)

        response_data[USER_TOKEN] = user_login.user_token
        response_data[USER_ID] = user_login.id
        response_data[FIRST_NAME] = user_login.first_name
        response_data[LAST_NAME] = user_login.last_name
        photo_link = ""
        if unicode(user_login.photo):
            photo_link = settings.MEDIA_URL + unicode(user_login.photo)
        response_data[PHOTO] = photo_link
        response_data[NUM_FOLLOWER] = user_login.num_follower
        response_data[NUM_LIKE] = user_login.num_like
        response_data[NUM_PHOTO] = user_login.num_photo
        response_data[SOCIAL_ID] = user_login.social_id
        response_data[DEVICE_TOKEN] = user_login.device_token

    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
        return  json_http(response_data)


    response_data[USER_TOKEN] = user.user_token
    return  json_http(response_data)
示例#4
0
def create_event(request):
    title = request.POST.get(TITLE,'')
    description = request.POST.get(DESCRIPTION,'')
    if not title or not description:
        return json_http(None)
    latitude = request.POST.get(LATITUDE,'') or 0
    longitude = request.POST.get(LONGITUDE,'') or 0
    place_address = request.POST.get(PLACE_ADDRESS,'')
    place_name = request.POST.get(PLACE_NAME,'')
    phone = request.POST.get(PHONE,'')
    time_limit = request.POST.get(TIME_LIMIT,'') or 24
    is_public = request.POST.get(IS_PUBLIC,'')
    code = request.POST.get(CODE,'')

    response_data = {ERROR_CODE:NO_ERROR}

    if is_public != 'on' and not code:
        response_data[ERROR_CODE] = EVENT_CODE_NOT_SET
        response_data[ERROR_MESSAGE] = EVENT_CODE_NOT_SET_MESSAGE
        return  json_http(response_data)

    try:
        user = request.user

        event = Event()
        event.created_by_id = user.id
        event.description = description
        event.latitude = latitude
        event.longitude = longitude
        event.place_address = place_address
        event.place_name = place_name
        event.phone = phone
        event.time_limit = time_limit
        event.is_public = is_public
        event.code = code
        event.title = title

        event.save()

        event_user = EventUser()
        event_user.user_id = user.id
        event_user.event_id = event.id
        event_user.joined = True
        event_user.joining = True
        event_user.save()

        user.num_event += 1
        user.save()

        response_data[EVENT_ID] = event.id
        response_data[TITLE] = event.title
        response_data[DESCRIPTION] = event.description
        response_data[LATITUDE] = event.latitude
        response_data[LONGITUDE] = event.longitude
        response_data[TIME_LIMIT] = event.time_limit
        response_data[IS_PUBLIC] = event.is_public
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
    return  json_http(response_data)
示例#5
0
def comment(request):
    parent_comment_id = request.POST.get(PARENT_COMMENT_ID, '') or 0
    content = request.POST.get(CONTENT, '')
    if not comment:
        return json_http(None)

    response_data = {ERROR_CODE:NO_ERROR}
    try:
        user = request.user
        image = request.image
        comment_obj = Comment(user_id=user.id, image_id=image.id)
        comment_obj.content = content
        comment_obj.parent = parent_comment_id
        comment_obj.save()
        image.num_comments += 1
        image.save()
        if parent_comment_id != 0:
            parent = Comment.objects.get(pk=parent_comment_id)
            parent.num_reply += 1
            parent.save()

        response_data[COMMENT_ID] =comment_obj.id
        response_data[USER_ID] = comment_obj.user_id
        response_data[IMAGE_ID] = comment_obj.image_id
        response_data[CONTENT] = comment_obj.content
        response_data[NUM_REPLY] = comment_obj.num_reply

    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
    return  json_http(response_data)
示例#6
0
 def inner(request, *args, **kwargs):
     response_data = {}
     if not request.POST.get(USER_TOKEN, ''):
         response_data[ERROR_CODE] = USER_TOKEN_NOT_SET
         response_data[ERROR_MESSAGE] = USER_TOKEN_NOT_SET_MESSAGE
         return json_http(response_data)
     elif not request.user.is_authenticated():
         response_data[ERROR_CODE] = USER_NOT_FOUND
         response_data[ERROR_MESSAGE] = USER_NOT_FOUND_MESSAGE
         return json_http(response_data)
     return func(request, *args, **kwargs)
示例#7
0
def set_posted_event(request):
    event = request.event
    user = request.user
    response_data = {ERROR_CODE:NO_ERROR}
    if event.created_by_id != user.id:
        response_data[ERROR_CODE] = NO_PERMISSION
        response_data[ERROR_MESSAGE] = NO_PERMISSION_MESSAGE
        return  json_http(response_data)
    event.posted = True
    event.save()

    return  json_http(response_data)
示例#8
0
def login_via_facebook(request):
    social_id = request.POST.get(SOCIAL_ID, '')
    if not social_id:
        return

    email = request.POST.get(EMAIL, '')
    photo = request.POST.get(PHOTO, '')
    first_name = request.POST.get(FIRST_NAME, '')
    last_name = request.POST.get(LAST_NAME, '')
    phone = request.POST.get(PHONE, '')
    device_token = request.POST.get(DEVICE_TOKEN, '')

    response_data = {ERROR_CODE:NO_ERROR}
    if not device_token:
        response_data[ERROR_CODE] = DEVICE_TOKEN_NOT_SET
        response_data[ERROR_MESSAGE] = DEVICE_TOKEN_NOT_SET_MESSAGE
        return  json_http(response_data)

    try:
        user, created = User.objects.get_or_create(social_id=social_id)
        user_token = User.objects.make_random_password()

        user.user_token = user_token
        user.email = email
        user.device_token = device_token
        user.photo = photo
        user.first_name = first_name
        user.last_name = last_name
        user.phone = phone
        user.save()

        user_login = gauth.authenticate(user_token=user_token)
        gauth.login(request, user_login)

        response_data[USER_TOKEN] = user_login.user_token
        response_data[USER_ID] = user_login.id
        response_data[FIRST_NAME] = user_login.first_name
        response_data[LAST_NAME] = user_login.last_name
        response_data[PHOTO] = photo
        response_data[NUM_FOLLOWER] = user_login.num_follower
        response_data[NUM_LIKE] = user_login.num_like
        response_data[NUM_PHOTO] = user_login.num_photo
        response_data[SOCIAL_ID] = user_login.social_id
        response_data[DEVICE_TOKEN] = user_login.device_token
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
        return json_http(response_data)

    return  json_http(response_data)
示例#9
0
def get_joinable_events(request):
    latitude = request.POST.get(LATITUDE, '')
    longitude = request.POST.get(LONGITUDE, '')
    distance = request.POST.get(DISTANCE, '') or 100
    if not latitude or not longitude or not distance:
        return json_http(None)
    events = Event.objects.all()

    response_data = {}
#    try:
    event_list = []
    original_time = datetime(2013, 1, 1, 0,0,0)
    end_time = (datetime.now() - original_time).total_seconds()
    end_time_minute = end_time/60
    for event in events:
        created = event.created_date
        time = datetime(created.year, created.month, created.day, created.hour, created.minute, created.second)
        start_time = (time - original_time).total_seconds()
        start_time_minute = start_time/60
        result = end_time_minute - start_time_minute
        time_limit = event.time_limit * 60

        current_distance = haversine(float(longitude), float(latitude), float(event.longitude), float(event.latitude))
        if current_distance <= float(distance) and result < time_limit:
            event_item = {}
            user_data = {}
            user = event.created_by
            user_data[USER_ID] = user.id
            user_data[NAME] = user.full_name()
            user_data[PHOTO] = unicode(user.photo) if '://' in unicode(user.photo) else settings.MEDIA_URL + unicode(user.photo)

            event_item[EVENT_ID] = event.id
            event_item[TITLE] = event.title
            event_item[NUM_MEMBER] = event.num_member
            event_item[NUM_LIKE] = event.num_likes
            event_item[NUM_PHOTO] = event.num_images
            event_item[LONGITUDE] = event.longitude
            event_item[LATITUDE] = event.latitude
            event_item[PLACE_ADDRESS] = event.place_address
            event_item[TIME_LIMIT] = event.time_limit*60
            event_item['current_distance'] = current_distance

            event_list.append(event_item)
    response_data['events'] = event_list
#    except:
#        response_data[ERROR_CODE] = UNKNOWN_ERROR
#        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return json_http(response_data)
示例#10
0
def forgot_password(request):
    email = request.POST.get(EMAIL, '')
    if not email:
        return

    response_data = {ERROR_CODE:NO_ERROR}
    try:
        from django.utils.crypto import get_random_string
        user = User.objects.get(email=email)
        random_password = get_random_string(6)
        user.set_password(random_password)
        user.save()

        from django.core import mail

        emails = (
            ('Reset Password', 'This is new password:'******'*****@*****.**', [email]),
        )
        results = mail.send_mass_mail(emails)
        response_data['email'] = email
#        response_data['num_results'] = len(results)

    except User.DoesNotExist:
        response_data[ERROR_CODE] = WRONG_EMAIL
        response_data[ERROR_MESSAGE] = WRONG_EMAIL_MESSAGE
    return  json_http(response_data)
示例#11
0
 def inner(request, *args, **kwargs):
     if not request.POST.get(USER_ID, ''):
         response_data = {}
         response_data[ERROR_CODE] = USER_ID_NOT_SET
         response_data[ERROR_MESSAGE] = USER_ID_NOT_SET_MESSAGE
         return json_http(response_data)
     return func(request, *args, **kwargs)
示例#12
0
 def inner(request, *args, **kwargs):
     if request.method != 'POST':
         response_data = {}
         response_data[ERROR_CODE] = GET_METHOD_ERROR
         response_data[ERROR_MESSAGE] = GET_METHOD_ERROR_MESSAGE
         return json_http(response_data)
     return func(request, *args, **kwargs)
示例#13
0
def get_join_user_list(request):
    response_data = {ERROR_CODE:NO_ERROR}
    user_list = []
    try:
        event = request.event
        event_users = EventUser.objects.filter(event_id=event.id, joined=True)
        for event_user in event_users:
            user = event_user.user
            user_item = {}
            user_item[USER_ID] = user.id
            user_item[FIRST_NAME] = user.first_name
            user_item[LAST_NAME] = user.last_name
            user_item[PHOTO] = unicode(user.photo) if '://' in unicode(user.photo) else settings.MEDIA_URL + unicode(user.photo)
            user_item[NUM_FOLLOWER] = user.num_follower
            user_item[NUM_LIKE] = user.num_like
            user_item[NUM_PHOTO] = user.num_photo

            user_list.append(user_item)

        response_data['users'] = user_list

    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#14
0
def vote_photo(request):
    vote = request.POST.get(VOTE, '')

    response_data = {ERROR_CODE:NO_ERROR}
    try:
        image = request.image
        user = request.user
        image_like, created = Image_Like.objects.get_or_create(image_id=image.id, user_id=user.id)

        if vote == 'on':
            image_like.vote = True
            if image.num_likes == 0:
                image.event.num_likes+=1
                image.event.save()
                image.owner.num_like+=1
                image.owner.save()
            image.num_likes += 1
        else:
            if image.num_likes == 1:
                image.event.num_likes-=1
                image.event.save()
                image.owner.num_like-=1
                image.owner.save()
            image_like.vote = False
            image.num_likes -= 1
        image_like.save()
        image.save()
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#15
0
def get_photo_detail(request):
    response_data = {ERROR_CODE:NO_ERROR}

    image = request.image

    owner = image.owner
    creator = {}
    creator[USER_ID] = owner.id
    creator[NAME] = owner.full_name()
    creator[PHOTO] = unicode(owner.photo) if '://' in unicode(owner.photo) else settings.MEDIA_URL + unicode(owner.photo)

    comment_list = []
    comments = Comment.objects.filter(image_id=image.id)
    for comment in comments:
        comment_item = {}

        user = comment.user
        user_comment = {}
        user_comment[USER_ID] = user.id
        user_comment[NAME] = user.full_name()
        user_comment[PHOTO] = unicode(user.photo) if '://' in unicode(user.photo) else settings.MEDIA_URL + unicode(user.photo)

        comment_item[CONTENT] = comment.content
        comment_item['user'] = user_comment

        comment_list.append(comment_item)

    response_data[IMAGE_ID] = image.id
    response_data[SOURCE] = settings.MEDIA_URL+unicode(image.source)
    response_data[NUM_LIKE] = image.num_likes
    response_data[NUM_COMMENT] = image.num_comments
    response_data['creator'] = creator
    response_data['comments'] = comment_list

    return  json_http(response_data)
示例#16
0
def get_posted_events(request):
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        user = request.user
        posted_events = Event.objects.filter(created_by_id=user.id, posted=True)
        event_list = []
        for event in posted_events:
            event_item = {}
            user_data = {}
            creator = event.created_by
            user_data[USER_ID] = creator.id
            user_data[NAME] = creator.full_name()
            user_data[PHOTO] = unicode(creator.photo) if '://' in unicode(creator.photo) else settings.MEDIA_URL + unicode(creator.photo)

            event_item[EVENT_ID] = event.id
            event_item[TITLE] = event.title
            event_item[NUM_MEMBER] = event.num_member
            event_item[NUM_LIKE] = event.num_likes
            event_item[NUM_PHOTO] = event.num_images
            event_item[LONGITUDE] = event.longitude
            event_item[LATITUDE] = event.latitude
            event_item[PLACE_ADDRESS] = event.place_address
            event_item[TIME_LIMIT] = event.time_limit*60

            event_list.append(event_item)

        user_friend_filters = UserFriend.objects.filter(user_id=user.id)
        for user_friend_filter in user_friend_filters:
            friend_id = user_friend_filter.friend.id

            posted_events_of_friends = Event.objects.filter(created_by_id=friend_id, posted=True)
            for event in posted_events_of_friends:
                event_item = {}
                user_data = {}
                creator = event.created_by
                user_data[USER_ID] = creator.id
                user_data[NAME] = creator.full_name()
                user_data[PHOTO] = unicode(creator.photo) if '://' in unicode(creator.photo) else settings.MEDIA_URL + unicode(creator.photo)

                event_item[EVENT_ID] = event.id
                event_item[TITLE] = event.title
                event_item[NUM_MEMBER] = event.num_member
                event_item[NUM_LIKE] = event.num_likes
                event_item[NUM_PHOTO] = event.num_images
                event_item[LONGITUDE] = event.longitude
                event_item[LATITUDE] = event.latitude
                event_item[PLACE_ADDRESS] = event.place_address
                event_item[TIME_LIMIT] = event.time_limit*60

                event_list.append(event_item)

        response_data['events'] = event_list
        response_data[NUM_EVENT] = len(event_list)
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
    return  json_http(response_data)
示例#17
0
def get_list_own_events(request):
    user = request.user
    response_data = {ERROR_CODE:NO_ERROR}
#    try:
    get_events_by_user_id(user.id, response_data)
#    except:
#        response_data[ERROR_CODE] = UNKNOWN_ERROR
#        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#18
0
def delete_image(request):
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        image = request.image
        user = request.user
        event = request.event
        is_admin = image.owner_id == user.id or event.created_by == user.id
        if is_admin and image.event_id == image.event_id:
            image.delete()
        else:
            response_data[ERROR_CODE] = NO_PERMISSION
            response_data[ERROR_MESSAGE] = NO_PERMISSION_MESSAGE
            return  json_http(response_data)

    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#19
0
def get_list_user_events(request):
    user_id = request.POST.get(USER_ID, '')
    user = User.objects.get(pk=user_id)
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        get_events_by_user_id(user.id, response_data)
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#20
0
def set_status_event(request):
    is_public = request.POST.get(IS_PUBLIC, '')
    code = request.POST.get(CODE, '')
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        event = request.event
        if is_public != 'on' and not code:
            response_data[ERROR_CODE] = EVENT_CODE_NOT_SET
            response_data[ERROR_MESSAGE] = EVENT_CODE_NOT_SET_MESSAGE
            return  json_http(response_data)
        if is_public == 'on':
            event.is_public = True
        else:
            event.is_public = False
            event.code = code
        event.save()
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#21
0
def login(request):
    email = request.POST.get(EMAIL, '')
    password = request.POST.get(PASSWORD, '')
    if not email or not password:
        return json_http(None)

    response_data = {ERROR_CODE:NO_ERROR}
    device_token = request.POST.get(DEVICE_TOKEN, '')
    try:
        user_login = gauth.authenticate(email=email, password=password)
        if user_login is None:
            response_data[ERROR_CODE] = WRONG_EMAIL_OR_PASSWORD
            response_data[ERROR_MESSAGE] = WRONG_EMAIL_OR_PASSWORD_MESSAGE
            return  json_http(response_data)

        user_token = default_token_generator.make_token(user_login)
        user_login.user_token = user_token
        user_login.save()

        gauth.login(request, user_login)
        user_login.device_token = device_token
        user_login.save()

        response_data[USER_TOKEN] = user_login.user_token
        response_data[USER_ID] = user_login.id
        response_data[FIRST_NAME] = user_login.first_name
        response_data[LAST_NAME] = user_login.last_name
        photo_link = unicode(user_login.photo) if '://' in unicode(user_login.photo) else settings.MEDIA_URL + unicode(user_login.photo)
        response_data[PHOTO] = photo_link
        response_data[NUM_FOLLOWER] = user_login.num_follower
        response_data[NUM_LIKE] = user_login.num_like
        response_data[NUM_PHOTO] = user_login.num_photo
        response_data[SOCIAL_ID] = user_login.social_id
        response_data[DEVICE_TOKEN] = user_login.device_token

    except User.DoesNotExist:
        response_data[ERROR_CODE] = WRONG_EMAIL

    return  json_http(response_data)
示例#22
0
def set_abused_reports(request):
    to = request.POST.get(TO, '') or '*****@*****.**'
    cc = request.POST.get(CC, '')
    bcc = request.POST.get(BCC, '')
    content = request.POST.get(CONTENT, '')
    if not content:
        return json_http(None)
    abused_user_id = request.POST.get(USER_ID, '')

    response_data = {ERROR_CODE:NO_ERROR}
    try:
        abused_user = User.objects.get(pk=abused_user_id)
        report, created = AbuseReport.objects.get_or_create(user = abused_user, reporter = request.user, event=request.event)
        report.to = to
        report.cc = cc
        report.bcc = bcc
        report.content = content

        if created:
            abused_user.num_reports+=1
            if abused_user.num_reports > 1 and abused_user.num_reports <=5:
                abused_user.level = LOWER
            elif abused_user.num_reports > 5 and abused_user.num_reports <=10:
                abused_user.level = MIDDLE
            elif abused_user.num_reports > 10:
                abused_user.level = HIGH
            abused_user.save()
        report.save()

        response_data[REPORT_ID] = report.id
        response_data[TO] = report.to
        response_data[CC] = report.cc
        response_data[BCC] = report.bcc
        response_data[CONTENT] = report.content
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return json_http(response_data)
示例#23
0
def get_user_detail(request):
    user_id = request.POST.get(USER_ID)
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        user = User.objects.get(pk=user_id)
        if not user.is_active:
            response_data[ERROR_CODE] = USER_BLOCKED
            response_data[ERROR_MESSAGE] = USER_BLOCKED_MESSAGE
            return  json_http(response_data)

        response_data[USER_ID] = user.id
        response_data[FIRST_NAME] = user.first_name
        response_data[LAST_NAME] = user.last_name
        response_data[PHOTO] = unicode(user.photo) if '://' in unicode(user.photo) else settings.MEDIA_URL + unicode(user.photo)
        response_data[NUM_FOLLOWER] = user.num_follower
        response_data[NUM_LIKE] = user.num_like
        response_data[NUM_PHOTO] = user.num_photo
        response_data[NUM_EVENT] = user.num_event
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#24
0
def upload_user_photo(request):
    photo = request.FILES.get(PHOTO, '')
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        user = request.user
        photo_url = save_file(file=photo, upload_to='user')
        user.photo = photo_url
        response_data[PHOTO] = settings.MEDIA_URL+photo_url
        user.save()
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#25
0
def join_event(request):
    response_data = {ERROR_CODE:NO_ERROR}
    code = request.POST.get(CODE,'')
    try:
        event = request.event
        user = request.user
        if not event.is_active:
            response_data[ERROR_CODE] = EVENT_BLOCKED
            response_data[ERROR_MESSAGE] = EVENT_BLOCKED_MESSAGE
            return  json_http(response_data)
        try:
            EventUser.objects.get(event=event, user=user, blocked=True)
            response_data[ERROR_CODE] = EVENT_BLOCKED_USER
            response_data[ERROR_MESSAGE] = EVENT_BLOCKED_USER_MESSAGE
            return  json_http(response_data)
        except EventUser.DoesNotExist:
            pass

        wrong_code = not code or code != event.code
        if user.id != event.created_by_id and not event.is_public and wrong_code:
            response_data[ERROR_CODE] = NO_PERMISSION
            response_data[ERROR_MESSAGE] = NO_PERMISSION_MESSAGE
            return  json_http(response_data)

        user = request.user
        event_user, created = EventUser.objects.get_or_create(event_id=event.id, user_id=user.id)
        event_user.joined = True
        event_user.joining = True
        event_user.save()
        if created:
            event.num_member += 1
            event.save()
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#26
0
def get_user_photos(request):
    user_id = request.POST.get(USER_ID, '')
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        images = Image.objects.filter(owner_id=user_id)
        image_list = []
        for image in images:
            image_item = {}
            image_item[IMAGE_ID] = image.id
            image_item[SOURCE] = settings.MEDIA_URL+unicode(image.source)
            image_item[NUM_LIKE] = image.num_likes
            image_item[CREATED_DATE] = unicode(image.created_date)
            image_list.append(image_item)
        response_data['photos'] = image_list
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE
    return  json_http(response_data)
示例#27
0
def get_unpublished_events(request):
    user = request.user
    response_data = {ERROR_CODE:NO_ERROR}
    event_list = []
    try:
        events = Event.objects.filter(created_by_id=user.id)
        original_time = datetime(2013, 1, 1, 0,0,0)
        end_time = (datetime.now() - original_time).total_seconds()
        end_time_minute = end_time/60

        for event in events:
            created = event.created_date
            time = datetime(created.year, created.month, created.day, created.hour, created.minute, created.second)
            start_time = (time - original_time).total_seconds()
            start_time_minute = start_time/60
            result = end_time_minute - start_time_minute
            time_limit = event.time_limit * 60
            if result > time_limit and not event.posted:
                event_item = {}
                user_data = {}
                user = event.created_by
                user_data[USER_ID] = user.id
                user_data[NAME] = user.full_name()
                user_data[PHOTO] = settings.MEDIA_URL+unicode(user.photo)

                event_item[EVENT_ID] = event.id
                event_item[TITLE] = event.title
                event_item[NUM_MEMBER] = event.num_member
                event_item[NUM_LIKE] = event.num_likes
                event_item[NUM_PHOTO] = event.num_images
                event_item[LONGITUDE] = event.longitude
                event_item[LATITUDE] = event.latitude
                event_item[PLACE_ADDRESS] = event.place_address
                event_item[TIME_LIMIT] = time_limit
                event_item[CREATED_DATE] = unicode(event.created_date)

                event_list.append(event_item)

        response_data['events'] = event_list
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return json_http(response_data)
示例#28
0
def leave_event(request):
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        event = request.event
        user = request.user
        event_user, created = EventUser.objects.get_or_create(event_id=event.id, user_id=user.id)
        event_user.joining = False
        event_user.save()

        #check neu la admin
        if user.id == event.created_by_id:
            joining_users = EventUser.objects.filter(joining=True, event_id=event.id)
            import json
            for joining_user in joining_users:
                notification(joining_user.user.device_token, 'Test notification admin leave')
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#29
0
def set_follow_user(request):
    followed = request.POST.get(FOLLOWED)
    response_data = {ERROR_CODE:NO_ERROR}
    try:
        friend = request.friend
        user = request.user
        try:
            user_friend = UserFriend.objects.get(user_id=user.id, friend_id=friend.id)
            if followed == '0':
                user_friend.delete()
                friend.num_follower -= 1
        except UserFriend.DoesNotExist:
            UserFriend.objects.create(user_id=user.id, friend_id=friend.id)
            friend.num_follower += 1
        friend.save()
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)
示例#30
0
def get_list_user_followers(request):
    response_data = {ERROR_CODE:NO_ERROR}
    user_id = request.POST.get(USER_ID, '')
    try:
        userfriendfilters = UserFriend.objects.filter(friend_id=user_id)
        user_list = []
        for userfriendfilter in userfriendfilters:
            user_item = {}
            user_item[USER_ID] = userfriendfilter.friend.id
            user_item[FIRST_NAME] = userfriendfilter.friend.first_name
            user_item[LAST_NAME] = userfriendfilter.friend.last_name
            user_item[PHOTO] = unicode(userfriendfilter.friend.photo) if '://' in unicode(userfriendfilter.friend.photo) else settings.MEDIA_URL + unicode(userfriendfilter.friend.photo)
            user_item[NUM_FOLLOWER] = userfriendfilter.friend.num_follower
            user_item[NUM_LIKE] = userfriendfilter.friend.num_like
            user_item[NUM_PHOTO] = userfriendfilter.friend.num_photo
            user_list.append(user_item)
        response_data['users'] = user_list
    except:
        response_data[ERROR_CODE] = UNKNOWN_ERROR
        response_data[ERROR_MESSAGE] = UNKNOWN_ERROR_MESSAGE

    return  json_http(response_data)