Exemplo n.º 1
0
def create_default_entity(sender, app, **kwargs):
    """
    Load default entities if none exist
    or create an entity with id=1 if not exist.
    """
    def get_site_display_name():
        setting_table_exists = Setting._meta.db_table in \
                    connection.introspection.table_names()
        if setting_table_exists:
            return get_setting("site", "global", "sitedisplayname")
        return ''

    if app == "entities":
        site_name = get_site_display_name().strip()
        if not Entity.objects.all():
            call_command("loaddata", "default_entities.json")
            if site_name:
                # update the entity_name of the first default entity
                entity = Entity.objects.get(pk=1)
                entity.entity_name = site_name
                entity.save()
        else:
            if not Entity.objects.filter(pk=1):
                if not site_name:
                    site_name = "Default"

                entity = Entity()
                entity.allow_anonymous_view = False
                entity.entity_name = site_name
                entity.id = 1

                entity.save()
Exemplo n.º 2
0
def search(request, template_name="entities/search.html"):
    filters = Entity.get_search_filter(request.user)
    entities = Entity.objects.all()
    if filters:
        entities = entities.filter(filters).distinct()

    EventLog.objects.log()

    return render_to_resp(request=request,
                          template_name=template_name,
                          context={'entities': entities})
Exemplo n.º 3
0
def create_default_entity(sender, app, **kwargs):
    """
    Load default entities if none exist
    or create an entity with id=1 if not exist.
    """
    def get_site_display_name():
        setting_table_exists = Setting._meta.db_table in \
                    connection.introspection.table_names()
        if setting_table_exists:
            return get_setting("site", "global", "sitedisplayname")
        return ''

    if app == "entities":
        site_name = get_site_display_name().strip()
        if not Entity.objects.all():
            call_command("loaddata", "default_entities.json")
            if site_name:
                # update the entity_name of the first default entity
                entity = Entity.objects.get(pk=1)
                entity.entity_name = site_name
                entity.save()
        else:
            if not Entity.objects.filter(pk=1):
                if not site_name:
                    site_name = "Default"

                entity = Entity()
                entity.allow_anonymous_view = False
                entity.entity_name = site_name
                entity.id = 1

                entity.save()
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)
        else:
            self.user = None
        super(DonationForm, self).__init__(*args, **kwargs)
        # populate the user fields
        if self.user and self.user.id:
            self.fields['first_name'].initial = self.user.first_name
            self.fields['last_name'].initial = self.user.last_name
            self.fields['email'].initial = self.user.email
            try:
                profile = self.user.profile
                if profile:
                    self.fields['company'].initial = profile.company
                    self.fields['address'].initial = profile.address
                    self.fields['address2'].initial = profile.address2
                    self.fields['city'].initial = profile.city
                    self.fields['state'].initial = profile.state
                    self.fields['zip_code'].initial = profile.zipcode
                    self.fields['country'].initial = profile.country
                    self.fields['phone'].initial = profile.phone
            except:
                pass

        self.fields['payment_method'].widget = forms.RadioSelect(
            choices=get_payment_method_choices(self.user))
        # donate_to_entity or allocation
        filters = Entity.get_search_filter(self.user)
        entity_qs = Entity.objects.filter(show_for_donation=True)
        if filters:
            entity_qs = entity_qs.filter(filters).distinct()
        if not entity_qs.exists():
            del self.fields['donate_to_entity']
            allocation_str = get_setting('module', 'donations',
                                         'donationsallocations')
            if allocation_str:
                self.fields['allocation'].choices = get_allocation_choices(
                    self.user, allocation_str)
            else:
                del self.fields['allocation']
        else:
            del self.fields['allocation']
            self.fields['donate_to_entity'].queryset = entity_qs
            self.fields['donate_to_entity'].empty_label = _("Select One")
            self.fields['donate_to_entity'].label = _('Donate to')

        preset_amount_str = (get_setting('module', 'donations',
                                         'donationspresetamounts')).strip('')
        if preset_amount_str:
            self.fields['donation_amount'] = forms.ChoiceField(
                choices=get_preset_amount_choices(preset_amount_str))
Exemplo n.º 5
0
def create_default_entity(sender, app, **kwargs):
    """
    Auto-create an entity with id=1 if none exist.
    """
    if app == "entities":
        if not Entity.objects.filter(pk=1):
            site_name = "Default"
            table_exists = Setting._meta.db_table in \
                connection.introspection.table_names()
            if table_exists and get_setting("site", "global", "sitedisplayname"):
                site_name = get_setting("site", "global", "sitedisplayname")

            entity = Entity()
            entity.allow_anonymous_view = False
            entity.entity_name = site_name
            entity.id = 1

            entity.save()
Exemplo n.º 6
0
    def handle(self, *args, **options):
        from tendenci.apps.entities.models import Entity
        from tendenci.apps.user_groups.models import Group
        from tendenci.apps.site_settings.utils import get_setting
        from tendenci.apps.perms.models import TendenciBaseModel

        verbosity = int(options['verbosity'])

        [entity] = Entity.objects.filter(pk=1)[:1] or [None]
        [user] = User.objects.filter(pk=1)[:1] or [None]

        site_display_name = get_setting('site', 'global', 'sitedisplayname')
        if not site_display_name:
            site_display_name = 'Default'

        site_contact_name = get_setting('site', 'global', 'sitecontactname')
        site_contact_email = get_setting('site', 'global', 'sitecontactemail')
        site_phone_number = get_setting('site', 'global', 'sitephonenumber')
        site_url = get_setting('site', 'global', 'siteurl')
        # if there is no entity, create one.
        if not entity:
            params = {
                'id': 1,
                'entity_name': site_display_name,
                'entity_type': '',
                'contact_name': site_contact_name,
                'phone': site_phone_number,
                'email': site_contact_email,
                'fax': '',
                'website': site_url,
                'summary': '',
                'notes': '',
                'admin_notes': 'system auto created',
                'allow_anonymous_view': True,
                'status': True,
                'status_detail': 'active'
            }
            if user:
                params.update({
                    'creator': user,
                    'creator_username': user.username,
                    'owner': user,
                    'owner_username': user.username
                })
            else:
                params.update({'creator_username': '', 'owner_username': ''})
            entity = Entity(**params)

            entity.save()
            print('entity created: ', entity.entity_name)

        # loop through all the tables and populate
        # the entity field only if it's null.
        models = apps.get_models()
        # exclude legacy tables
        tables_excluded = [
            'corporate_memberships_corporatemembership',
            'corporate_memberships_corporatemembershiparchive'
        ]
        table_updated = []
        for model in models:
            if TendenciBaseModel in model.__bases__:
                if hasattr(model, 'entity'):
                    table_name = model._meta.db_table
                    if table_name in tables_excluded:
                        continue
                    for row in model.objects.all():
                        if not row.entity:
                            row.entity = entity
                            row.save(update_fields=['entity'])
                    table_updated.append(table_name)

        if verbosity >= 2:
            print()
            print('List of tables updated: ')
            print('\n'.join(table_updated))
            print()

        # GROUP - check if we have a group associated with
        group_exists = Group.objects.filter(entity=entity).exists()
        if not group_exists:
            params = {
                'name': site_display_name,
                'entity': entity,
                'type': 'distribution',
                'email_recipient': site_contact_email,
                'allow_anonymous_view': True,
                'status': True,
                'status_detail': 'active'
            }
            if user:
                params.update({
                    'creator': user,
                    'creator_username': user.username,
                    'owner': user,
                    'owner_username': user.username
                })
            else:
                params.update({'creator_username': '', 'owner_username': ''})
            group = Group(**params)

            try:
                group.save()
                print('Group created: ', group.name)
            except Exception as e:
                print(e)

        print('All done.')
    def handle(self, *args, **options):
        from tendenci.apps.entities.models import Entity
        from tendenci.apps.user_groups.models import Group
        from tendenci.core.site_settings.utils import get_setting
        from tendenci.core.perms.models import TendenciBaseModel

        verbosity = int(options['verbosity'])

        [entity] = Entity.objects.filter(pk=1)[:1] or [None]
        user = User.objects.get(pk=1)

        site_display_name = get_setting('site',
                                        'global',
                                        'sitedisplayname')
        if not site_display_name:
            site_display_name = 'Default'

        site_contact_name = get_setting('site',
                                        'global',
                                        'sitecontactname')
        site_contact_email = get_setting('site',
                                         'global',
                                         'sitecontactemail')
        site_phone_number = get_setting('site',
                                        'global',
                                        'sitephonenumber')
        site_url = get_setting('site',
                               'global',
                               'siteurl')
        # if there is no entity, create one.
        if not entity:
            entity = Entity(entity_name=site_display_name,
                            entity_type='',
                            contact_name=site_contact_name,
                            phone=site_phone_number,
                            email=site_contact_email,
                            fax='',
                            website=site_url,
                            summary='',
                            notes='',
                            admin_notes='system auto created',
                            allow_anonymous_view=True,
                            creator=user,
                            creator_username=user.username,
                            owner=user,
                            owner_username=user.username,
                            status=True,
                            status_detail='active',
                            id=1)

            entity.save()
            print 'entity created: ', entity.entity_name

        # loop through all the tables and populate
        # the entity field only if it's null.
        models = get_models()
        table_updated = []
        for model in models:
            if TendenciBaseModel in model.__bases__:
                if hasattr(model, 'entity'):
                    table_name = model._meta.db_table
                    for row in model.objects.all():
                        if not row.entity:
                            row.entity = entity
                            row.save()
                    table_updated.append(table_name)

        if verbosity >= 2:
            print
            print 'List of tables updated: '
            print '\n'.join(table_updated)
            print

        # GROUP - check if we have a group associated with
        group_exists = Group.objects.filter(
            name=site_display_name).exists()
        if not group_exists:
            group = Group(name=site_display_name,
                          entity=entity,
                          type='distribution',
                          email_recipient=site_contact_email,
                          allow_anonymous_view=True,
                          creator=user,
                          creator_username=user.username,
                          owner=user,
                          owner_username=user.username,
                          status=True,
                          status_detail='active')

            group.save()
            print 'Group created: ', group.name

        print 'All done.'
Exemplo n.º 8
0
    def handle(self, *args, **options):
        from tendenci.apps.entities.models import Entity
        from tendenci.apps.user_groups.models import Group
        from tendenci.apps.site_settings.utils import get_setting
        from tendenci.apps.perms.models import TendenciBaseModel

        verbosity = int(options['verbosity'])

        [entity] = Entity.objects.filter(pk=1)[:1] or [None]
        [user] = User.objects.filter(pk=1)[:1] or [None]

        site_display_name = get_setting('site',
                                        'global',
                                        'sitedisplayname')
        if not site_display_name:
            site_display_name = 'Default'

        site_contact_name = get_setting('site',
                                        'global',
                                        'sitecontactname')
        site_contact_email = get_setting('site',
                                         'global',
                                         'sitecontactemail')
        site_phone_number = get_setting('site',
                                        'global',
                                        'sitephonenumber')
        site_url = get_setting('site',
                               'global',
                               'siteurl')
        # if there is no entity, create one.
        if not entity:
            params = {'id': 1,
                      'entity_name': site_display_name,
                      'entity_type': '',
                      'contact_name': site_contact_name,
                      'phone': site_phone_number,
                      'email': site_contact_email,
                      'fax': '',
                      'website': site_url,
                      'summary': '',
                      'notes': '',
                      'admin_notes': 'system auto created',
                      'allow_anonymous_view': True,
                      'status': True,
                      'status_detail': 'active'
                      }
            if user:
                params.update({'creator': user,
                               'creator_username': user.username,
                               'owner': user,
                               'owner_username': user.username
                               })
            else:
                params.update({'creator_username': '',
                               'owner_username': ''
                               })
            entity = Entity(**params)

            entity.save()
            print('entity created: ', entity.entity_name)

        # loop through all the tables and populate
        # the entity field only if it's null.
        models = apps.get_models()
        # exclude legacy tables
        tables_excluded = ['corporate_memberships_corporatemembership',
                           'corporate_memberships_corporatemembershiparchive']
        table_updated = []
        for model in models:
            if TendenciBaseModel in model.__bases__:
                if hasattr(model, 'entity'):
                    table_name = model._meta.db_table
                    if table_name in tables_excluded:
                        continue
                    for row in model.objects.all():
                        if not row.entity:
                            row.entity = entity
                            row.save(update_fields=['entity'])
                    table_updated.append(table_name)

        if verbosity >= 2:
            print()
            print('List of tables updated: ')
            print('\n'.join(table_updated))
            print()

        # GROUP - check if we have a group associated with
        group_exists = Group.objects.filter(entity=entity).exists()
        if not group_exists:
            params = {'name': site_display_name,
                      'entity': entity,
                      'type': 'distribution',
                      'email_recipient': site_contact_email,
                      'allow_anonymous_view': True,
                      'status': True,
                      'status_detail': 'active'
                      }
            if user:
                params.update({'creator': user,
                               'creator_username': user.username,
                               'owner': user,
                               'owner_username': user.username
                               })
            else:
                params.update({'creator_username': '',
                               'owner_username': ''
                               })
            group = Group(**params)

            try:
                group.save()
                print('Group created: ', group.name)
            except Exception as e:
                print(e)

        print('All done.')