当前位置: 首页>>代码示例>>Python>>正文


Python models.ModuleSetting类代码示例

本文整理汇总了Python中anaf.core.models.ModuleSetting的典型用法代码示例。如果您正苦于以下问题:Python ModuleSetting类的具体用法?Python ModuleSetting怎么用?Python ModuleSetting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ModuleSetting类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

    def setUp(self):
        self.group = Group.objects.create(name='test')
        self.user = DjangoUser.objects.create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()

        perspective = Perspective(name='default')
        perspective.set_user(self.user.profile)
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.folder = Folder(name='test')
        self.folder.set_user(self.user.profile)
        self.folder.save()

        self.document = Document(title='test_document', folder=self.folder)
        self.document.set_user(self.user.profile)
        self.document.save()

        self.file = File(name='test_file', folder=self.folder)
        self.file.set_user(self.user.profile)
        self.file.save()

        self.link = WebLink(title='test', folder=self.folder, url='test')
        self.link.set_user(self.user.profile)
        self.link.save()
开发者ID:tovmeod,项目名称:anaf,代码行数:27,代码来源:tests.py

示例2: setUp

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()

        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()

        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.set_default_user()
        self.contact.save()

        self.stream = MessageStream(name='test')
        self.stream.set_default_user()
        self.stream.save()

        self.message = Message(
            title='test', body='test', author=self.contact, stream=self.stream)
        self.message.set_default_user()
        self.message.save()
开发者ID:tovmeod,项目名称:anaf,代码行数:27,代码来源:tests.py

示例3: __init__

    def __init__(self, user, *args, **kwargs):
        "Sets choices and initial value"
        super(SettingsForm, self).__init__(*args, **kwargs)
        self.user = user

        self.fields['default_contact_type'].label = _('Default Contact Type')
        self.fields['default_contact_type'].queryset = Object.filter_permitted(user,
                                                                               ContactType.objects, mode='x')
        try:
            conf = ModuleSetting.get_for_module('anaf.messaging', 'default_contact_type',
                                                user=user)[0]
            default_contact_type = ContactType.objects.get(pk=long(conf.value))
            self.fields[
                'default_contact_type'].initial = default_contact_type.id
        except:
            pass

        self.fields['default_imap_folder'].label = _('Default IMAP Folder')
        try:
            conf = ModuleSetting.get_for_module('anaf.messaging', 'default_imap_folder',
                                                user=user)[0]
            self.fields['default_imap_folder'].initial = conf.value
        except:
            self.fields[
                'default_imap_folder'].initial = settings.ANAF_MESSAGING_IMAP_DEFAULT_FOLDER_NAME

        self.fields['signature'].label = _('Signature')
        try:
            conf = ModuleSetting.get_for_module('anaf.messaging', 'signature',
                                                user=user, strict=True)[0]
            signature = conf.value
            self.fields['signature'].initial = signature
        except:
            pass
开发者ID:tovmeod,项目名称:anaf,代码行数:34,代码来源:forms.py

示例4: htdate

def htdate(context, date, dateformat="DATE_FORMAT"):
    """ Render date in the current locale

    To render date in a custom format use Django format, details:
    http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date

    """

    if not date:
        return ""

    lang = translation.get_language()

    localeformat = dateformat
    formatspath = getattr(settings, "FORMAT_MODULE_PATH", "anaf.formats")
    try:
        modulepath = formatspath + "." + lang + ".formats"
        module = __import__(modulepath, fromlist=[str(modulepath)])
        localeformat = getattr(module, dateformat, dateformat)
    except ImportError:
        pass

    request = context["request"]

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get("default_timezone")[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get("default_timezone", user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]

    all_timezones = settings.ANAF_SERVER_TIMEZONE
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if sign == "-":
        date = date - timedelta(hours=hours, minutes=mins)
    else:
        date = date + timedelta(hours=hours, minutes=mins)

    result = djangodate(date, localeformat)
    return Markup(result)
开发者ID:tovmeod,项目名称:anaf,代码行数:59,代码来源:modules.py

示例5: email_caller_on_new_ticket

def email_caller_on_new_ticket(sender, instance, created, **kwargs):
    "When a new ticket is created send an email to the caller"
    if created:
        send_email_to_caller = False
        try:
            conf = ModuleSetting.get_for_module(
                'anaf.services', 'send_email_to_caller')[0]
            send_email_to_caller = conf.value
        except:
            send_email_to_caller = settings.ANAF_SEND_EMAIL_TO_CALLER

        if send_email_to_caller:
            # don't send email to yourself
            creator_contact = None
            if instance.creator:
                creator_contact = instance.creator.get_contact()

            if instance.caller and instance.caller != creator_contact:
                if not instance.reference:
                    if instance.queue:
                        instance.reference = instance.queue.ticket_code + \
                            str(instance.id)
                    else:
                        instance.reference = str(instance.id)
                    instance.save()
                subject = "[#{0!s}] {1!s}".format(instance.reference, instance.name)

                # Construct context and render to html, body
                context = {'ticket': instance}
                try:
                    conf = ModuleSetting.get_for_module(
                        'anaf.services', 'send_email_template')[0]
                    send_email_template = conf.value
                    html = render_string_template(send_email_template, context)
                except:
                    html = render_to_string(
                        'services/emails/notify_caller', context, response_format='html')
                body = strip_tags(html)

                if instance.queue and instance.queue.message_stream:
                    stream = instance.queue.message_stream
                    if stream.outgoing_server_name:
                        try:
                            caller_email = instance.caller.get_email()
                            if caller_email:
                                toaddr = caller_email
                                ssl = False
                                if stream.outgoing_server_type == 'SMTP-SSL':
                                    ssl = True
                                email = BaseEmail(stream.outgoing_server_name,
                                                  stream.outgoing_server_username,
                                                  stream.outgoing_password,
                                                  stream.outgoing_email,
                                                  toaddr, subject, body, html=html,
                                                  ssl=ssl)
                                email.process_email()
                        except:
                            pass
开发者ID:tovmeod,项目名称:anaf,代码行数:58,代码来源:models.py

示例6: save

    def save(self):
        "Form processor"
        try:
            ModuleSetting.set_for_module('default_task_status',
                                         self.cleaned_data[
                                             'default_task_status'].id,
                                         'anaf.projects')

        except Exception:
            return False
开发者ID:tovmeod,项目名称:anaf,代码行数:10,代码来源:forms.py

示例7: create_instance

 def create_instance(self, request, *args, **kwargs):
     ticket = Ticket(creator=request.user.profile)
     if not request.agent:
         if request.queue:
             ticket.queue = request.queue
             if request.queue.default_ticket_status:
                 ticket.status = request.queue.default_ticket_status
             else:
                 try:
                     conf = ModuleSetting.get_for_module(
                         'anaf.services', 'default_ticket_status')[0]
                     ticket.status = TicketStatus.objects.get(
                         pk=long(conf.value))
                 except:
                     if 'statuses' in request.context:
                         try:
                             ticket.status = request.context['statuses'][0]
                         except:
                             pass
             ticket.priority = request.queue.default_ticket_priority
             ticket.service = request.queue.default_service
         else:
             try:
                 conf = ModuleSetting.get_for_module(
                     'anaf.services', 'default_ticket_status')[0]
                 ticket.status = TicketStatus.objects.get(
                     pk=long(conf.value))
             except:
                 if 'statuses' in request.context:
                     try:
                         ticket.status = request.context['statuses'][0]
                     except:
                         pass
             try:
                 conf = ModuleSetting.get_for_module(
                     'anaf.services', 'default_ticket_queue')[0]
                 ticket.queue = TicketQueue.objects.get(pk=long(conf.value))
             except:
                 if 'queues' in request.context:
                     try:
                         ticket.queue = request.context['queues'][0]
                     except:
                         pass
         try:
             ticket.caller = request.user.profile.get_contact()
         except:
             pass
     return ticket
开发者ID:tovmeod,项目名称:anaf,代码行数:48,代码来源:handlers.py

示例8: settings_view

def settings_view(request, response_format='html'):
    "Settings"

    # default changeset status
    try:
        conf = ModuleSetting.get_for_module(
            'anaf.changes', 'default_changeset_status')[0]
        default_changeset_status = ChangeSetStatus.objects.get(
            pk=long(conf.value))

    except Exception:
        default_changeset_status = None

    # check not trashed
    if default_changeset_status and default_changeset_status.trash:
        default_changeset_status = None

    settings_statuses = ChangeSetStatus.objects.filter(trash=False)

    context = _get_default_context(request)
    context.update({'default_changeset_status': default_changeset_status,
                    'settings_statuses': settings_statuses})

    return render_to_response('changes/settings_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:25,代码来源:views.py

示例9: invoice

 def invoice(self):
     "Create a new sale order for self"
     new_invoice = SaleOrder()
     try:
         conf = ModuleSetting.get_for_module(
             'anaf.sales', 'default_order_status')[0]
         new_invoice.status = long(conf.value)
     except Exception:
         ss = SaleStatus.objects.all()[0]
         new_invoice.status = ss
     so = SaleSource.objects.all()[0]
     new_invoice.source = so
     new_invoice.client = self.client
     new_invoice.reference = "Subscription Invoice " + \
                             str(datetime.today().strftime('%Y-%m-%d'))
     new_invoice.save()
     try:
         op = self.orderedproduct_set.filter(
             trash=False).order_by('-date_created')[0]
         opn = OrderedProduct()
         opn.order = new_invoice
         opn.product = self.product
         opn.quantity = op.quantity
         opn.discount = op.discount
         opn.subscription = self
         opn.save()
     except IndexError:
         opn = OrderedProduct()
         opn.order = new_invoice
         opn.product = self.product
         opn.quantity = 1
         opn.subscription = self
         opn.save()
     return new_invoice.reference
开发者ID:tovmeod,项目名称:anaf,代码行数:34,代码来源:models.py

示例10: htform

def htform(context, form):
    "Set time zone"

    request = context["request"]

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get("default_timezone")[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get("default_timezone", user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]

    all_timezones = settings.ANAF_SERVER_TIMEZONE
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if not form.errors:
        for field in form:
            try:
                date = datetime.strptime(str(field.form.initial[field.name]), "%Y-%m-%d %H:%M:%S")
                if date:
                    if sign == "-":
                        field.form.initial[field.name] = date - timedelta(hours=hours, minutes=mins)
                    else:
                        field.form.initial[field.name] = date + timedelta(hours=hours, minutes=mins)
            except:
                pass

    return form
开发者ID:tovmeod,项目名称:anaf,代码行数:46,代码来源:modules.py

示例11: messaging_compose

def messaging_compose(request, response_format='html'):
    "New message page"

    user = request.user.profile

    if request.POST:
        if 'cancel' not in request.POST:
            message = Message()
            message.author = user.get_contact()
            if not message.author:
                return user_denied(request,
                                   message="You can't send message without a Contact Card assigned to you.",
                                   response_format=response_format)

            form = MessageForm(
                request.user.profile, None, None, request.POST, instance=message)
            if form.is_valid():
                message = form.save()
                message.recipients.add(user.get_contact())
                message.set_user_from_request(request)
                message.read_by.add(user)
                try:
                    # if email entered create contact and add to recipients
                    if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']:
                        try:
                            conf = ModuleSetting.get_for_module(
                                'anaf.messaging', 'default_contact_type')[0]
                            default_contact_type = ContactType.objects.get(
                                pk=long(conf.value))
                        except Exception:
                            default_contact_type = None
                        emails = request.POST[
                            'multicomplete_recipients'].split(',')
                        for email in emails:
                            emailstr = unicode(email).strip()
                            if re.match('[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr):
                                contact, created = Contact.get_or_create_by_email(
                                    emailstr, contact_type=default_contact_type)
                                message.recipients.add(contact)
                                if created:
                                    contact.set_user_from_request(request)
                except:
                    pass
                # send email to all recipients
                message.send_email()

                return HttpResponseRedirect(reverse('messaging'))
        else:
            return HttpResponseRedirect(reverse('messaging'))

    else:
        form = MessageForm(request.user.profile, None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('messaging/message_compose', context,
                              context_instance=RequestContext(request), response_format=response_format)
开发者ID:tovmeod,项目名称:anaf,代码行数:58,代码来源:views.py

示例12: process_msg

    def process_msg(self, msg, attrs, attachments):
        """Save message, Cap!"""
        from anaf.messaging.models import Message

        try:
            conf = ModuleSetting.get_for_module("anaf.messaging", "default_contact_type")[0]
            default_contact_type = ContactType.objects.get(pk=long(conf.value))
        except:
            default_contact_type = None

        email_author, created = Contact.get_or_create_by_email(
            attrs.author_email, attrs.author_name, default_contact_type
        )
        if created:
            email_author.copy_permissions(self.stream)

        # check if the message is already retrieved
        existing = Message.objects.filter(
            stream=self.stream, title=attrs.subject, author=email_author, body=attrs.body
        ).exists()
        if not existing:
            message = None
            if attrs.subject[:3] == "Re:":
                # process replies
                if attrs.subject[:4] == "Re: ":
                    original_subject = attrs.subject[4:]
                else:
                    original_subject = attrs.subject[3:]

                try:
                    query = (
                        Q(reply_to__isnull=True)
                        & Q(recipients=email_author)
                        & (Q(title=original_subject) | Q(title=attrs.subject))
                    )
                    original = Message.objects.filter(query).order_by("-date_created")[:1][0]
                    message = Message(
                        title=attrs.subject, body=attrs.body, author=email_author, stream=self.stream, reply_to=original
                    )
                    if attrs.email_date:
                        message.date_created = attrs.email_date

                    message.save()
                    message.copy_permissions(original)
                    original.read_by.clear()
                except IndexError:
                    pass
            if not message:
                message = Message(title=attrs.subject, body=attrs.body, author=email_author, stream=self.stream)
                if attrs.email_date:
                    message.date_created = attrs.email_date
                message.save()
                message.copy_permissions(self.stream)
                message.recipients.add(email_author)
开发者ID:tovmeod,项目名称:anaf,代码行数:54,代码来源:emails.py


注:本文中的anaf.core.models.ModuleSetting类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。