Exemple #1
0
def edit(request, id, form_class=DirectoryForm, template_name="directories/edit.html"):
    directory = get_object_or_404(Directory, pk=id)

    if not has_perm(request.user,'directories.change_directory', directory):
        raise Http403
    
    form = form_class(request.POST or None, request.FILES or None, 
                      instance=directory, 
                      user=request.user)
    
    del form.fields['payment_method']
    if not request.user.profile.is_superuser:
        del form.fields['pricing']
        del form.fields['list_type']
    
    if request.method == "POST":
        if form.is_valid():
            directory = form.save(commit=False)
            
            if directory.logo:
                try:
                    directory.logo.file.seek(0)
                except IOError:
                    directory.logo = None
            # update all permissions and save the model
            directory = update_perms_and_save(request, form, directory)

            # resize the image that has been uploaded
            if directory.logo:
                if settings.USE_S3_STORAGE:
                    resize_s3_image(directory.logo.name)
                else:
                    try:
                        logo = Image.open(directory.logo.path)
                        logo.thumbnail((200,200),Image.ANTIALIAS)
                        logo.save(directory.logo.path)
                    except:
                        pass

            messages.add_message(request, messages.SUCCESS, 'Successfully updated %s' % directory)
                                                                         
            return HttpResponseRedirect(reverse('directory', args=[directory.slug]))             
        else:
            form = form_class(instance=directory, user=request.user)

        return render_to_response(template_name, {'directory': directory, 'form':form}, 
            context_instance=RequestContext(request))


    return render_to_response(template_name, {'directory': directory, 'form':form}, 
        context_instance=RequestContext(request))
Exemple #2
0
def edit(request, id, form_class=DirectoryForm, template_name="directories/edit.html"):
    directory = get_object_or_404(Directory, pk=id)

    if not has_perm(request.user,'directories.change_directory', directory):
        raise Http403
    
    form = form_class(request.POST or None, request.FILES or None, 
                      instance=directory, 
                      user=request.user)
    
    del form.fields['payment_method']
    if not request.user.profile.is_superuser:
        del form.fields['pricing']
        del form.fields['list_type']
    
    if request.method == "POST":
        if form.is_valid():
            directory = form.save(commit=False)
            
            if directory.logo:
                directory.logo.file.seek(0)
            # update all permissions and save the model
            directory = update_perms_and_save(request, form, directory)

            # resize the image that has been uploaded
            if directory.logo:
                if settings.USE_S3_STORAGE:
                    resize_s3_image(directory.logo.name)
                else:
                    try:
                        logo = Image.open(directory.logo.path)
                        logo.thumbnail((200,200),Image.ANTIALIAS)
                        logo.save(directory.logo.path)
                    except:
                        pass

            messages.add_message(request, messages.SUCCESS, 'Successfully updated %s' % directory)
                                                                         
            return HttpResponseRedirect(reverse('directory', args=[directory.slug]))             
        else:
            form = form_class(instance=directory, user=request.user)

        return render_to_response(template_name, {'directory': directory, 'form':form}, 
            context_instance=RequestContext(request))


    return render_to_response(template_name, {'directory': directory, 'form':form}, 
        context_instance=RequestContext(request))
Exemple #3
0
def add(request, form_class=DirectoryForm, template_name="directories/add.html"):
    can_add_active = has_perm(request.user,'directories.add_directory')
    
    if not any([request.user.profile.is_superuser,
               can_add_active,
               get_setting('module', 'directories', 'usercanadd'),
               (request.user.profile.is_member and get_setting('module', 'directories', 'directoriesrequiresmembership'))
               ]):
        raise Http403

    pricings = DirectoryPricing.objects.filter(status=True)
    if not pricings and has_perm(request.user, 'directories.add_directorypricing'):
        messages.add_message(request, messages.WARNING, 'You need to add a %s Pricing before you can add %s.' % (get_setting('module', 'directories', 'label_plural'),get_setting('module', 'directories', 'label')))
        return HttpResponseRedirect(reverse('directory_pricing.add'))     

    require_payment = get_setting('module', 'directories', 'directoriesrequirespayment')
    
    form = form_class(request.POST or None, request.FILES or None, user=request.user)
    
    if not require_payment:
        del form.fields['payment_method']
        del form.fields['list_type']

    if request.method == "POST":
        if require_payment:
            is_free = is_free_listing(request.user,
                               request.POST.get('pricing', 0),
                               request.POST.get('list_type'))
            if is_free:
                del form.fields['payment_method']

        if form.is_valid():
            directory = form.save(commit=False)
            pricing = form.cleaned_data['pricing']

            if require_payment and is_free:
                directory.payment_method = 'paid - cc'
            if directory.payment_method:
                directory.payment_method = directory.payment_method.lower()
            if not directory.requested_duration:
                directory.requested_duration = 30
            if not directory.list_type:
                directory.list_type = 'regular'
            
            if not directory.slug:
                directory.slug = '%s-%s' % (slugify(directory.headline), Directory.objects.count())
            
            if not can_add_active:
                directory.status = True
                directory.status_detail = 'pending'
            else:
                directory.activation_dt = datetime.now()
                # set the expiration date
                directory.expiration_dt = directory.activation_dt + timedelta(days=directory.requested_duration)

            # We set the logo to None temporarily because we need
            # the PK when we save to get the filepath of the file
            logo = directory.logo
            directory.logo = None

            directory = update_perms_and_save(request, form, directory)

            # directory now has a pk, so we can reassign the logo
            # and resave
            directory.logo = logo

            if directory.logo:
                directory.logo.file.seek(0)

                directory.save(log=False)

                if settings.USE_S3_STORAGE:
                    resize_s3_image(directory.logo.name)
                else:
                    try:
                        logo = Image.open(directory.logo.path)
                        logo.thumbnail((200,200),Image.ANTIALIAS)
                        logo.save(directory.logo.path)
                    except:
                        pass                
                        
            # create invoice
            directory_set_inv_payment(request.user, directory, pricing)

            messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % directory)
            
            # send notification to administrators
            # get admin notice recipients
            recipients = get_notice_recipients('module', 'directories', 'directoryrecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': directory,
                        'request': request,
                    }
                    notification.send_emails(recipients,'directory_added', extra_context)
                    
            if directory.payment_method.lower() in ['credit card', 'cc']:
                if directory.invoice and directory.invoice.balance > 0:
                    return HttpResponseRedirect(reverse('payment.pay_online', args=[directory.invoice.id, directory.invoice.guid])) 
            if can_add_active:  
                return HttpResponseRedirect(reverse('directory', args=[directory.slug])) 
            else:
                return HttpResponseRedirect(reverse('directory.thank_you'))             

    return render_to_response(template_name,
                              {'form': form,
                               'require_payment': require_payment},
        context_instance=RequestContext(request))
Exemple #4
0
def add(request, form_class=DirectoryForm, template_name="directories/add.html"):
    can_add_active = has_perm(request.user,'directories.add_directory')
    
    if not any([request.user.profile.is_superuser,
               can_add_active,
               get_setting('module', 'directories', 'usercanadd'),
               (request.user.profile.is_member and get_setting('module', 'directories', 'directoriesrequiresmembership'))
               ]):
        raise Http403
     
    require_payment = get_setting('module', 'directories', 'directoriesrequirespayment')
    
    form = form_class(request.POST or None, request.FILES or None, user=request.user)
    
    if not require_payment:
        del form.fields['payment_method']
        del form.fields['list_type']

    if request.method == "POST":   
        if form.is_valid():           
            directory = form.save(commit=False)
            pricing = form.cleaned_data['pricing']
            
            if directory.payment_method: 
                directory.payment_method = directory.payment_method.lower()
            if not directory.requested_duration:
                directory.requested_duration = 30
            if not directory.list_type:
                directory.list_type = 'regular'
            
            if not directory.slug:
                directory.slug = '%s-%s' % (slugify(directory.headline), Directory.objects.count())
            
            if not can_add_active:
                directory.status = True
                directory.status_detail = 'pending'
            else:
                directory.activation_dt = datetime.now()
                # set the expiration date
                directory.expiration_dt = directory.activation_dt + timedelta(days=directory.requested_duration)

            if directory.logo:
                directory.logo.file.seek(0)
            # update all permissions and save the model
            directory = update_perms_and_save(request, form, directory)
            
            # resize the image that has been uploaded
            if directory.logo:
                if settings.USE_S3_STORAGE:
                    resize_s3_image(directory.logo.name)
                else:
                    try:
                        logo = Image.open(directory.logo.path)
                        logo.thumbnail((200,200),Image.ANTIALIAS)
                        logo.save(directory.logo.path)
                    except:
                        pass                
                        
            # create invoice
            directory_set_inv_payment(request.user, directory, pricing)

            messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % directory)
            
            # send notification to administrators
            # get admin notice recipients
            recipients = get_notice_recipients('module', 'directories', 'directoryrecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': directory,
                        'request': request,
                    }
                    notification.send_emails(recipients,'directory_added', extra_context)
                    
            if directory.payment_method.lower() in ['credit card', 'cc']:
                if directory.invoice and directory.invoice.balance > 0:
                    return HttpResponseRedirect(reverse('payments.views.pay_online', args=[directory.invoice.id, directory.invoice.guid])) 
            if can_add_active:  
                return HttpResponseRedirect(reverse('directory', args=[directory.slug])) 
            else:
                return HttpResponseRedirect(reverse('directory.thank_you'))             

    return render_to_response(template_name, {'form':form}, 
        context_instance=RequestContext(request))
Exemple #5
0
def add(request,
        form_class=DirectoryForm,
        template_name="directories/add.html"):
    can_add_active = has_perm(request.user, 'directories.add_directory')

    if not any([
            request.user.profile.is_superuser, can_add_active,
            get_setting('module', 'directories', 'usercanadd'),
        (request.user.profile.is_member and get_setting(
            'module', 'directories', 'directoriesrequiresmembership'))
    ]):
        raise Http403

    pricings = DirectoryPricing.objects.filter(status=True)
    if not pricings and has_perm(request.user,
                                 'directories.add_directorypricing'):
        messages.add_message(
            request, messages.WARNING,
            'You need to add a %s Pricing before you can add %s.' %
            (get_setting('module', 'directories', 'label_plural'),
             get_setting('module', 'directories', 'label')))
        return HttpResponseRedirect(reverse('directory_pricing.add'))

    require_payment = get_setting('module', 'directories',
                                  'directoriesrequirespayment')

    form = form_class(request.POST or None,
                      request.FILES or None,
                      user=request.user)

    if not require_payment:
        del form.fields['payment_method']
        del form.fields['list_type']

    if request.method == "POST":
        if require_payment:
            is_free = is_free_listing(request.user,
                                      request.POST.get('pricing', 0),
                                      request.POST.get('list_type'))
            if is_free:
                del form.fields['payment_method']

        if form.is_valid():
            directory = form.save(commit=False)
            pricing = form.cleaned_data['pricing']

            if require_payment and is_free:
                directory.payment_method = 'paid - cc'
            if directory.payment_method:
                directory.payment_method = directory.payment_method.lower()
            if not directory.requested_duration:
                directory.requested_duration = 30
            if not directory.list_type:
                directory.list_type = 'regular'

            if not directory.slug:
                directory.slug = '%s-%s' % (slugify(
                    directory.headline), Directory.objects.count())

            if not can_add_active:
                directory.status = True
                directory.status_detail = 'pending'
            else:
                directory.activation_dt = datetime.now()
                # set the expiration date
                directory.expiration_dt = directory.activation_dt + timedelta(
                    days=directory.requested_duration)

            # We set the logo to None temporarily because we need
            # the PK when we save to get the filepath of the file
            logo = directory.logo
            directory.logo = None

            directory = update_perms_and_save(request, form, directory)

            # directory now has a pk, so we can reassign the logo
            # and resave
            directory.logo = logo

            if directory.logo:
                directory.logo.file.seek(0)

                directory.save(log=False)

                if settings.USE_S3_STORAGE:
                    resize_s3_image(directory.logo.name)
                else:
                    try:
                        logo = Image.open(directory.logo.path)
                        logo.thumbnail((200, 200), Image.ANTIALIAS)
                        logo.save(directory.logo.path)
                    except:
                        pass

            # create invoice
            directory_set_inv_payment(request.user, directory, pricing)

            messages.add_message(request, messages.SUCCESS,
                                 'Successfully added %s' % directory)

            # send notification to administrators
            # get admin notice recipients
            recipients = get_notice_recipients('module', 'directories',
                                               'directoryrecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': directory,
                        'request': request,
                    }
                    notification.send_emails(recipients, 'directory_added',
                                             extra_context)

            if directory.payment_method.lower() in ['credit card', 'cc']:
                if directory.invoice and directory.invoice.balance > 0:
                    return HttpResponseRedirect(
                        reverse('payment.pay_online',
                                args=[
                                    directory.invoice.id,
                                    directory.invoice.guid
                                ]))
            if can_add_active:
                return HttpResponseRedirect(
                    reverse('directory', args=[directory.slug]))
            else:
                return HttpResponseRedirect(reverse('directory.thank_you'))

    return render_to_response(template_name, {
        'form': form,
        'require_payment': require_payment
    },
                              context_instance=RequestContext(request))
Exemple #6
0
def add(request, form_class=DirectoryForm, template_name="directories/add.html"):
    can_add_active = has_perm(request.user, "directories.add_directory")

    if not any(
        [
            request.user.profile.is_superuser,
            can_add_active,
            get_setting("module", "directories", "usercanadd"),
            (request.user.profile.is_member and get_setting("module", "directories", "directoriesrequiresmembership")),
        ]
    ):
        raise Http403

    pricings = DirectoryPricing.objects.filter(status=True)
    if not pricings and has_perm(request.user, "directories.add_directorypricing"):
        messages.add_message(
            request,
            messages.WARNING,
            "You need to add a %s Pricing before you can add %s."
            % (get_setting("module", "directories", "label_plural"), get_setting("module", "directories", "label")),
        )
        return HttpResponseRedirect(reverse("directory_pricing.add"))

    require_payment = get_setting("module", "directories", "directoriesrequirespayment")

    form = form_class(request.POST or None, request.FILES or None, user=request.user)

    if not require_payment:
        del form.fields["payment_method"]
        del form.fields["list_type"]

    if request.method == "POST":
        if form.is_valid():
            directory = form.save(commit=False)
            pricing = form.cleaned_data["pricing"]

            if directory.payment_method:
                directory.payment_method = directory.payment_method.lower()
            if not directory.requested_duration:
                directory.requested_duration = 30
            if not directory.list_type:
                directory.list_type = "regular"

            if not directory.slug:
                directory.slug = "%s-%s" % (slugify(directory.headline), Directory.objects.count())

            if not can_add_active:
                directory.status = True
                directory.status_detail = "pending"
            else:
                directory.activation_dt = datetime.now()
                # set the expiration date
                directory.expiration_dt = directory.activation_dt + timedelta(days=directory.requested_duration)

            # We set the logo to None temporarily because we need
            # the PK when we save to get the filepath of the file
            logo = directory.logo
            directory.logo = None

            directory = update_perms_and_save(request, form, directory)

            # directory now has a pk, so we can reassign the logo
            # and resave
            directory.logo = logo

            if directory.logo:
                directory.logo.file.seek(0)

                directory.save(log=False)

                if settings.USE_S3_STORAGE:
                    resize_s3_image(directory.logo.name)
                else:
                    try:
                        logo = Image.open(directory.logo.path)
                        logo.thumbnail((200, 200), Image.ANTIALIAS)
                        logo.save(directory.logo.path)
                    except:
                        pass

            # create invoice
            directory_set_inv_payment(request.user, directory, pricing)

            messages.add_message(request, messages.SUCCESS, "Successfully added %s" % directory)

            # send notification to administrators
            # get admin notice recipients
            recipients = get_notice_recipients("module", "directories", "directoryrecipients")
            if recipients:
                if notification:
                    extra_context = {"object": directory, "request": request}
                    notification.send_emails(recipients, "directory_added", extra_context)

            if directory.payment_method.lower() in ["credit card", "cc"]:
                if directory.invoice and directory.invoice.balance > 0:
                    return HttpResponseRedirect(
                        reverse("payment.pay_online", args=[directory.invoice.id, directory.invoice.guid])
                    )
            if can_add_active:
                return HttpResponseRedirect(reverse("directory", args=[directory.slug]))
            else:
                return HttpResponseRedirect(reverse("directory.thank_you"))

    return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))