예제 #1
0
def upgrade_trial(request):
    """
    View that handles upgrading from a Free account to a Trial account.
    
    """
    userprofile = request.user.userprofile
    
    if userprofile.account_level.level == 'Paid':
        messages.error(request, 'You already have a Paid account.')
        return redirect('features')
    elif userprofile.account_level.level == 'Trial':
        messages.error(request, 'You already have a Trial account.')
        return redirect('features')
    # An account can only be upgraded to a Trial account once.
    elif userprofile.trial_signed_up:
        messages.error(request, 'You already tried a Trial account.')
        return redirect('features')
    
    trial_account = AccountLevel.objects.get(pk=4)
    
    userprofile.account_level = trial_account
    userprofile.trial_signed_up = True
    userprofile.trial_expiry_date = (datetime.date.today() + 
            datetime.timedelta(days=DAYS_BEFORE_EXPIRATION))
    userprofile.api_key = generate_api_key(API_KEY_LEN)
    userprofile.save()
    
    # Update user's videos expiration dates
    vids = Video.objects.filter(uploader=request.user)
    for vid in vids:
        is_expired(vid)
        
    messages.success(request, 'You have successfully upgraded to a Trial account.')
    return redirect('account_info')
예제 #2
0
def authorize_monthly(request):
    
    if request.method == 'POST':
        form = ARBForm(request.POST)
        if form.is_valid():
            card_number = form.cleaned_data['card_number']
            expiration_date = form.cleaned_data['expiration_date']
            bill_first_name = form.cleaned_data['bill_first_name']
            bill_last_name = form.cleaned_data['bill_last_name']
            
            arb_api = arb.Api(LOGIN_ID, TRANS_KEY, is_test=IS_TEST, delimiter=DELIMITER, encapsulator=ENCAPSULATOR)
            
            subs = arb_api.create_subscription(
                card_number = card_number,
                expiration_date = unicode(expiration_date.strftime("%Y-%m")),
                bill_first_name = bill_first_name,
                bill_last_name = bill_last_name,
                interval_unit = MONTHS_INTERVAL,
                interval_length = 1,
                start_date = unicode(date.today().strftime("%Y-%m-%d")),
                amount = 10,
                subscription_name = unicode("Screenbird Paid Account - Monthly Subscription")
            )
            
            code_text = subs.messages.message.code.text_
            message_text = subs.messages.message.text.text_
            result_text = subs.messages.result_code.text_
            
            if code_text == 'I00001' and message_text == 'Successful.' and result_text == 'Ok':
                userprofile = UserProfile.objects.get(user__id=request.user.id)
                AuthorizeARBUser.objects.create(user_profile=userprofile, subscription_id=subs.subscription_id.text_)
                
                vids = Video.objects.filter(uploader=request.user)
                for vid in vids:
                    is_expired(vid)
                
                messages.success(request, "You have successfully upgraded your account!")
                return redirect('account_info')    
            else:
                messages.error(request, "There was a problem processing your subscription. Please try again later.")
                return redirect('features')
            
    else:
        form = ARBForm()
    
    context = {
        'form': form
    }
    
    return render_to_response('authorize_monthly.html', RequestContext(request, context))
예제 #3
0
def add_video_to_channel(request, channel_id, video_id):
    """
    Adds the selected video to the selected channel.

    """
    channel = get_object_or_404(Channel, id=channel_id, owner=request.user)
    video = get_object_or_404(Video, id=video_id, uploader=request.user)

    # Set the channel. Set expiry date to None.
    video.channel = channel
    if video.channel.owner.userprofile.account_level.level == 'Paid':
        video.expiry_date = None
    video.save()
    is_expired(video)
    messages.success(request, '%s has been added to %s.' % (video, channel))

    # Redirect to referer, or to the value of `next`, or to the home page,
    # whichever is present first, in that order.
    return redirect(request.META.get('HTTP_REFERER', request.GET.get('next', '/')))
예제 #4
0
def add_video_to_channel(request, channel_id, video_id):
    """
    Adds the selected video to the selected channel.

    """
    channel = get_object_or_404(Channel, id=channel_id, owner=request.user)
    video = get_object_or_404(Video, id=video_id, uploader=request.user)

    # Set the channel. Set expiry date to None.
    video.channel = channel
    if video.channel.owner.userprofile.account_level.level == 'Paid':
        video.expiry_date = None
    video.save()
    is_expired(video)
    messages.success(request, '%s has been added to %s.' % (video, channel))

    # Redirect to referer, or to the value of `next`, or to the home page,
    # whichever is present first, in that order.
    return redirect(
        request.META.get('HTTP_REFERER', request.GET.get('next', '/')))
예제 #5
0
def get_vids_from_profile(profile_id, request):
    try:
        profile = UserProfile.objects.get(pk=profile_id)
    except UserProfile.DoesNotExist:
        return None

    user = profile.user
    user_channels = profile.channels.all().values_list('id', flat=True).distinct()
    my_videos = Video.objects.filter(Q(uploader=user) | Q(channel__id__in=user_channels)).order_by('-created')
    my_videos_count = my_videos.count()

    if my_videos:
        my_videos_list = []
        for vid in my_videos:
            if vid.channel:
                # if video is part of a channel
                # account_level of channel owner will be used
                account_level = vid.channel.owner.userprofile.account_level
            else:
                # else use account_level of uploader
                account_level = vid.uploader.userprofile.account_level

            video_dict = {}
            video_dict['video'] = vid
            video_dict['account_level'] = account_level
            check_video = is_expired(vid)
            if account_level.video_validity and not vid.youtube_embed_url:
                video_dict['expired'] = check_video
                video_dict['days_left'] = days_left(vid)
            my_videos_list.append(video_dict)

        paginator = Paginator(my_videos_list, 25)

        try:
            page = int(request.GET.get('page', '1'))
        except ValueError:
            page = 1
        # If page request (9999) is out of range, deliver last page of results.
        try:
            latest_submissions_page = paginator.page(page)
        except (EmptyPage, InvalidPage):
            latest_submissions_page = paginator.page(paginator.num_pages)

        next_page = latest_submissions_page.next_page_number()
        prev_page = latest_submissions_page.previous_page_number()
        context = {'latest_submissions_page':latest_submissions_page, 'paginator':paginator, 'next_page':next_page,
                       'prev_page':prev_page, 'my_videos_count':my_videos_count}
    else:
        context = None

    return context
 def handle_noargs(self, **options):
     videos = Video.objects.all()
     user_videos = {}
     for video in videos:
         print "Video: " + video.title
         if video.uploader and is_expired(video) and not is_deletable(video):
             print "Expired and will be deleted soon? True"
             if video.uploader not in user_videos:
                 user_videos[video.uploader] = []
             user_videos[video.uploader].append(video)
         else:
             print "Expired and will be deleted soon? False"
     for uploader, videos in user_videos.iteritems():
         send_delete_warning(uploader, videos)
 def handle_noargs(self, **options):
     videos = Video.objects.all()
     user_videos = {}
     for video in videos:
         print "Video: " + video.title
         if video.uploader and is_expired(
                 video) and not is_deletable(video):
             print "Expired and will be deleted soon? True"
             if video.uploader not in user_videos:
                 user_videos[video.uploader] = []
             user_videos[video.uploader].append(video)
         else:
             print "Expired and will be deleted soon? False"
     for uploader, videos in user_videos.iteritems():
         send_delete_warning(uploader, videos)
예제 #8
0
def upgrade_trial(request):
    """
    View that handles upgrading from a Free account to a Trial account.
    
    """
    userprofile = request.user.userprofile

    if userprofile.account_level.level == 'Paid':
        messages.error(request, 'You already have a Paid account.')
        return redirect('features')
    elif userprofile.account_level.level == 'Trial':
        messages.error(request, 'You already have a Trial account.')
        return redirect('features')
    # An account can only be upgraded to a Trial account once.
    elif userprofile.trial_signed_up:
        messages.error(request, 'You already tried a Trial account.')
        return redirect('features')

    trial_account = AccountLevel.objects.get(pk=4)

    userprofile.account_level = trial_account
    userprofile.trial_signed_up = True
    userprofile.trial_expiry_date = (
        datetime.date.today() +
        datetime.timedelta(days=DAYS_BEFORE_EXPIRATION))
    userprofile.api_key = generate_api_key(API_KEY_LEN)
    userprofile.save()

    # Update user's videos expiration dates
    vids = Video.objects.filter(uploader=request.user)
    for vid in vids:
        is_expired(vid)

    messages.success(request,
                     'You have successfully upgraded to a Trial account.')
    return redirect('account_info')
예제 #9
0
    def handle_noargs(self, **options):
        videos = Video.objects.all()
        notify = {}
        delete = {}
        clear_video = {}
        for video in videos:
            if video.uploader:
                if video.channel:
                    # if video is part of a channel
                    # account_level of channel owner will be used
                    account_level = video.channel.owner.userprofile.account_level
                else:
                    # else use account_level of uploader
                    account_level = video.uploader.userprofile.account_level

                if account_level.video_validity and not video.youtube_embed_url:
                    if not video.expired:
                        expired = is_expired(video)
                        if expired:
                            # Notify user
                            user_expired_vids = notify.get(
                                str(video.uploader.id), [])
                            user_expired_vids.append(video)
                            notify[str(video.uploader.id)] = user_expired_vids
                    else:
                        print 'Video has already expired! %s; slug=%s' % (
                            video, video.slug)
                        if is_deletable(video):
                            user_deleted_vids = delete.get(
                                str(video.uploader.id), [])
                            user_deleted_vids.append(video)
                            delete[str(video.uploader.id)] = user_deleted_vids
                        else:
                            print ">>> Not deletable"
                            #send_delete_warning(video)

            else:
                if not video.youtube_embed_url:
                    if not video.expiry_date:
                        expiry_date = video.created + datetime.timedelta(
                            days=DAYS_BEFORE_EXPIRATION)
                        video.expiry_date = expiry_date
                        video.save()
                    expired = days_left(video)
                    if not video.expired:
                        if expired <= 0:
                            video_status = True
                            video.expired = True
                            video.save()
                    else:
                        if is_deletable(video):
                            user_deleted_vids = delete.get('None', [])
                            user_deleted_vids.append(video)
                            delete['None'] = user_deleted_vids
                            #send_delete_warning(video)
            if video.youtube_embed_url:
                today = datetime.date.today()
                print "Checking if %s's youtube expiry, %s, has expired." % (
                    video, video.youtube_video_expiry_date)
                if video.youtube_video_expiry_date:
                    days = video.youtube_video_expiry_date.date() - today
                    print "YouTube Video Expiry Days left: %s" % days.days
                    if days.days <= 0:
                        user_clear_vids = delete.get(str(video.uploader.id),
                                                     [])
                        user_clear_vids.append(video)
                        clear_video[str(video.uploader.id)] = user_clear_vids

        print "List of videos to notify users about expiration:"
        print notify
        print "List of videos to notify users about deletion:"
        print delete

        # Send actual notifications here

        print "Expiring videos"
        # For expiring videos
        for user, vids in notify.items():
            print user, vids
            uploader = User.objects.get(id=int(user))
            expired_video_names = "".join([v.title + "\n\t" for v in vids])
            print "Expired video names:"
            print expired_video_names

            message = \
"""
Hello %(username)s,

    You have videos expiring today, %(now)s!

        %(expired_video_names)s

    Other users and you won't be able to view the video from %(site)s, but you will have an option to download it or send it to Youtube for another 30 days.
    However after the 30 days it will be deleted from the site.


Thanks,

-------------------------
%(site)s Team
""" % \
            ({'expired_video_names': expired_video_names,
              'now': datetime.date.today().isoformat(),
              'username': uploader.username,
              'site': SITE,})

            send_mail('%s: Video Expired' % SITE,
                      message,
                      "no-reply@%s.com" % SITE.lower(), [uploader.email],
                      fail_silently=False)
            print 'Email Sent to username: %s! %s has expired.' % (
                uploader, expired_video_names)

        print "Videos to delete"
        # For videos to delete
        for user2, vids2 in delete.items():
            print user2, vids2
            deletable_video_names = "".join([v.title + "\n\t" for v in vids2])
            print "Deletable video names:"
            print deletable_video_names
            # Delete the actual videos
            print vids2
            for v in vids2:
                v.delete()
                print "Permanently deleted: ", v.title

            #Handles old videos with uploader are set to None
            if not user2 == 'None':
                uploader = User.objects.get(id=int(user2))
                message = \
"""
Hello %(username)s,

    The following videos have been deleted from %(site)s today, %(now)s!

        %(deletable_video_names)s

    The video has already exceeded the allowable time it would be stored on %(site)s.com, for further info contact us.


Thanks,

-------------------------
%(site)s Team
""" % \
            ({'username': uploader.username,
                'now': datetime.date.today().isoformat(),
                'deletable_video_names': deletable_video_names,
                'site': SITE,})

                send_mail('%s: Video Deleted' % SITE,
                          message,
                          "no-reply@%s.com" % SITE.lower(), [uploader.email],
                          fail_silently=False)

        for user3, vids3 in clear_video.items():
            print user3, vids3
            uploader = User.objects.get(id=int(user3))
            clear_videoupload_names = "".join(
                [vid3.title + "\n\t" for vid3 in vids3])
            print "Deletable video files:"
            print clear_videoupload_names
            # Delete the videofiles
            for vid3 in vids3:
                try:
                    delete_videoupload(vid3)
                    vid3.youtube_video_expiry_date = None
                    vid3.save()
                    print "Deleted video file on server: ", vid3.title
                    message = \
"""
Hello %(username)s,

    The following videos have been deleted from %(site)s today, %(now)s!

        %(deletable_video_names)s

    The video has already exceeded the allowable time it would be stored on %(site)s.com, for further info contact us.


Thanks,

-------------------------
%(site)s Team
""" % \
                    ({'username': uploader.username,
                      'now': datetime.date.today().isoformat(),
                      'deletable_video_names': clear_videoupload_names,
                      'site': SITE,})

                    send_mail('%s: Video Deleted' % SITE,
                              message,
                              "no-reply@%s.com" % SITE.lower(),
                              [uploader.email],
                              fail_silently=False)
                    print "Email Sent to %s" % uploader.username
                except os.error:
                    print 'ERROR when deleting'
예제 #10
0
def upgrade_account(request):
    """
    View that handles upgrading from a Free account to a Paid account via
    Authorize.net
    
    Note: Authorize.net payment option is currently on backlog
    
    """
    error_message = ""
    success_message = ""
    if request.user.userprofile.account_level.level == 'Paid':
        error_message = "You already have a Paid account."

    if request.method == 'POST':
        form = PaymentInformationForm(request.POST)
        if form.is_valid():
            paid_account = AccountLevel.objects.get(pk=2)
            r = authorize.call_auth(
                paid_account,
                unicode(paid_account.authnet_item_price),
                data = { 
                    'card_number':form.cleaned_data['card_number'],
                    'expiry':form.cleaned_data['expiry_date'],
                    'card_code':form.cleaned_data['card_code'],
                    'first_name':form.cleaned_data['first_name'],
                    'last_name':form.cleaned_data['last_name'],
                    'company':form.cleaned_data['company'],
                    'address':form.cleaned_data['address'],
                    'city':form.cleaned_data['city'],
                    'state':form.cleaned_data['state'],
                    'province':form.cleaned_data['province'],
                    'country':form.cleaned_data['country'],
                    'zip_code':form.cleaned_data['zip_code'],
                    'email':form.cleaned_data['email'],
                    'phone':form.cleaned_data['phone']
                },
            )
            success_message = ""
            if r.split('|')[0] == '1':
                trans_id = r.split('|')[6]
                r = authorize.call_capture(trans_id)
                if r.split('|')[0] == '1':
                    error_message = ""
                    userprofile = UserProfile.objects.get(user__id=request.user.id)
                    if userprofile.account_level.level == 'Trial':
                        userprofile.trial_ended = True
                        userprofile.trial_expiry_date = None
                    userprofile.account_level = paid_account
                    api_key_len = UserProfile._meta.get_field('api_key')
                    userprofile.api_key = generate_api_key(api_key_len)
                    userprofile.save()
                    form = PaymentInformationForm(request.POST)
                    success_message = "Payment Accepted"
                    form = PaymentInformationForm(request.POST)

                    # Update user's videos expiration dates
                    vids = Video.objects.filter(uploader=request.user)
                    for vid in vids:
                        is_expired(vid)
                else:
                    error_message = r.split('|')[3]
                    form = PaymentInformationForm(request.POST)
            else:
                error_message = "%s" % (r.split('|')[3])
                form = PaymentInformationForm(request.POST)
    else:
        form = PaymentInformationForm()

    context = {
        'form': form, 
        'error_message':error_message, 
        'success_message':success_message,
    }
    return render(request, 'purchase.html', context)
예제 #11
0
    def handle_noargs(self, **options):
        videos = Video.objects.all()
        notify = {}
        delete = {}
        clear_video = {}
        for video in videos:
            if video.uploader:
                if video.channel:
                    # if video is part of a channel
                    # account_level of channel owner will be used
                    account_level = video.channel.owner.userprofile.account_level
                else:
                    # else use account_level of uploader
                    account_level = video.uploader.userprofile.account_level

                if account_level.video_validity and not video.youtube_embed_url:
                    if not video.expired:
                        expired = is_expired(video)
                        if expired:
                            # Notify user
                            user_expired_vids = notify.get(str(video.uploader.id), [])
                            user_expired_vids.append(video)
                            notify[str(video.uploader.id)] = user_expired_vids
                    else:
                        print 'Video has already expired! %s; slug=%s' % (video, video.slug)
                        if is_deletable(video):
                            user_deleted_vids = delete.get(str(video.uploader.id), [])
                            user_deleted_vids.append(video)
                            delete[str(video.uploader.id)] = user_deleted_vids
                        else:
                            print ">>> Not deletable"
                            #send_delete_warning(video)
                            
            else:
                if not video.youtube_embed_url:
                    if not video.expiry_date:
                        expiry_date = video.created + datetime.timedelta(days=DAYS_BEFORE_EXPIRATION)
                        video.expiry_date = expiry_date
                        video.save()
                    expired = days_left(video)
                    if not video.expired:
                        if expired <= 0:
                            video_status = True
                            video.expired = True
                            video.save()
                    else:
                        if is_deletable(video):
                            user_deleted_vids = delete.get('None', [])
                            user_deleted_vids.append(video)
                            delete['None'] = user_deleted_vids
                            #send_delete_warning(video)
            if video.youtube_embed_url:
                today = datetime.date.today()
                print "Checking if %s's youtube expiry, %s, has expired." % (video, video.youtube_video_expiry_date)
                if video.youtube_video_expiry_date:
                    days = video.youtube_video_expiry_date.date() - today
                    print "YouTube Video Expiry Days left: %s" % days.days
                    if days.days <= 0:
                        user_clear_vids = delete.get(str(video.uploader.id), [])
                        user_clear_vids.append(video)
                        clear_video [str(video.uploader.id)] = user_clear_vids

        print "List of videos to notify users about expiration:"
        print notify
        print "List of videos to notify users about deletion:"
        print delete

        # Send actual notifications here

        print "Expiring videos"
        # For expiring videos
        for user, vids in notify.items():
            print user, vids
            uploader = User.objects.get(id=int(user))
            expired_video_names = "".join([v.title + "\n\t" for v in vids])
            print "Expired video names:"
            print expired_video_names

            message = \
"""
Hello %(username)s,

    You have videos expiring today, %(now)s!

        %(expired_video_names)s

    Other users and you won't be able to view the video from %(site)s, but you will have an option to download it or send it to Youtube for another 30 days.
    However after the 30 days it will be deleted from the site.


Thanks,

-------------------------
%(site)s Team
""" % \
            ({'expired_video_names': expired_video_names,
              'now': datetime.date.today().isoformat(),
              'username': uploader.username,
              'site': SITE,})

            send_mail('%s: Video Expired' % SITE,
                      message,
                      "no-reply@%s.com" % SITE.lower(),
                      [uploader.email], fail_silently=False)
            print 'Email Sent to username: %s! %s has expired.' % (uploader, expired_video_names)

        print "Videos to delete"
        # For videos to delete
        for user2, vids2 in delete.items():
            print user2, vids2
            deletable_video_names = "".join([v.title + "\n\t" for v in vids2])
            print "Deletable video names:"
            print deletable_video_names
            # Delete the actual videos
            print vids2
            for v in vids2:
                v.delete()
                print "Permanently deleted: ", v.title

            #Handles old videos with uploader are set to None
            if not user2 == 'None':
                uploader = User.objects.get(id=int(user2))
                message = \
"""
Hello %(username)s,

    The following videos have been deleted from %(site)s today, %(now)s!

        %(deletable_video_names)s

    The video has already exceeded the allowable time it would be stored on %(site)s.com, for further info contact us.


Thanks,

-------------------------
%(site)s Team
""" % \
            ({'username': uploader.username,
              'now': datetime.date.today().isoformat(),
              'deletable_video_names': deletable_video_names,
              'site': SITE,})

                send_mail('%s: Video Deleted' % SITE,
                      message,
                      "no-reply@%s.com" % SITE.lower(),
                      [uploader.email], fail_silently=False)

        for user3, vids3 in clear_video.items():
            print user3, vids3
            uploader = User.objects.get(id=int(user3))
            clear_videoupload_names = "".join([vid3.title + "\n\t" for vid3 in vids3])
            print "Deletable video files:"
            print clear_videoupload_names
            # Delete the videofiles
            for vid3 in vids3:
                try:
                    delete_videoupload(vid3)
                    vid3.youtube_video_expiry_date = None
                    vid3.save()
                    print "Deleted video file on server: ", vid3.title
                    message = \
"""
Hello %(username)s,

    The following videos have been deleted from %(site)s today, %(now)s!

        %(deletable_video_names)s

    The video has already exceeded the allowable time it would be stored on %(site)s.com, for further info contact us.


Thanks,

-------------------------
%(site)s Team
""" % \
                    ({'username': uploader.username,
                      'now': datetime.date.today().isoformat(),
                      'deletable_video_names': clear_videoupload_names,
                      'site': SITE,})

                    send_mail('%s: Video Deleted' % SITE,
                              message,
                              "no-reply@%s.com" % SITE.lower(),
                              [uploader.email], fail_silently=False)
                    print "Email Sent to %s" % uploader.username
                except os.error:
                    print 'ERROR when deleting'
예제 #12
0
def upgrade_account(request):
    """
    View that handles upgrading from a Free account to a Paid account via
    Authorize.net
    
    Note: Authorize.net payment option is currently on backlog
    
    """
    error_message = ""
    success_message = ""
    if request.user.userprofile.account_level.level == 'Paid':
        error_message = "You already have a Paid account."

    if request.method == 'POST':
        form = PaymentInformationForm(request.POST)
        if form.is_valid():
            paid_account = AccountLevel.objects.get(pk=2)
            r = authorize.call_auth(
                paid_account,
                unicode(paid_account.authnet_item_price),
                data={
                    'card_number': form.cleaned_data['card_number'],
                    'expiry': form.cleaned_data['expiry_date'],
                    'card_code': form.cleaned_data['card_code'],
                    'first_name': form.cleaned_data['first_name'],
                    'last_name': form.cleaned_data['last_name'],
                    'company': form.cleaned_data['company'],
                    'address': form.cleaned_data['address'],
                    'city': form.cleaned_data['city'],
                    'state': form.cleaned_data['state'],
                    'province': form.cleaned_data['province'],
                    'country': form.cleaned_data['country'],
                    'zip_code': form.cleaned_data['zip_code'],
                    'email': form.cleaned_data['email'],
                    'phone': form.cleaned_data['phone']
                },
            )
            success_message = ""
            if r.split('|')[0] == '1':
                trans_id = r.split('|')[6]
                r = authorize.call_capture(trans_id)
                if r.split('|')[0] == '1':
                    error_message = ""
                    userprofile = UserProfile.objects.get(
                        user__id=request.user.id)
                    if userprofile.account_level.level == 'Trial':
                        userprofile.trial_ended = True
                        userprofile.trial_expiry_date = None
                    userprofile.account_level = paid_account
                    api_key_len = UserProfile._meta.get_field('api_key')
                    userprofile.api_key = generate_api_key(api_key_len)
                    userprofile.save()
                    form = PaymentInformationForm(request.POST)
                    success_message = "Payment Accepted"
                    form = PaymentInformationForm(request.POST)

                    # Update user's videos expiration dates
                    vids = Video.objects.filter(uploader=request.user)
                    for vid in vids:
                        is_expired(vid)
                else:
                    error_message = r.split('|')[3]
                    form = PaymentInformationForm(request.POST)
            else:
                error_message = "%s" % (r.split('|')[3])
                form = PaymentInformationForm(request.POST)
    else:
        form = PaymentInformationForm()

    context = {
        'form': form,
        'error_message': error_message,
        'success_message': success_message,
    }
    return render(request, 'purchase.html', context)