Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(ModelSearchForm, self).__init__(*args, **kwargs)

        # Check to see if users should be included in global search
        include_users = False

        if is_admin(kwargs['user']) or get_setting('module', 'users', 'allowanonymoususersearchuser') \
        or (kwargs['user'].is_authenticated() and get_setting('module', 'users', 'allowusersearch')):
            include_users = True

        if include_users:
            for app in registered_apps:
                if app['verbose_name'].lower() == 'user':
                    registered_apps_models.append(app['model'])
                    registered_apps_names.append(app['model']._meta.module_name)
        else:
            for app in registered_apps:
                if app['verbose_name'].lower() == 'user':
                    try:
                        models_index = registered_apps_models.index(app['model'])
                        registered_apps_models.pop(models_index)
                        names_index = registered_apps_names.index(app['model']._meta.module_name)
                        registered_apps_names.pop(names_index)
                    except Exception as e:
                        pass

        self.models = registered_apps_models
        self.fields['models'] = forms.MultipleChoiceField(choices=model_choices(), required=False, label=_('Search In'), widget=forms.CheckboxSelectMultiple)
Ejemplo n.º 2
0
    def get_description(self):
        object = self.object

        ### Assign variables -----------------------  
        site_name = get_setting('site','global','sitedisplayname')
        geo_location = get_setting('site','global','sitegeographiclocation')

        if object.description:
            content = object.description

        content = strip_tags(content) #strips HTML tags
        content = unescape_entities(content)
        content = content.replace("\n","").replace("\r","")
        content = truncate_words(content, 50) # ~ about 250 chars

        ### Build string -----------------------
        value = object.name

        value = '%s : %s' % (value, content)

        value = '%s Photo Sets for %s, %s' % (
            value, site_name, geo_location)

        value = value.strip()

        return value
Ejemplo n.º 3
0
    def get_keywords(self):
        object = self.object

        ### Assign variables -----------------------
        dynamic_keywords = generate_meta_keywords(object.body)
        primary_keywords = get_setting("site", "global", "siteprimarykeywords")
        secondary_keywords = get_setting("site", "global", "sitesecondarykeywords")
        geo_location = get_setting("site", "global", "sitegeographiclocation")
        site_name = get_setting("site", "global", "sitedisplayname")

        creator_name = "%s %s" % (object.creator.first_name, object.creator.last_name)

        ### Build string -----------------------
        value = ""

        if primary_keywords:
            value = "%s %s" % (value, primary_keywords)
            value = value.strip()

        if object.headline:
            list = ["Articles", geo_location, site_name, "white paper", creator_name]

            # remove blank items
            for item in list:
                if not item.strip():
                    list.remove(item)

            value = "%s %s, %s" % (value, ", ".join(list), dynamic_keywords)

        else:
            list = ["Articles", geo_location, site_name, "white paper", secondary_keywords]
            value = "%s %s" % (value, "".join(list))

        return value
Ejemplo n.º 4
0
    def get_keywords(self):
        object = self.object

        ### Assign variables -----------------------  
        dynamic_keywords = generate_meta_keywords(object.body)
        geo_location = get_setting('site','global','sitegeographiclocation')
        site_name = get_setting('site','global','sitedisplayname')


        ### Build string -----------------------
        value = ''

        list = [
            'Photos',
            geo_location,
            site_name,
        ]

        # remove blank items
        for item in list:
            if not item.strip():
                list.remove(item)
 
        value = '%s %s, %s' % (value, ', '.join(list), dynamic_keywords)


        return value
Ejemplo n.º 5
0
    def clean_password1(self):
        password1 = self.cleaned_data.get('password1')
        password_regex = get_setting('module', 'users', 'password_requirements_regex')
        password_requirements = get_setting('module', 'users', 'password_text')
        if password_regex:
            if not re.match(password_regex, password1):
                raise forms.ValidationError(mark_safe("The password does not meet the requirements </li><li>%s" % password_requirements))

        return password1
 def get_admin_emails():
     admin_emails = get_setting('module', 'memberships', 'membershiprecipients').strip()
     if admin_emails:
         admin_emails = admin_emails.split(',')
     if not admin_emails:
         admin_emails = (get_setting('site', 'global', 'admincontactemail').strip()).split(',')
         
     if admin_emails:
         admin_emails = ','.join(admin_emails)
     return admin_emails
Ejemplo n.º 7
0
def encode_site(xml):
    xml.write("<title>%s</title>"%get_setting('site', 'global', 'sitedisplayname'), depth=1)
    xml.write("<description></description>", depth=1)
    xml.write("<pubDate>%s</pubDate>"%datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), depth=1)
    xml.write("<language>%s</language>"%get_setting('site', 'global', 'localizationlanguage'), depth=1)
    xml.write("<wp:wxr_version>%s</wp:wxr_version>"%1.0, depth=1)
    # not sure if this is required
    #xml.write("<wp:base_site_url>http://wordpress.com/</wp:base_site_url>", depth=1)
    #xml.write("<wp:base_blog_url>http://sambixly.wordpress.com</wp:base_blog_url>", depth=1)
    encode_categories(xml)
    encode_tags(xml)
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(LoginForm, self).__init__(*args, **kwargs)
     # check if we need to hide the remember me checkbox
     # and set the default value for remember me
     hide_remember_me = get_setting('module', 'users', 'usershiderememberme')
     remember_me_default_checked = get_setting('module', 'users', 'usersremembermedefaultchecked')
     
     if remember_me_default_checked:
         self.fields['remember'].initial = True
     if hide_remember_me:
         self.fields['remember'].widget = forms.HiddenInput()
Ejemplo n.º 9
0
    def get_title(self):
        object = self.object

        ### Assign variables -----------------------  
        primary_keywords = get_setting('site','global','siteprimarykeywords')
        geo_location = get_setting('site','global','sitegeographiclocation')
        site_name = get_setting('site','global','sitedisplayname')
        category_set = object.category_set
        category = category_set.get('category', '')
        subcategory = category_set.get('sub_category', '')

        creator_name = '%s %s' % (
            object.creator.first_name, 
            object.creator.last_name
        )
        creator_name = creator_name.strip()

        ### Build string -----------------------
        value = '%s - %s' % (object.headline, object.activation_dt)
        value = value.strip()

        value = ''

        # start w/ headline
        if object.headline:
            value += object.headline

        # contact activation
        if object.headline and object.activation_dt:
            value += ' - %s' % object.activation_dt.strftime('%m-%d-%Y')
        elif object.activation_dt:
            value += object.activation_dt.strftime('%m-%d-%Y')

        # primary keywords OR category/subcategory
        if primary_keywords:
            value = '%s : %s' % (value, primary_keywords)
        else:
            if category:
                value = '%s %s' % (value, category)
            if category and subcategory:
                value = '%s : %s' % (value, subcategory)

        value = '%s directory' % value

        if creator_name:
            value = '%s contact: %s' % (value, creator_name)

        value = '%s directories for %s' % (value, site_name)

        if geo_location:
            value = '%s in %s' % (value, geo_location)

        return value
Ejemplo n.º 10
0
    def clean_new_password1(self):
        password1 = self.cleaned_data.get('new_password1')
        password_regex = get_setting('module', 'users', 'password_requirements_regex')
        password_requirements = get_setting('module', 'users', 'password_text')
        print password_regex
        print password_requirements
        if password_regex:
            # At least MIN_LENGTH long
            # "^(?=.{8,})(?=.*[0-9=]).*$"
            print re.match(password_regex, password1)
            if not re.match(password_regex, password1):
                raise forms.ValidationError(mark_safe("The new password does not meet the requirements </li><li>%s" % password_requirements))

        return password1
Ejemplo n.º 11
0
    def get_title(self):
        object = self.object

        ### Assign variables -----------------------
        primary_keywords = get_setting("site", "global", "siteprimarykeywords")
        geo_location = get_setting("site", "global", "sitegeographiclocation")
        site_name = get_setting("site", "global", "sitedisplayname")
        category_set = object.category_set
        category = category_set.get("category", "")
        subcategory = category_set.get("sub_category", "")

        creator_name = "%s %s" % (object.creator.first_name, object.creator.last_name)
        creator_name = creator_name.strip()

        ### Build string -----------------------
        value = "%s - %s" % (object.headline, object.release_dt)
        value = value.strip()

        value = ""

        # start w/ headline
        if object.headline:
            value += object.headline

        # contact release
        if object.headline and object.release_dt:
            value += " - %s" % object.release_dt.strftime("%m-%d-%Y")
        elif object.release_dt:
            value += object.release_dt.strftime("%m-%d-%Y")

        # primary keywords OR category/subcategory
        if primary_keywords:
            value = "%s : %s" % (value, primary_keywords)
        else:
            if category:
                value = "%s %s" % (value, category)
            if category and subcategory:
                value = "%s : %s" % (value, subcategory)

        value = "%s article" % value

        if creator_name:
            value = "%s contact: %s" % (value, creator_name)

        value = "%s articles for %s" % (value, site_name)

        if geo_location:
            value = "%s in %s" % (value, geo_location)

        return value
Ejemplo n.º 12
0
    def get_description(self):
        object = self.object

        ### Assign variables -----------------------  
        primary_keywords = get_setting('site','global','siteprimarykeywords')
        category_set = object.category_set
        category = category_set.get('category', '')
        subcategory = category_set.get('sub_category', '')
        site_name = get_setting('site','global','sitedisplayname')
        geo_location = get_setting('site','global','sitegeographiclocation')
        creator_name = '%s %s' % (
            object.creator.first_name, 
            object.creator.last_name
        )
        creator_name = creator_name.strip()

        if object.summary:
            content = object.summary
        else:
            content = object.body

        content = strip_tags(content) #strips HTML tags
        content = unescape_entities(content)
        content = content.replace("\n","").replace("\r","")
        content = truncate_words(content, 50) # ~ about 250 chars

        ### Build string -----------------------
        value = object.headline

        if creator_name:
            value = '%s %s' % (value, creator_name)

        value = '%s : %s' % (value, content)

        if primary_keywords:
            value = '%s %s' % (value, primary_keywords)
        else:
            if category:
                value = '%s %s' % (value, category)
            if category and subcategory:
                value = '%s : %s' % (value, subcategory)

            value = '%s directory' % value

        value = '%s Directories for %s %s' % (
            value, site_name, geo_location)

        value = value.strip()

        return value
Ejemplo n.º 13
0
    def get_keywords(self):
        object = self.object

        ### Assign variables -----------------------  
        dynamic_keywords = generate_meta_keywords(object.body)
        primary_keywords = get_setting('site','global','siteprimarykeywords')
        secondary_keywords = get_setting('site','global','sitesecondarykeywords')
        geo_location = get_setting('site','global','sitegeographiclocation')
        site_name = get_setting('site','global','sitedisplayname')

        creator_name = '%s %s' % (
            object.creator.first_name, 
            object.creator.last_name
        )

        ### Build string -----------------------
        value = ''

        if primary_keywords:
            value = '%s %s' % (value, primary_keywords)
            value = value.strip()

        if object.headline:
            list = [
                'Directories',
                geo_location,
                site_name,
                'white paper',
                creator_name,
            ]

            # remove blank items
            for item in list:
                if not item.strip():
                    list.remove(item)
 
            value = '%s %s, %s' % (value, ', '.join(list), dynamic_keywords)

        else:
            list = [
                'Directories',
                geo_location,
                site_name,
                'white paper',
                secondary_keywords,
            ]
            value = '%s %s' % (value, ''.join(list))

        return value
Ejemplo n.º 14
0
def search(request, template_name="locations/search.html"):
    query = request.GET.get('q', None)

    if get_setting('site', 'global', 'searchindex') and query:
        locations = Location.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'locations.view_location')
        locations = Location.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            locations = locations.select_related()

    locations = locations.order_by('-create_dt')

    log_defaults = {
        'event_id' : 834000,
        'event_data': '%s listed by %s' % ('Location', request.user),
        'description': '%s listed' % 'Location',
        'user': request.user,
        'request': request,
        'source': 'locations'
    }
    EventLog.objects.log(**log_defaults)
    
    return render_to_response(template_name, {'locations':locations}, 
        context_instance=RequestContext(request))
Ejemplo n.º 15
0
def index(request, cat_slug=None, template_name="videos/list.html"):
    """
    This page lists out all videos. The order can be customized.
    Filtering by category only works if a search index is available.
    """
    has_index = get_setting('site', 'global', 'searchindex')

    if has_index and cat_slug:
        videos = Video.objects.search('cat:%s' % cat_slug, user=request.user)
        videos = videos.order_by('-ordering','-create_dt')
        category = get_object_or_404(Category, slug=cat_slug)
    else:
        filters = get_query_filters(request.user, 'videos.view_video')
        videos = Video.objects.filter(filters).distinct()
        if request.user.is_authenticated():
            videos = videos.select_related()
        videos = videos.order_by('-ordering', '-create_dt')

    categories = Category.objects.all()

    EventLog.objects.log(**{
        'event_id' : 1200400,
        'event_data': '%s viewed by %s' % ('Video list', request.user),
        'description': '%s viewed' % 'Video',
        'user': request.user,
        'request': request,
        'source': 'video',
    })

    return render_to_response(template_name, locals(), 
        context_instance=RequestContext(request))
Ejemplo n.º 16
0
def photoset_details(request, id, template_name="photos/photo-set/details.html"):
    """ View photos in photo set """
    
    photo_set = get_object_or_404(PhotoSet, id=id)
    if not has_view_perm(request.user, 'photos.view_photoset', photo_set):
        raise Http403
    
    order = get_setting('module', 'photos', 'photoordering')
    if order == 'descending':
        photos = photo_set.get_images(user=request.user).order_by('-pk')
    else:
        photos = photo_set.get_images(user=request.user).order_by('pk')
    
    EventLog.objects.log(**{
        'event_id' : 991500,
        'event_data': '%s (%d) viewed by %s' % (photo_set._meta.object_name, photo_set.pk, request.user),
        'description': '%s viewed' % photo_set._meta.object_name,
        'user': request.user,
        'request': request,
        'instance': photo_set,
    })

    return render_to_response(template_name, {
        "photos": photos,
        "photo_set": photo_set,
    }, context_instance=RequestContext(request))
Ejemplo n.º 17
0
def user_sqs(sqs, **kwargs):
    """
    people between admin and anon permission
    (status+status_detail+(anon OR user)) OR (who_can_view__exact)
    """
    user = kwargs.get('user')
    member_perms = get_setting('module', 'memberships', 'memberprotection')

    anon_q = Q(allow_anonymous_view=True)
    user_q = Q(allow_user_view=True)
    status_q = Q(status=1, status_detail='active')
    perm_q = Q(users_can_view__in=user.username)

    q = reduce(operator.or_, [anon_q, user_q])
    q = reduce(operator.and_, [status_q, q])
    q = reduce(operator.or_, [q, perm_q])

    filtered_sqs = sqs.filter(q)
    if not is_member(user):
        # all-members means members can view all other members
        if member_perms == "all-members":
            filtered_sqs = filtered_sqs.none()
        # member type means members can only view members of their same type
        if member_perms == "member-type":
            filtered_sqs = filtered_sqs.none()

    return filtered_sqs
Ejemplo n.º 18
0
    def __init__(self, *args, **kwargs):
        from base.http import Http403
        from site_settings.utils import get_setting
        from perms.utils import is_member, is_admin
        from memberships.models import Membership

        self.user = kwargs.pop('user', None)
        super(ExportForm, self).__init__(*args, **kwargs)

        who_can_export = get_setting('module','memberships','memberexport')

        if who_can_export == 'admin-only':
            if not is_admin(self.user):
                raise Http403
        elif who_can_export == 'membership-of-same-type':
            if not is_member(self.user):
                raise Http403
            membership_types = self.user.memberships.values_list('membership_type').distinct()
            self.fields['app'].queryset = App.objects.filter(membership_types__in=membership_types)
        elif who_can_export == 'members':
            if not is_member(self.user):
                raise Http403
        elif who_can_export == 'users':
            if not self.user.is_authenticated():
                raise Http403
Ejemplo n.º 19
0
def get_corporate_membership_type_choices(user, corpapp, renew=False):
    cmt_list = []
    corporate_membership_types = corpapp.corp_memb_type.all()
    
    if not is_admin(user):
        corporate_membership_types = corporate_membership_types.filter(admin_only=False)
    currency_symbol = get_setting("site", "global", "currencysymbol")
    
    for cmt in corporate_membership_types:
        if not renew:
            price_display = '%s - %s%0.2f' % (cmt.name, currency_symbol, cmt.price)
        else:
            indiv_renewal_price = cmt.membership_type.renewal_price
            if not indiv_renewal_price:
                indiv_renewal_price = 'Free<span class="type-ind-price"></span>'
            else:
                indiv_renewal_price = '%s<span class="type-ind-price">%0.2f</span>' % (currency_symbol, indiv_renewal_price)
            if not cmt.renewal_price:
                cmt.renewal_price = 0
            
            price_display = """%s - <b>%s<span class="type-corp-price">%0.2f</span></b> 
                            (individual members renewal: 
                            <b>%s</b>)""" % (cmt.name, 
                                            currency_symbol, 
                                            cmt.renewal_price,
                                            indiv_renewal_price)
        price_display = mark_safe(price_display)
        cmt_list.append((cmt.id, price_display))
            
    return cmt_list 
Ejemplo n.º 20
0
def payment_processing_object_updates(request, payment, **kwargs):
    # they are paid, so update the object
    # trap the error and send us the error email - just in case
    try:
        if str(payment.response_code) == '1' and str(payment.response_reason_code) == '1':
            obj = payment.invoice.get_object()
            if obj and hasattr(obj, 'auto_update_paid_object'):
                obj.auto_update_paid_object(request, payment)
    except:
        import traceback
        from django.core.mail import send_mail
        from django.conf import settings
        from site_settings.utils import get_setting
        
        err_msg = traceback.format_exc()
        subject = 'Payment error from %s (ID:%d)' % (get_setting('site', 'global', 'siteurl'), 
                                                     payment.id)
        body = err_msg
        sender = settings.DEFAULT_FROM_EMAIL
        admins = settings.ADMINS
        recipients = [item[1] for item in admins]
        if not recipients:
            recipients = ['*****@*****.**']
        send_mail(subject, body, sender, recipients, fail_silently=True)
        
        # still want the end user know an error occurred
        raise Exception, err_msg
Ejemplo n.º 21
0
def template_update(request, template_id):
    """
    This method makes use of the same files to update the CM Template.
    Useful for updating data/content only and retaining design.
    """

    template = get_object_or_404(Template, template_id=template_id)

    if not has_perm(request.user, 'campaign_monitor.change_template',
                    template):
        raise Http403

    #set up urls
    site_url = get_setting('site', 'global', 'siteurl')
    html_url = str("%s%s" % (site_url, template.get_html_url()))
    if template.zip_file:
        zip_url = str("%s%s" % (site_url, template.get_zip_url()))
    else:
        zip_url = ""

    #sync with campaign monitor
    try:
        t = CST(template_id=template.template_id)
        t.update(str(template.name), html_url, zip_url)
    except BadRequest, e:
        messages.add_message(
            request, messages.ERROR,
            'Bad Request %s: %s' % (e.data.Code, e.data.Message))
        return redirect(template)
Ejemplo n.º 22
0
def search(request, template_name="staff/search.html"):
    """Staff plugin search list view"""
    query = request.GET.get('q', None)

    if get_setting('site', 'global', 'searchindex') and query:
        staff = Staff.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'staff.view_staff')
        staff = Staff.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            staff = staff.select_related()

    staff = staff.order_by('-status','status_detail','start_date')
    
    log_defaults = {
        'event_id' : 1080400,
        'event_data': '%s searched by %s' % ('Staff', request.user),
        'description': '%s searched' % 'Staff',
        'user': request.user,
        'request': request,
        'source': 'staff'
    }
    EventLog.objects.log(**log_defaults)

    return render_to_response(template_name, {'staff_members':staff},
        context_instance=RequestContext(request))
Ejemplo n.º 23
0
def search(request, template_name="user_groups/search.html"):
    """
    This page lists out all user groups.  If a search index
    is available, this page also allows you to search through
    user groups.
    """
    has_index = get_setting('site', 'global', 'searchindex')
    query = request.GET.get('q', None)

    if has_index and query:
        groups = Group.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'groups.view_group', perms_field=False)
        groups = Group.objects.filter(filters).distinct()
        if request.user.is_authenticated():
            groups = groups.select_related()
        groups = groups.order_by('slug')

    log_defaults = {
        'event_id' : 164000,
        'event_data': '%s searched by %s' % ('Group', request.user),
        'description': '%s searched' % 'Group',
        'user': request.user,
        'request': request,
        'source': 'user_groups'
    }
    EventLog.objects.log(**log_defaults)

    return render_to_response(template_name, {'groups':groups}, 
        context_instance=RequestContext(request))
Ejemplo n.º 24
0
def search(request, template_name="resumes/search.html"):
    """
    This page lists out all resumes from newest to oldest.
    If a search index is available, this page will also
    have the option to search through resumes.
    """
    has_index = get_setting('site', 'global', 'searchindex')
    query = request.GET.get('q', None)

    if has_index and query:
        resumes = Resume.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'resumes.view_resume')
        resumes = Resume.objects.filter(filters).distinct()
        if request.user.is_authenticated():
            resumes = resumes.select_related()
    resumes = resumes.order_by('-create_dt')

    EventLog.objects.log(**{
        'event_id' : 354000,
        'event_data': '%s searched by %s' % ('Resume', request.user),
        'description': '%s searched' % 'Resume',
        'user': request.user,
        'request': request,
        'source': 'resumes'
    })
    
    return render_to_response(template_name, {'resumes':resumes}, 
        context_instance=RequestContext(request))
Ejemplo n.º 25
0
def photoset_view_latest(request, template_name="photos/photo-set/latest.html"):
    """ View latest photo set """

    query = request.GET.get('q', None)
    if get_setting('site', 'global', 'searchindex') and query:
        photo_sets = PhotoSet.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'photos.view_photoset')
        photo_sets = PhotoSet.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            photo_sets = photo_sets.select_related()
    photo_sets = photo_sets.order_by('-create_dt')

    log_defaults = {
        'event_id' : 991400,
        'event_data': '%s searched by %s' % ('PhotoSet', request.user),
        'description': '%s searched' % 'PhotoSet',
        'user': request.user,
        'request': request,
        'source': 'photos'
    }
    EventLog.objects.log(**log_defaults)

    return render_to_response(template_name, {"photo_sets": photo_sets}, 
        context_instance=RequestContext(request))
Ejemplo n.º 26
0
    def get_description(self):
        object = self.object

        ### Assign variables -----------------------  
        site_name = get_setting('site','global','sitedisplayname')

        ### Build string -----------------------
        value = ''

        # start w/ title
        if object.title:
            value += object.title

        # location
        if object.location:
            value = '%s - %s' % (value, object.location)

        # description
        # TODO truncate at 450 characters
        if object.description:
            value = '%s - %s' % (value, object.description)

        value = '%s - employment opportunity %s' % (value, site_name)

        return value
Ejemplo n.º 27
0
def search(request, template_name="services/search.html"):
    """Search view for Services plugin"""
    query = request.GET.get('q', None)
    if get_setting('site', 'global', 'searchindex') and query:
        services = Service.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'services.view_service')
        services = Service.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            services = services.select_related()

    services = services.order_by('-create_dt')

    log_defaults = {
        'event_id' : 354000,
        'event_data': '%s searched by %s' % ('Service', request.user),
        'description': '%s searched' % 'service',
        'user': request.user,
        'request': request,
        'source': 'services'
    }
    EventLog.objects.log(**log_defaults)
    
    return render_to_response(template_name, {'services':services}, 
        context_instance=RequestContext(request))
Ejemplo n.º 28
0
def search(request, template_name="case_studies/search.html"):
    query = request.GET.get('q', None)

    if get_setting('site', 'global', 'searchindex') and query:
        case_studies = CaseStudy.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'case_studies.view_casestudy')
        case_studies = CaseStudy.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            case_studies = case_studies.select_related()
    case_studies = case_studies.order_by('-create_dt')
    services = Service.objects.all()
    technologies = Technology.objects.all()
    
    log_defaults = {
        'event_id' : 1000400,
        'event_data': '%s searched by %s' % ('Case Study', request.user),
        'description': '%s searched' % 'Case Study',
        'user': request.user,
        'request': request,
        'source': 'case_studies'
    }
    EventLog.objects.log(**log_defaults)

    return render_to_response(template_name, {'case_studies': case_studies, 'services': services, 'technologies': technologies},
        context_instance=RequestContext(request))
Ejemplo n.º 29
0
def search(request, template_name="jobs/search.html"):
    query = request.GET.get('q', None)

    if get_setting('site', 'global', 'searchindex') and query:
        jobs = Job.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'jobs.view_job')
        jobs = Job.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            jobs = jobs.select_related()

    jobs = jobs.order_by('status_detail','list_type','-post_dt')

    log_defaults = {
        'event_id': 254000,
        'event_data': '%s searched by %s' % ('Job', request.user),
        'description': '%s searched' % 'Job',
        'user': request.user,
        'request': request,
        'source': 'jobs'
    }
    EventLog.objects.log(**log_defaults)

    return render_to_response(template_name, {'jobs': jobs},
        context_instance=RequestContext(request))
Ejemplo n.º 30
0
 def email_script_errors(err_msg):
     """Send error message to us in case of an error.
     """
     email = Email()
     email.sender = get_setting('site', 'global', 'siteemailnoreplyaddress')
     email.sender_display = get_setting('site', 'global', 'sitedisplayname')
     site_url = get_setting('site', 'global', 'siteurl')
 
     now = datetime.now()
     nowstr = time.strftime("%d-%b-%y %I:%M %p", now.timetuple())
     email.recipient = get_script_support_emails()
     if email.recipient:
         email.body = '%s \n\nTime Submitted: %s\n' % (err_msg, nowstr)
         email.content_type = "text"
         email.subject = 'Error Setting Up Campaign Monitor Account on New Site %s' % site_url
         
         email.send()
Ejemplo n.º 31
0
    def handle(self, *args, **kwargs):
        from site_settings.utils import get_setting
        from memberships.models import Membership
        from user_groups.models import GroupMembership
        protection = get_setting('module', 'memberships', 'memberprotection')

        if protection == 'public':
            Membership.objects.update(
                allow_anonymous_view=True,
                allow_user_view=False,
                allow_member_view=False
            )
        elif protection == 'all-members':
            Membership.objects.update(
                allow_anonymous_view=False,
                allow_user_view=False,
                allow_member_view=True
            )
        elif protection == 'member-type':
            Membership.objects.update(
                allow_anonymous_view=False,
                allow_user_view=False,
                allow_member_view=False
            )
            for membership in Membership.objects.all():

                # add or remove from group -----
                if membership.is_active():  # should be in group; make sure they're in
                    membership.membership_type.group.add_user(membership.user)
                else:  # should not be in group; make sure they're out
                    GroupMembership.objects.filter(
                        member=membership.user,
                        group=membership.membership_type.group
                    ).delete()
                # -----

                print membership

        else:  # private
            Membership.objects.update(
                allow_anonymous_view=False,
                allow_user_view=False,
                allow_member_view=False
            )
Ejemplo n.º 32
0
    def handle(self, *args, **options):
        import os
        from Tendenci50.settings import MEDIA_ROOT
        from site_settings.utils import get_setting
        from events.models import Event
        from events.utils import get_vevents
        from django.contrib.auth.models import User

        p = re.compile(r'http(s)?://(www.)?([^/]+)')
        d = {}
        d['site_url'] = get_setting('site', 'global', 'siteurl')
        match = p.search(d['site_url'])
        if match:
            d['domain_name'] = match.group(3)
        else:
            d['domain_name'] = ""

        absolute_directory = os.path.join(MEDIA_ROOT, 'files/ics')
        if not os.path.exists(absolute_directory):
            os.makedirs(absolute_directory)

        # Create ics file for every user
        users = User.objects.all()
        user = User.objects.get(pk='1')
        #for user in users:
        ics_str = "BEGIN:VCALENDAR\n"
        ics_str += "PRODID:-//Schipul Technologies//Schipul Codebase 5.0 MIMEDIR//EN\n"
        ics_str += "VERSION:2.0\n"
        ics_str += "METHOD:PUBLISH\n"

        # function get_vevents in events.utils
        ics_str += get_vevents(user, d)

        ics_str += "END:VCALENDAR\n"
        ics_str = ics_str.encode('UTF-8')
        file_name = 'ics-%s.ics' % (user.pk)
        file_path = os.path.join(absolute_directory, file_name)
        destination = open(file_path, 'w+')
        destination.write(ics_str)
        destination.close()
        print 'Created ics for user %s pk=%s' % (user, user.pk)