Exemple #1
0
def group_delete(request, id, template_name="user_groups/delete.html"):
    group = get_object_or_404(Group, pk=id)
    
    if not has_perm(request.user,'user_groups.delete_group',group): raise Http403

    if request.method == "POST":
        # send notification to administrators
        recipients = get_notice_recipients('module', 'groups', 'grouprecipients')
        if recipients: 
            if notification:
                extra_context = {
                    'object': group,
                    'request': request,
                }
                notification.send_emails(recipients,'group_deleted', extra_context)
                    
        log_defaults = {
            'event_id' : 163000,
            'event_data': '%s (%d) deleted by %s' % (group._meta.object_name, group.pk, request.user),
            'description': '%s deleted' % group._meta.object_name,
            'user': request.user,
            'request': request,
            'instance': group,
        }
        EventLog.objects.log(**log_defaults)

        group.delete()
        return HttpResponseRedirect(reverse('group.search'))

    return render_to_response(template_name, {'group':group}, 
        context_instance=RequestContext(request))
Exemple #2
0
def delete(request, id, template_name="news/delete.html"):
    news = get_object_or_404(News, pk=id)

    # check permission
    if not has_perm(request.user, "news.delete_news"):
        raise Http403

    if request.method == "POST":
        log_defaults = {
            "event_id": 305300,
            "event_data": "%s (%d) deleted by %s" % (news._meta.object_name, news.pk, request.user),
            "description": "%s deleted" % news._meta.object_name,
            "user": request.user,
            "request": request,
            "instance": news,
        }
        EventLog.objects.log(**log_defaults)
        messages.add_message(request, messages.SUCCESS, "Successfully deleted %s" % news)

        # send notification to administrators
        recipients = get_notice_recipients("module", "news", "newsrecipients")
        if recipients:
            if notification:
                extra_context = {"object": news, "request": request}
                notification.send_emails(recipients, "news_deleted", extra_context)

        news.delete()
        return HttpResponseRedirect(reverse("news.search"))

    return render_to_response(template_name, {"news": news}, context_instance=RequestContext(request))
Exemple #3
0
def delete(request, id, template_name="resumes/delete.html"):
    resume = get_object_or_404(Resume, pk=id)

    if has_perm(request.user,'resumes.delete_resume'):   
        if request.method == "POST":
            log_defaults = {
                'event_id' : 433000,
                'event_data': '%s (%d) deleted by %s' % (resume._meta.object_name, resume.pk, request.user),
                'description': '%s deleted' % resume._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': resume,
            }
            
            EventLog.objects.log(**log_defaults)
            messages.add_message(request, messages.SUCCESS, 'Successfully deleted %s' % resume)
            
            # send notification to administrators
            recipients = get_notice_recipients('module', 'resumes', 'resumerecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': resume,
                        'request': request,
                    }
                    notification.send_emails(recipients,'resume_deleted', extra_context)
            
            resume.delete()
                
            return HttpResponseRedirect(reverse('resume.search'))
    
        return render_to_response(template_name, {'resume': resume}, 
            context_instance=RequestContext(request))
    else:
        raise Http403
Exemple #4
0
def send_notifications(scope, scope_category, name, label, extra_context=None):
    """
        a small wrapper for sending notification emails to 
        recipients specified in site_settings.
    """
    recipients = get_notice_recipients(scope, scope_category, name)
    if recipients:
        send_emails(recipients, label, extra_context)
Exemple #5
0
def add(request, form_class=ResumeForm, template_name="resumes/add.html"):

    can_add_active = has_perm(request.user, 'resumes.add_resume')

    if request.method == "POST":
        form = form_class(request.POST, user=request.user)
        if form.is_valid():
            resume = form.save(commit=False)

            # set it to pending if the user does not have add permission
            if not can_add_active:
                resume.status = 0
                resume.status_detail = 'pending'

            # set up the expiration time based on requested duration
            now = now_localized()
            resume.expiration_dt = now + timedelta(days=resume.requested_duration)

            resume = update_perms_and_save(request, form, resume)

            log_defaults = {
                'event_id' : 351000,
                'event_data': '%s (%d) added by %s' % (resume._meta.object_name, resume.pk, request.user),
                'description': '%s added' % resume._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': resume,
            }
            EventLog.objects.log(**log_defaults)

            if request.user.is_authenticated():
                messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % resume)

            # send notification to administrators
            recipients = get_notice_recipients('module', 'resumes', 'resumerecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': resume,
                        'request': request,
                    }
                    notification.send_emails(recipients,'resume_added', extra_context)

            if not request.user.is_authenticated():
                return HttpResponseRedirect(reverse('resume.thank_you'))
            else:
                return HttpResponseRedirect(reverse('resume', args=[resume.slug]))
    else:
        form = form_class(user=request.user)

    return render_to_response(template_name, {'form':form},
        context_instance=RequestContext(request))
Exemple #6
0
def request_new(request, template_name="help_files/request_new.html"):
    "Request new file form"
    if request.method == "POST":
        form = RequestForm(request.POST)
        if form.is_valid():
            instance = form.save()
            # send notification to administrators
            recipients = get_notice_recipients("module", "help_files", "helpfilerecipients")
            if recipients:
                if notification:
                    extra_context = {"object": instance, "request": request}
                    notification.send_emails(recipients, "help_file_requested", extra_context)
            messages.add_message(request, messages.INFO, "Thanks for requesting a new help file!")
            return HttpResponseRedirect(reverse("help_files"))
    else:
        form = RequestForm()

    return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))
Exemple #7
0
    def save_model(self, request, object, form, change):
        instance = form.save(commit=False)

        # update all permissions and save the model
        instance = update_perms_and_save(request, form, instance)

        # notifications
        if not is_admin(request.user):
            # send notification to administrators
            recipients = get_notice_recipients('site', 'global', 'allnoticerecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': instance,
                        'request': request,
                    }
                    notification.send_emails(recipients, notice_type, extra_context)

        return instance
Exemple #8
0
def delete(request, id, template_name="profiles/delete.html"):
    user = get_object_or_404(User, pk=id)
    try:
        profile = Profile.objects.get(user=user)
    except:
        profile = None
    
    if not has_perm(request.user,'profiles.delete_profile',profile): raise Http403

    if request.method == "POST":
        recipients = get_notice_recipients('module', 'users', 'userrecipients')
        if recipients:
            if notification:
                extra_context = {
                    'profile': profile,
                    'request': request,
                }
                notification.send_emails(recipients,'user_deleted', extra_context)
        #soft delete
        #profile.delete()
        #user.delete()
        if profile:
            profile.status_detail = 'inactive'
            profile.save()
        user.is_active = False
        user.save()

        log_defaults = {
            'event_id' : 123000,
            'event_data': '%s (%d) deleted by %s' % (user._meta.object_name, user.pk, request.user),
            'description': '%s deleted' % user._meta.object_name,
            'user': request.user,
            'request': request,
            'instance': user,
        }
        EventLog.objects.log(**log_defaults)
        
        
        return HttpResponseRedirect(reverse('profile.search'))

    return render_to_response(template_name, {'user_this':user, 'profile': profile}, 
        context_instance=RequestContext(request))
Exemple #9
0
def edit(request, id=None, form_class=HelpFileForm, template_name="help_files/edit.html"):
    help_file = get_object_or_404(HelpFile, pk=id)
    if has_perm(request.user, "help_files.change_helpfile", help_file):
        if request.method == "POST":
            form = form_class(request.POST, instance=help_file, user=request.user)
            if form.is_valid():
                help_file = form.save(commit=False)

                # add all permissions and save the model
                help_file = update_perms_and_save(request, form, help_file)
                form.save_m2m()

                log_defaults = {
                    "event_id": 1000200,
                    "event_data": "%s (%d) edited by %s" % (help_file._meta.object_name, help_file.pk, request.user),
                    "description": "%s edited" % help_file._meta.object_name,
                    "user": request.user,
                    "request": request,
                    "instance": help_file,
                }
                EventLog.objects.log(**log_defaults)

                messages.add_message(request, messages.SUCCESS, "Successfully edited %s" % help_file)

                # send notification to administrator(s) and module recipient(s)
                recipients = get_notice_recipients("module", "help_files", "helpfilerecipients")
                # if recipients and notification:
                #                     notification.send_emails(recipients,'help_file_added', {
                #                         'object': help_file,
                #                         'request': request,
                #                     })

                return HttpResponseRedirect(reverse("help_file.details", args=[help_file.slug]))
        else:
            form = form_class(instance=help_file, user=request.user)

        return render_to_response(
            template_name, {"help_file": help_file, "form": form}, context_instance=RequestContext(request)
        )
    else:
        raise Http403
Exemple #10
0
    def save_model(self, request, object, form, change):
        instance = form.save(commit=False)

        instance = update_perms_and_save(request, form, instance)
        
        # notifications
        if not is_admin(request.user):
            # send notification to administrators
            recipients = get_notice_recipients('module', 'pages', 'pagerecipients')
            notice_type = 'page_added'
            if change: notice_type = 'page_edited' 
            if recipients:
                if notification:
                    extra_context = {
                        'object': instance,
                        'request': request,
                    }
                    notification.send_emails(recipients, notice_type, extra_context)

        return instance

# admin.site.register(Page, PageAdmin)
Exemple #11
0
def add(request, form_class=ArticleForm, template_name="articles/add.html"):
    if has_perm(request.user,'articles.add_article'):
        if request.method == "POST":
            form = form_class(request.POST, user=request.user)
            if form.is_valid():           
                article = form.save(commit=False)

                # add all permissions and save the model
                articles = update_perms_and_save(request, form, article)

                log_defaults = {
                    'event_id' : 431000,
                    'event_data': '%s (%d) added by %s' % (article._meta.object_name, article.pk, request.user),
                    'description': '%s added' % article._meta.object_name,
                    'user': request.user,
                    'request': request,
                    'instance': article,
                }
                EventLog.objects.log(**log_defaults)
                
                messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % article)
                
                # send notification to administrator(s) and module recipient(s)
                recipients = get_notice_recipients('module', 'articles', 'articlerecipients')
                if recipients and notification: 
                    notification.send_emails(recipients,'article_added', {
                        'object': article,
                        'request': request,
                    })

                return HttpResponseRedirect(reverse('article', args=[article.slug]))
        else:
            form = form_class(user=request.user)
           
        return render_to_response(template_name, {'form':form}, 
            context_instance=RequestContext(request))
    else:
        raise Http403
Exemple #12
0
def add(request, form_class=NewsForm, template_name="news/add.html"):

    # check permission
    if not has_perm(request.user, "news.add_news"):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST, user=request.user)
        if form.is_valid():
            news = form.save(commit=False)

            # update all permissions and save the model
            news = update_perms_and_save(request, form, news)

            log_defaults = {
                "event_id": 305100,
                "event_data": "%s (%d) added by %s" % (news._meta.object_name, news.pk, request.user),
                "description": "%s added" % news._meta.object_name,
                "user": request.user,
                "request": request,
                "instance": news,
            }
            EventLog.objects.log(**log_defaults)

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

            # send notification to administrators
            recipients = get_notice_recipients("module", "news", "newsrecipients")
            if recipients:
                if notification:
                    extra_context = {"object": news, "request": request}
                    notification.send_emails(recipients, "news_added", extra_context)

            return HttpResponseRedirect(reverse("news.view", args=[news.slug]))
    else:
        form = form_class(user=request.user)

    return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))
Exemple #13
0
def edit(request, id, form_class=ProfileForm, template_name="profiles/edit.html"):
    user_edit = get_object_or_404(User, pk=id)
    
    try:
        profile = Profile.objects.get(user=user_edit)
    except Profile.DoesNotExist:
        profile = Profile.objects.create_profile(user=user_edit)
        
    if not profile.allow_edit_by(request.user): raise Http403
    
    required_fields = get_setting('module', 'users', 'usersrequiredfields')
    if required_fields:
        required_fields_list = required_fields.split(',')
        required_fields_list = [field.strip() for field in required_fields_list]
    else:
        required_fields_list = None
       
    if request.method == "POST":
        form = form_class(request.POST, 
                          user_current=request.user,
                          user_this=user_edit,
                          required_fields_list=required_fields_list,
                          instance=profile)
        
        if form.is_valid():
            # get the old profile, so we know what has been changed in admin notification
            old_user = User.objects.get(id=id)
            old_profile = Profile.objects.get(user=old_user)
            profile = form.save(request, user_edit)
           
            if is_admin(request.user):
                security_level = form.cleaned_data['security_level']
                
                if security_level == 'developer':
                    user_edit.is_superuser = 1
                    user_edit.is_staff = 1
                    # remove them from auth_group if any - they don't need it
                    user_edit.groups = []
                elif security_level == 'admin':
                    user_edit.is_superuser = 0
                    user_edit.is_staff = 1
                    
                    # add them to admin auth group
                    user_add_remove_admin_auth_group(user_edit)
                else:
                    user_edit.is_superuser = 0
                    user_edit.is_staff = 0
                    # remove them from auth_group if any
                    user_edit.groups = []
                    
                # add them to admin auth group
                user_add_remove_admin_auth_group(user_edit)
                    
                # set up user permission
                profile.allow_user_view, profile.allow_user_edit = False, False
                
            else:
                user_edit.is_superuser = 0
                user_edit.is_staff = 0
                
            # interactive
            interactive = form.cleaned_data['interactive']
            try:
                interactive = int(interactive)
            except:
                interactive = 0
            if interactive == 1:
                user_edit.is_active = 1
            else:
                user_edit.is_active = 0
               
            profile.save()
            user_edit.save()
            
            # notify ADMIN of update to a user's record
            if get_setting('module', 'users', 'userseditnotifyadmin'):
            #    profile_edit_admin_notify(request, old_user, old_profile, profile)
                # send notification to administrators
                recipients = get_notice_recipients('module', 'users', 'userrecipients')
                if recipients:
                    if notification:
                        extra_context = {
                            'old_user': old_user,
                            'old_profile': old_profile,
                            'profile': profile,
                            'request': request,
                        }
                        notification.send_emails(recipients,'user_edited', extra_context)
            

            log_defaults = {
                'event_id' : 122000,
                'event_data': '%s (%d) edited by %s' % (user_edit._meta.object_name, user_edit.pk, request.user),
                'description': '%s edited' % user_edit._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': user_edit,
            }
            EventLog.objects.log(**log_defaults)
            return HttpResponseRedirect(reverse('profile', args=[user_edit.username]))
    else:
        if profile:
            form = form_class(user_current=request.user,
                          user_this=user_edit,
                          required_fields_list=required_fields_list,
                          instance=profile)
            
        else:
            form = form_class(user_current=request.user,
                          user_this=user_edit,
                          required_fields_list=required_fields_list)

    return render_to_response(template_name, {'user_this':user_edit, 'profile':profile, 'form':form,
                                              'required_fields_list':required_fields_list}, 
        context_instance=RequestContext(request))
Exemple #14
0
def add(request, form_class=ProfileForm, template_name="profiles/add.html"):
    if not has_perm(request.user,'profiles.add_profile'):raise Http403
    
    required_fields = get_setting('module', 'users', 'usersrequiredfields')
    if required_fields:
        required_fields_list = required_fields.split(',')
        required_fields_list = [field.strip() for field in required_fields_list]
    else:
        required_fields_list = None
    
    if request.method == "POST":
        form = form_class(request.POST, 
                          user_current=request.user,
                          user_this=None,
                          required_fields_list=required_fields_list)
        
        if form.is_valid():
            profile = form.save(request, None)
            new_user = profile.user
            
            # security_level
            if is_admin(request.user):
                security_level = form.cleaned_data['security_level']
                if security_level == 'developer':
                    new_user.is_superuser = 1
                    new_user.is_staff = 1
                elif security_level == 'admin':
                    new_user.is_superuser = 0
                    new_user.is_staff = 1
                    
                    # add them to admin auth group
                    user_add_remove_admin_auth_group(new_user)
                        
                else:
                    new_user.is_superuser = 0
                    new_user.is_staff = 0

                # set up user permission
                profile.allow_user_view, profile.allow_user_edit = False, False
                    
            else:
                new_user.is_superuser = 0
                new_user.is_staff = 0
                
            # interactive
            interactive = form.cleaned_data['interactive']
            try:
                interactive = int(interactive)
            except:
                interactive = 0

            new_user.is_active = interactive

            profile.save()
            new_user.save()

            ObjectPermission.objects.assign(new_user, profile)

            log_defaults = {
                'event_id' : 121000,
                'event_data': '%s (%d) added by %s' % (new_user._meta.object_name, new_user.pk, request.user),
                'description': '%s added' % new_user._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': new_user,
            }
            EventLog.objects.log(**log_defaults)
            
            # send notification to administrators
            recipients = get_notice_recipients('module', 'users', 'userrecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': profile,
                        'request': request,
                    }
                    notification.send_emails(recipients,'user_added', extra_context)
           
            return HttpResponseRedirect(reverse('profile', args=[new_user.username]))
    else:
        form = form_class(user_current=request.user,
                          user_this=None,
                          required_fields_list=required_fields_list)
    auto_pwd = request.POST.get('auto_pwd')
    return render_to_response(template_name, {'form':form, 'user_this':None,
                                              'required_fields_list': required_fields_list,
                                              'auto_pwd': auto_pwd
                                              }, 
        context_instance=RequestContext(request))
Exemple #15
0
def add(request, form_class=JobForm, template_name="jobs/add.html"):
    require_payment = get_setting('module', 'jobs', 'jobsrequirespayment')
    
    can_add_active = has_perm(request.user, 'jobs.add_job')
    
    content_type = get_object_or_404(ContentType, app_label='jobs',model='job')
    
    if is_admin(request.user):
        category_form_class = CategoryForm
    else:
        category_form_class = CategoryForm2
    
    if request.method == "POST":
        form = form_class(request.POST, user=request.user)
        categoryform = category_form_class(
                        content_type, 
                        request.POST,
                        prefix='category')

        # adjust the fields depending on user type
        if not require_payment:
            del form.fields['payment_method']
            del form.fields['list_type']

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

            # set it to pending if the user is anonymous or not an admin
            if not can_add_active:
                #job.status = 1
                job.status_detail = 'pending'

            # list types and duration
            if not job.requested_duration:
                job.requested_duration = 30
            if not job.list_type:
                job.list_type = 'regular'

            # set up all the times
            now = now_localized()
            job.activation_dt = now
            if not job.post_dt:
                job.post_dt = now

            # set the expiration date
            job.expiration_dt = job.activation_dt + timedelta(days=job.requested_duration)
            
            # semi-anon job posts don't get a slug field on the form
            # see __init__ method in JobForm
            if not job.slug:
                #job.slug = get_job_unique_slug(slugify(job.title))
                job.slug = '%s-%s' % (slugify(job.title), Job.objects.count())

            job = update_perms_and_save(request, form, job)

            # create invoice
            job_set_inv_payment(request.user, job, pricing)
            
            #setup categories
            category = Category.objects.get_for_object(job,'category')
            sub_category = Category.objects.get_for_object(job,'sub_category')
            
            ## update the category of the article
            category_removed = False
            category = categoryform.cleaned_data['category']
            if category != '0': 
                Category.objects.update(job,category,'category')
            else: # remove
                category_removed = True
                Category.objects.remove(job,'category')
                Category.objects.remove(job,'sub_category')
            
            if not category_removed:
                # update the sub category of the article
                sub_category = categoryform.cleaned_data['sub_category']
                if sub_category != '0': 
                    Category.objects.update(job, sub_category,'sub_category')
                else: # remove
                    Category.objects.remove(job,'sub_category') 
            
            #save relationships
            job.save()
            
            log_defaults = {
                'event_id': 251000,
                'event_data': '%s (%d) added by %s' % (job._meta.object_name, job.pk, request.user),
                'description': '%s added' % job._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': job,
            }
            EventLog.objects.log(**log_defaults)

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

            # send notification to administrators
            recipients = get_notice_recipients('module', 'jobs', 'jobrecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': job,
                        'request': request,
                    }
                    notification.send_emails(recipients, 'job_added', extra_context)

            # send user to the payment page if payment is required
            if require_payment:
                if job.payment_method.lower() in ['credit card', 'cc']:
                    if job.invoice and job.invoice.balance > 0:
                        return HttpResponseRedirect(reverse(
                            'payments.views.pay_online',
                            args=[job.invoice.id, job.invoice.guid])
                        )

            # send user to thank you or view page
            if is_admin(request.user):
                return HttpResponseRedirect(reverse('job', args=[job.slug]))
            else:
                return HttpResponseRedirect(reverse('job.thank_you'))
    else:
        # Redirect user w/perms to create pricing if none exist
        pricings = JobPricing.objects.all()
        if not pricings and has_perm(request.user, 'jobs.add_jobpricing'):
            messages.add_message(request, messages.WARNING, 'You need to add a %s Pricing before you can add a %s.' % (get_setting('module', 'jobs', 'label_plural'),get_setting('module', 'jobs', 'label')))
            return HttpResponseRedirect(reverse('job_pricing.add'))

        form = form_class(user=request.user)
        initial_category_form_data = {
            'app_label': 'jobs',
            'model': 'job',
            'pk': 0, #not used for this view but is required for the form
        }
        categoryform = category_form_class(
                        content_type,
                        initial=initial_category_form_data,
                        prefix='category')
        
        # adjust the fields depending on user type
        if not require_payment:
            del form.fields['payment_method']
            del form.fields['list_type']
    
    return render_to_response(template_name, 
            {'form': form, 'categoryform':categoryform},
            context_instance=RequestContext(request))
Exemple #16
0
def add(request, form_class=PageForm, meta_form_class=MetaForm, category_form_class=CategoryForm, template_name="pages/add.html"):
    
    if not has_perm(request.user,'pages.add_page'):
        raise Http403
    
    content_type = get_object_or_404(ContentType, app_label='pages',model='page')
    
    if request.method == "POST":
        form = form_class(request.POST, user=request.user)
        metaform = meta_form_class(request.POST, prefix='meta')
        categoryform = category_form_class(content_type, request.POST, prefix='category')
        if form.is_valid() and metaform.is_valid() and categoryform.is_valid():
            page = form.save(commit=False)
            
            # add all permissions and save the model
            page = update_perms_and_save(request, form, page)
            
            #save meta
            meta = metaform.save()
            page.meta = meta
            
            #setup categories
            category = Category.objects.get_for_object(page,'category')
            sub_category = Category.objects.get_for_object(page,'sub_category')
            
            ## update the category of the article
            category_removed = False
            category = categoryform.cleaned_data['category']
            if category != '0': 
                Category.objects.update(page ,category,'category')
            else: # remove
                category_removed = True
                Category.objects.remove(page ,'category')
                Category.objects.remove(page ,'sub_category')
            
            if not category_removed:
                # update the sub category of the article
                sub_category = categoryform.cleaned_data['sub_category']
                if sub_category != '0': 
                    Category.objects.update(page, sub_category,'sub_category')
                else: # remove
                    Category.objects.remove(page,'sub_category')  
            
            #save relationships
            page.save()

            log_defaults = {
                'event_id' : 581000,
                'event_data': '%s (%d) added by %s' % (page._meta.object_name, page.pk, request.user),
                'description': '%s added' % page._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': page,
            }
            EventLog.objects.log(**log_defaults)
            
            messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % page)
            
            if not is_admin(request.user):
                # send notification to administrators
                recipients = get_notice_recipients('module', 'pages', 'pagerecipients')
                if recipients:
                    if notification:
                        extra_context = {
                            'object': page,
                            'request': request,
                        }
                        notification.send_emails(recipients,'page_added', extra_context)
                
            return HttpResponseRedirect(reverse('page', args=[page.slug]))
    else:
        initial_category_form_data = {
            'app_label': 'pages',
            'model': 'page',
            'pk': 0, #not used for this view but is required for the form
        }
        form = form_class(user=request.user)
        metaform = meta_form_class(prefix='meta')
        categoryform = category_form_class(content_type, initial=initial_category_form_data, prefix='category')
    return render_to_response(template_name, 
            {
                'form':form,
                'metaform':metaform,
                'categoryform':categoryform,
            },
            context_instance=RequestContext(request))
Exemple #17
0
def index(request, form_class=ContactForm, template_name="form.html"):

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email', None)
            first_name = form.cleaned_data.get('first_name', None)
            last_name = form.cleaned_data.get('last_name', None)
            
            if listed_in_email_block(email):
                # listed in the email blocks - it's a spam email we want to block
                # log the spam
                log_defaults = {
                    'event_id' : 130999,
                    'event_data': 'SPAM detected in email from  %s %s, %s.' \
                                    % (first_name, last_name, email),
                    'description': 'email spam detected',
                    'user': request.user,
                    'request': request,
                }
                EventLog.objects.log(**log_defaults)
                
                # redirect normally so they don't suspect
                return HttpResponseRedirect(reverse('form.confirmation'))
            
            address = form.cleaned_data.get('address', None)
            city = form.cleaned_data.get('city', None)
            state = form.cleaned_data.get('state', None)
            zipcode = form.cleaned_data.get('zipcode', None)
            country = form.cleaned_data.get('country', None)
            phone = form.cleaned_data.get('phone', None)
            
            url = form.cleaned_data.get('url', None)
            message = form.cleaned_data.get('message', None)

            contact_kwargs = {
                'first_name': first_name,
                'last_name': last_name,
                'message': message,
            } 
            contact = Contact(**contact_kwargs)
            contact.creator_id = 1 # TODO: decide if we should use tendenci base model
            contact.owner_id = 1 # TODO: decide if we should use tendenci base model
            contact.save()

            if address or city or state or zipcode or country:
                address_kwargs = {
                    'address': address,
                    'city': city,
                    'state': state,
                    'zipcode': zipcode,
                    'country': country,
                }
                obj_address = Address(**address_kwargs)
                obj_address.save() # saves object
                contact.addresses.add(obj_address) # saves relationship

            if phone:
                obj_phone = Phone(number=phone)
                obj_phone.save() # saves object
                contact.phones.add(obj_phone) # saves relationship

            if email:
                obj_email = Email(email=email)
                obj_email.save() # saves object
                contact.emails.add(obj_email) # saves relationship

            if url:
                obj_url = URL(url=url)
                obj_url.save() # saves object
                contact.urls.add(obj_url) # saves relationship

            site_name = get_setting('site', 'global', 'sitedisplayname')
            message_link = get_setting('site', 'global', 'siteurl')

            # send notification to administrators
            # get admin notice recipients
            recipients = get_notice_recipients('module', 'contacts', 'contactrecipients')
            if recipients:
                if notification:
                    extra_context = {
                    'reply_to': email,
                    'contact':contact,
                    'first_name':first_name,
                    'last_name':last_name,
                    'address':address,
                    'city':city,
                    'state':state,
                    'zipcode':zipcode,
                    'country':country,
                    'phone':phone,
                    'email':email,
                    'url':url,
                    'message':message,
                    'message_link':message_link,
                    'site_name':site_name,
                    }
                    notification.send_emails(recipients,'contact_submitted', extra_context)

            try: user = User.objects.filter(email=email)[0]
            except: user = None

            if user:
                event_user = user
                event_id = 125115
            else:
                event_user = AnonymousUser()
                event_id = 125114

            log_defaults = {
                'event_id' : event_id,
                'event_data': 'Contact Form (id:%d) submitted by %s' % (contact.pk, email),
                'description': '%s added' % contact._meta.object_name,
                'user': event_user,
                'request': request,
                'instance': contact,
            }
            EventLog.objects.log(**log_defaults)

            return HttpResponseRedirect(reverse('form.confirmation'))
        else:
            return render_to_response(template_name, {'form': form}, 
                context_instance=RequestContext(request))

    form = form_class()
    return render_to_response(template_name, {'form': form}, 
        context_instance=RequestContext(request))
Exemple #18
0
def group_add_edit(request, group_slug=None, 
                   form_class=GroupForm, 
                   template_name="user_groups/add_edit.html"):
    add, edit = False, False
    if group_slug:
        group = get_object_or_404(Group, slug=group_slug)
       
        if not has_perm(request.user,'user_groups.change_group',group):
            raise Http403
        title = "Edit Group"
        edit = True
    else:
        group = None
        if not has_perm(request.user,'user_groups.add_group'):raise Http403
        title = "Add Group"
        add = True

    if request.method == 'POST':
        if edit:
            form = form_class(request.POST, instance=group, user=request.user)
        else:
            form = form_class(request.POST, user=request.user)
        if form.is_valid():
            group = form.save(commit=False)
            if not group.id:
                group.creator = request.user
                group.creator_username = request.user.username
                
            # set up user permission
            group.allow_user_view, group.allow_user_edit = form.cleaned_data['user_perms']
                            
            group.owner =  request.user
            group.owner_username = request.user.username
            group = form.save()
            
            if add:
                # send notification to administrators
                recipients = get_notice_recipients('module', 'groups', 'grouprecipients')
                if recipients:
                    if notification:
                        extra_context = {
                            'object': group,
                            'request': request,
                        }
                        notification.send_emails(recipients,'group_added', extra_context)
                    
                log_defaults = {
                    'event_id' : 161000,
                    'event_data': '%s (%d) added by %s' % (group._meta.object_name, group.pk, request.user),
                    'description': '%s added' % group._meta.object_name,
                    'user': request.user,
                    'request': request,
                    'instance': group,
                }
                EventLog.objects.log(**log_defaults)                
            if edit:
                log_defaults = {
                    'event_id' : 162000,
                    'event_data': '%s (%d) edited by %s' % (group._meta.object_name, group.pk, request.user),
                    'description': '%s edited' % group._meta.object_name,
                    'user': request.user,
                    'request': request,
                    'instance': group,
                }
                EventLog.objects.log(**log_defaults)
                
            return HttpResponseRedirect(group.get_absolute_url())
    else:
        if edit:
            form = form_class(instance=group, user=request.user)
        else:
            form = form_class(user=request.user)
      
    return render_to_response(template_name, {'form':form, 'titie':title, 'group':group}, context_instance=RequestContext(request))
Exemple #19
0
def add(request, form_class=MakePaymentForm, template_name="make_payments/add.html"):
    if request.method == "POST":
        form = form_class(request.user, request.POST)
        
        if form.is_valid():
            mp = form.save(commit=False)
            # we might need to create a user record if not exist
            if request.user.is_authenticated():
                user = request.user
            else:
                try:
                    user = User.objects.get(email=mp.email)
                except:
                    user = request.user

            if not user.is_anonymous():
                mp.user = user
                mp.creator = user
                mp.creator_username = user.username
            mp.save(user)
            
            # create invoice
            invoice = make_payment_inv_add(user, mp)
            # log an event for invoice add
            log_defaults = {
                'event_id' : 311000,
                'event_data': '%s (%d) added by %s' % (invoice._meta.object_name, invoice.pk, request.user),
                'description': '%s added' % invoice._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': invoice,
            }
            EventLog.objects.log(**log_defaults)  
            
            # updated the invoice_id for mp, so save again
            mp.save(user)
            
            # log an event for make_payment
            log_defaults = {
                'event_id' : 671000,
                'event_data': '%s (%d) added by %s' % (mp._meta.object_name, mp.pk, request.user),
                'description': '%s added' % mp._meta.object_name,
                'user': request.user,
                'request': request,
                'instance': mp,
            }
            EventLog.objects.log(**log_defaults)
            
            # send notification to administrators
            # get admin notice recipients
            recipients = get_notice_recipients('module', 'payments', 'paymentrecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'mp': mp,
                        'invoice': invoice,
                        'request': request,
                    }
                    notification.send_emails(recipients,'make_payment_added', extra_context)
            
            # email to user 
            email_receipt = form.cleaned_data['email_receipt']
            if email_receipt:
                make_payment_email_user(request, mp, invoice)
            
            # redirect to online payment or confirmation page
            if mp.payment_method == 'cc' or mp.payment_method == 'credit card':
                return HttpResponseRedirect(reverse('payments.views.pay_online', args=[invoice.id, invoice.guid]))
            else:
                return HttpResponseRedirect(reverse('make_payment.add_confirm', args=[mp.id]))
    else:
        form = form_class(request.user)

        # check for initial payment_amount and clean up
        payment_amount = request.GET.get('payment_amount', 0)
        try:
            payment_amount = float(payment_amount)
        except:
            payment_amount = 0
        if payment_amount > 0:
            form.fields['payment_amount'].initial = payment_amount

        # check for initial comment and clean up
        comments = request.GET.get('comments','')
        if comments:
            comments = strip_tags(comments)
            comments = strip_entities(comments)
            form.fields['comments'].initial = comments

    currency_symbol = get_setting("site", "global", "currencysymbol")
    if not currency_symbol: currency_symbol = "$"
       
    return render_to_response(template_name, {'form':form, 'currency_symbol': currency_symbol}, 
        context_instance=RequestContext(request))