def test_model_choice_preference(self):
        global_preferences = global_preferences_registry.manager()
        global_preferences['blog__featured_entry'] = self.blog_entry

        in_db = GlobalPreferenceModel.objects.get(section='blog', name='featured_entry')
        self.assertEqual(in_db.value, self.blog_entry)
        self.assertEqual(in_db.raw_value, str(self.blog_entry.pk))
Пример #2
0
def home_page(request):
    # instanciate a manager for global preferences
    global_preferences = global_preferences_registry.manager()
    MAX_VEHICLES_TO_SHOW = global_preferences['homepage__number_of_vehicles']
    MAX_CATEGORIES_TO_SHOW = 4

    # get list of slider objects
    sliders = SliderImage.objects.all()

    # get categories to show on homepage
    top_categories = Category.objects.get_home_page_categories()
    if top_categories:
        top_categories = top_categories[:MAX_CATEGORIES_TO_SHOW]

    # get recently added vehicles
    top_vehicles = Vehicle.objects.all().order_by(
        '-timestamp').prefetch_related('images')
    if top_vehicles:
        top_vehicles = top_vehicles[:MAX_VEHICLES_TO_SHOW]

    return render_to_response("home_page.html",
                              locals(),
                              context_instance=RequestContext(
                                  request,
                                  processors=[global_context_processor]))
    def get(self, request, subscription_id):
        preferences = global_preferences_registry.manager()
        subscription = get_object_or_404(Subscription, id=int(subscription_id))
        volunteer = subscription.volunteer
        secret = preferences['payment__bcash_secret']

        form = BcashForm(secret=secret, initial={
            'campanha':            preferences['payment__campaign'],
            'cod_loja':            preferences['payment__bcash_cod_loja'],
            'email_loja':          preferences['payment__receiver_email'],
            'meio_pagamento':      10,
            'parcela_maxima':      1,
            'produto_codigo_1':    subscription_id,
            'produto_descricao_1': preferences['payment__item_name'].format(volunteer.name),
            'produto_qtde_1':      1,
            'produto_valor_1':     preferences['subscription__ticket_value'],
            'redirect':            'true',
            'redirect_time':       '10',
            'url_retorno':         urljoin(preferences['general__site_url'], reverse('bcash:return_url')),
        })

        data = {
            'fields': form.to_json()
        }
        data['endpoint'] = form.get_endpoint()
        data['image_button'] = form.get_image()

        response = Response(data)
        return response
 def test_can_bypass_cache_in_get(self):
     manager = global_preferences_registry.manager()
     manager['no_section']
     with self.assertNumQueries(3):
         manager['no_section']
         manager['no_section']
         manager['no_section']
    def test_can_cache_all_preferences(self):

        manager = global_preferences_registry.manager()
        manager.all()
        with self.assertNumQueries(0):
            manager.all()
            manager.all()
            manager.all()
    def test_can_cache_single_preference(self):

        manager = global_preferences_registry.manager()
        v = manager["no_section"]
        with self.assertNumQueries(0):
            v = manager["no_section"]
            v = manager["no_section"]
            v = manager["no_section"]
    def test_can_bypass_cache_in_get_all(self):
        from django.db import connection
        manager = global_preferences_registry.manager()

        queries_before = len(connection.queries)
        manager.all()
        manager_queries = len(connection.queries) - queries_before

        manager.all()
        self.assertGreater(len(connection.queries), manager_queries)
    def test_deleting_model_also_delete_preference(self):
        global_preferences = global_preferences_registry.manager()
        global_preferences['blog__featured_entry'] = self.blog_entry

        self.assertGreater(len(signals.pre_delete.receivers), 0)

        self.blog_entry.delete()

        with self.assertRaises(GlobalPreferenceModel.DoesNotExist):
            GlobalPreferenceModel.objects.get(section='blog', name='featured_entry')
 def test_preference_model_manager_to_dict(self):
     manager = global_preferences_registry.manager()
     call_command("checkpreferences", verbosity=1, interactive=False)
     expected = {
         "test__TestGlobal1": "default value",
         "test__TestGlobal2": False,
         "test__TestGlobal3": False,
         "no_section": False,
         "user__max_users": 100,
         "user__items_per_page": 25,
         "user__registration_allowed": False,
     }
     self.assertDictEqual(manager.all(), expected)
Пример #10
0
 def test_preference_model_manager_to_dict(self):
     manager = global_preferences_registry.manager()
     call_command('checkpreferences', verbosity=1, interactive=False)
     expected = {
         u'test__TestGlobal1': u'default value',
         u'test__TestGlobal2': False,
         u'test__TestGlobal3': False,
         u'no_section': False,
         u'user__max_users': 100,
         u'user__items_per_page': 25,
         u'blog__featured_entry': None,
         u'user__registration_allowed': False}
     self.assertDictEqual(manager.all(), expected)
def global_context_processor(request):
    # instanciate a manager for global preferences
    global_preferences = global_preferences_registry.manager()
    default_email = global_preferences.get('general__default_email', None)
    live_chat = global_preferences.get('general__live_chat', False)
    # get all the social service providers
    social_providers = list(Social.objects.all())
    # get all parent categories with sub categories
    all_categories = Category.objects.get_categories_with_sub_categories()
    # get latest contact details
    contact_details = ContactDetail.objects.get_latest_contact_details()

    return locals()
Пример #12
0
    def test_cache_invalidate_on_save(self):

        manager = global_preferences_registry.manager()
        model_instance = manager.create_db_pref(section=None, name="no_section", value=False)

        with self.assertNumQueries(0):
            assert not manager["no_section"]
            manager["no_section"]

        model_instance.value = True
        model_instance.save()

        with self.assertNumQueries(0):
            assert manager["no_section"]
            manager["no_section"]
Пример #13
0
    def test_quickstart(self):
        global_preferences = global_preferences_registry.manager()

        self.assertEqual(global_preferences["user__registration_allowed"], False)

        global_preferences["user__registration_allowed"] = True

        self.assertEqual(global_preferences["user__registration_allowed"], True)
        self.assertEqual(GlobalPreferenceModel.objects.get(section="user", name="registration_allowed").value, True)

        self.assertEqual(self.henri.preferences["misc__favourite_colour"], "Green")

        self.henri.preferences["misc__favourite_colour"] = "Blue"

        self.assertEqual(self.henri.preferences["misc__favourite_colour"], "Blue")

        self.assertEqual(
            UserPreferenceModel.objects.get(section="misc", name="favourite_colour", instance=self.henri).value, "Blue"
        )
Пример #14
0
    def get(self, request, subscription_id):
        preferences = global_preferences_registry.manager()
        subscription = get_object_or_404(Subscription, id=int(subscription_id))
        volunteer = subscription.volunteer
        secret = preferences['payment__bcash_secret']

        form = BcashForm(secret=secret,
                         initial={
                             'campanha':
                             preferences['payment__campaign'],
                             'cod_loja':
                             preferences['payment__bcash_cod_loja'],
                             'email_loja':
                             preferences['payment__receiver_email'],
                             'meio_pagamento':
                             10,
                             'parcela_maxima':
                             1,
                             'produto_codigo_1':
                             subscription_id,
                             'produto_descricao_1':
                             preferences['payment__item_name'].format(
                                 volunteer.name),
                             'produto_qtde_1':
                             1,
                             'produto_valor_1':
                             preferences['subscription__ticket_value'],
                             'redirect':
                             'true',
                             'redirect_time':
                             '10',
                             'url_retorno':
                             urljoin(preferences['general__site_url'],
                                     reverse('bcash:return_url')),
                         })

        data = {'fields': form.to_json()}
        data['endpoint'] = form.get_endpoint()
        data['image_button'] = form.get_image()

        response = Response(data)
        return response
    def handle(self, *args, **options):

        # Create needed preferences
        # Global
        print('Creating missing global preferences...')
        manager = global_preferences_registry.manager()
        manager.all()

        deleted = delete_preferences(GlobalPreferenceModel.objects.all())
        print("Deleted {0} global preferences".format(len(deleted)))

        for preference_model, registry in preference_models.items():
            deleted = delete_preferences(preference_model.objects.all())
            print("Deleted {0} {1} preferences".format(len(deleted), preference_model.__class__.__name__))
            if not hasattr(preference_model, 'get_instance_model'):
                continue

            print('Creating missing preferences for {0} model...'.format(preference_model.get_instance_model().__name__))
            for instance in preference_model.get_instance_model().objects.all():
                instance.preferences.all()
    def get(self, request, subscription_id):
        preferences = global_preferences_registry.manager()
        subscription = get_object_or_404(Subscription, id=int(subscription_id))
        volunteer = subscription.volunteer

        form = PayPalPaymentsForm(initial={
            'business':         preferences['payment__receiver_email'],
            'amount':           preferences['subscription__ticket_value'],
            'custom':           preferences['payment__campaign'],
            'item_name':        preferences['payment__item_name'].format(volunteer.name),
            'item_number':      subscription_id,
            'notify_url':       urljoin(preferences['general__site_url'], reverse('paypal-ipn')),
            'invoice':          'Subscription(id=%s)' % subscription_id,
            'currency_code':    'BRL',
            'lc':               'BR',
            'no_shipping':      '1',
            'address_override': '1',
            'country':          'BR',

            'first_name':      volunteer.first_name(),
            'last_name':       volunteer.last_name(),
            'address1':        volunteer.address,
            'address2':        volunteer.complement,
            'city':            volunteer.city,
            'state':           volunteer.state,
            'zip':             volunteer.cep,
            'night_phone_a':   '',
            'night_phone_b':   '',
            'night_phone_c':   '',
            'email':           volunteer.email,
        })

        data = dict([(f.name, f.value()) for f in form if f.value() is not None])
        data['endpoint'] = form.get_endpoint()
        data['image_button'] = form.get_image()

        response = Response(data)
        return response
 def test_global_preferences_manager_by_name(self):
     manager = global_preferences_registry.manager()
     self.assertEqual(manager.by_name()['max_users'], manager['user__max_users'])
     self.assertEqual(len(manager.all()), len(manager.by_name()))
 def get_instance(cls):
     if cls._instance is None:
         cls._instance = global_preferences_registry.manager()
     return cls._instance
Пример #19
0
import io
import qrcode

from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from django.template.defaultfilters import slugify

from dynamic_preferences import global_preferences_registry
from paypal.standard.ipn.signals import valid_ipn_received
from paypal.standard.ipn.models import PayPalIPN
from paypal.standard.models import ST_PP_COMPLETED
from bcash.models import Transaction, ST_APPROVED
from subscriptions.models import Subscription, SubscriptionPayment

preferences = global_preferences_registry.manager()


def detect_paypal_payment_and_mark_subscription(sender, **kwargs):
    match = re.search('^Subscription\(id=(\d+)\)$', sender.invoice)

    if match:
        pk = int(match.group(1))
        subscription = Subscription.objects.filter(pk=pk).first()

        if subscription:
            if sender.payment_status == ST_PP_COMPLETED:
                subscription.paid = sender.payment_gross
                subscription.payment = 'eletronic'
                subscription.save()
 def test_global_preferences_manager_get_by_name(self):
     manager = global_preferences_registry.manager()
     self.assertEqual(manager.get_by_name('max_users'), manager['user__max_users'])
 def setUp(self):
     # instanciate a manager for global preferences
     self.global_preferences = global_preferences_registry.manager()
Пример #22
0
    def get(self, request, subscription_id):
        preferences = global_preferences_registry.manager()
        subscription = get_object_or_404(Subscription, id=int(subscription_id))
        volunteer = subscription.volunteer

        form = PayPalPaymentsForm(
            initial={
                'business':
                preferences['payment__receiver_email'],
                'amount':
                preferences['subscription__ticket_value'],
                'custom':
                preferences['payment__campaign'],
                'item_name':
                preferences['payment__item_name'].format(volunteer.name),
                'item_number':
                subscription_id,
                'notify_url':
                urljoin(preferences['general__site_url'], reverse(
                    'paypal-ipn')),
                'invoice':
                'Subscription(id=%s)' % subscription_id,
                'currency_code':
                'BRL',
                'lc':
                'BR',
                'no_shipping':
                '1',
                'address_override':
                '1',
                'country':
                'BR',
                'first_name':
                volunteer.first_name(),
                'last_name':
                volunteer.last_name(),
                'address1':
                volunteer.address,
                'address2':
                volunteer.complement,
                'city':
                volunteer.city,
                'state':
                volunteer.state,
                'zip':
                volunteer.cep,
                'night_phone_a':
                '',
                'night_phone_b':
                '',
                'night_phone_c':
                '',
                'email':
                volunteer.email,
            })

        data = dict([(f.name, f.value()) for f in form
                     if f.value() is not None])
        data['endpoint'] = form.get_endpoint()
        data['image_button'] = form.get_image()

        response = Response(data)
        return response
Пример #23
0
 def test_template_gets_global_preferences_via_template_processor(self):
     global_preferences = global_preferences_registry.manager()
     url = reverse("dynamic_preferences.test.templateview")
     response = self.client.get(url)
     self.assertEqual(response.context["global_preferences"], global_preferences.all())
Пример #24
0
 def test_global_preferences_manager_get(self):
     global_preferences = global_preferences_registry.manager()
     self.assertEqual(global_preferences["no_section"], False)
Пример #25
0
 def test_global_preferences_manager_set(self):
     global_preferences = global_preferences_registry.manager()
     global_preferences["no_section"] = True
     self.assertEqual(global_preferences["no_section"], True)