def __init__(self, user, skip=None, *args, **kwargs): "Sets allowed values" if skip is None: skip = [] super(SLAFilterForm, self).__init__(*args, **kwargs) self.fields['client'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['client'].required = False self.fields['client'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) self.fields['client'].label = _("Client") self.fields['provider'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['provider'].required = False self.fields['provider'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) self.fields['provider'].label = _("Provider") self.fields['service'].queryset = Object.filter_permitted( user, Service.objects, mode='x') self.fields['service'].required = False self.fields['service'].label = _("Service")
def __init__(self, user, *args, **kwargs): "Sets allowed values" super(QueueForm, self).__init__(*args, **kwargs) manager = TicketQueue.objects if 'instance' in kwargs: instance = kwargs['instance'] manager = manager.exclude(Q(parent=instance) & Q(pk=instance.id)) self.fields['parent'].queryset = Object.filter_permitted(user, manager, mode='x') self.fields['default_service'].queryset = Object.filter_permitted( user, Service.objects, mode='x') self.fields['waiting_time'].help_text = "seconds" self.fields['name'].label = _("Name") self.fields['active'].label = _("Active") self.fields['parent'].label = _("Parent") self.fields['default_ticket_status'].label = _("Default ticket status") self.fields['default_ticket_priority'].label = _( "Default ticket priority") self.fields['default_service'].label = _("Default service") self.fields['waiting_time'].label = _("Waiting time") self.fields['next_queue'].queryset = Object.filter_permitted( user, TicketQueue.objects, mode='x') self.fields['next_queue'].label = _("Next queue") self.fields['ticket_code'].label = _("Ticket code") self.fields['message_stream'].label = _("Message stream") self.fields['message_stream'].widget.attrs.update( {'popuplink': reverse('messaging_stream_add')}) self.fields['details'].label = _("Details")
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(OrderFilterForm, self).__init__(*args, **kwargs) if 'status' in skip: del self.fields['status'] else: self.fields['status'].queryset = Object.filter_permitted(user, SaleStatus.objects.filter(use_sales=True)) self.fields['status'].required = False self.fields['status'].label = _("Status") self.fields['paid'].label = _("Payment Status") self.fields['client'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['client'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['client'].required = False self.fields['client'].label = _("Client") self.fields['source'].queryset = Object.filter_permitted( user, SaleSource.objects.filter(active=True)) self.fields['source'].required = False self.fields['source'].label = _("Source") self.fields['assigned'].label = _("Assigned") self.fields['assigned'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_user_lookup')}) if 'assigned' in skip: del self.fields['assigned'] else: self.fields['assigned'].help_text = ""
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(LeadFilterForm, self).__init__(*args, **kwargs) self.fields['contact'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['contact'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['contact'].required = False self.fields['contact'].label = _("Contact") self.fields['products_interested'].queryset = Object.filter_permitted( user, Product.objects) self.fields['products_interested'].required = False self.fields['products_interested'].help_text = "" self.fields['products_interested'].label = _("Products interested") self.fields['source'].queryset = Object.filter_permitted(user, SaleSource.objects.filter(active=True)) self.fields['source'].required = False self.fields['source'].label = _("Source") self.fields['status'].queryset = Object.filter_permitted(user, SaleStatus.objects.filter(use_leads=True)) self.fields['status'].required = False self.fields['status'].label = _("Status") self.fields['contact_method'].required = False self.fields['contact_method'].label = _("Contact method")
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(FilterForm, self).__init__(*args, **kwargs) if 'title' in skip: del self.fields['title'] else: self.fields['title'].required = False self.fields['title'].label = _("Title") if 'stream' in skip: del self.fields['stream'] else: self.fields['stream'].queryset = Object.filter_permitted( user, MessageStream.objects, mode='x') self.fields['stream'].required = False self.fields['stream'].label = _("Stream") if 'author' in skip: del self.fields['author'] else: self.fields['author'].required = False self.fields['author'].label = _("Author") self.fields['author'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['author'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')})
def __init__(self, user, project_id, *args, **kwargs): super(ProjectForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['parent'].queryset = Object.filter_permitted( user, Project.objects, mode='x') self.fields['parent'].label = _("Parent") if project_id: self.fields['parent'].initial = project_id self.fields['manager'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['manager'].label = _("Manager") self.fields['manager'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['manager'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['client'].label = _("Client") self.fields['client'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['client'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['client'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['details'].label = _("Details") self.fields['details'].widget.attrs.update({'class': 'full-editor'})
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(TransactionFilterForm, self).__init__(*args, **kwargs) if 'datefrom' in skip: del self.fields['datefrom'] del self.fields['dateto'] else: self.fields['datefrom'] = forms.DateField(label=_("Date From"), required=False) self.fields['datefrom'].widget.attrs.update( {'class': 'datepicker'}) if 'dateto' in skip: del self.fields['dateto'] del self.fields['datefrom'] else: self.fields['dateto'] = forms.DateField(label=_("Date To"), required=False) self.fields['dateto'].widget.attrs.update({'class': 'datepicker'}) if 'category' in skip: del self.fields['category'] else: self.fields['category'].queryset = Object.filter_permitted( user, Category.objects) self.fields['category'].label = _("Category") self.fields['category'].help_text = "" self.fields['category'].required = False if 'source' in skip: del self.fields['source'] else: self.fields['source'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['source'].label = _("Source") self.fields['source'].help_text = "" self.fields['source'].required = False self.fields['source'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) if 'target' in skip: del self.fields['target'] else: self.fields['target'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['target'].required = False self.fields['target'].label = _("Target") self.fields['target'].help_text = "" self.fields['target'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') })
def __init__(self, user, parent=None, *args, **kwargs): super(ProductForm, self).__init__(*args, **kwargs) self.fields['supplier'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['supplier'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['supplier'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['supplier'].label = _("Supplier") self.fields['active'].initial = True self.fields['active'].label = _("Active") manager = Product.objects.filter(active=True) if 'instance' in kwargs: instance = kwargs['instance'] manager = manager.exclude(Q(parent=instance) & Q(pk=instance.id)) self.fields['parent'].queryset = Object.filter_permitted( user, manager, mode='x') if parent: self.fields['parent'].initial = get_object_or_404( Product, pk=parent) self.fields['parent'].label = _("Parent") self.fields['product_type'].label = _("Product type") self.fields['code'].label = _("Code") self.fields['supplier_code'].label = _("Supplier code") self.fields['buy_price'].label = _("Buy price") self.fields['sell_price'].label = _("Sell price") self.fields['stock_quantity'].label = _("Stock quantity") self.fields['runout_action'].label = _("Runout action") self.fields['details'].label = _("Details")
def __init__(self, user, *args, **kwargs): super(EquityForm, self).__init__(*args, **kwargs) self.fields['equity_type'].label = _("Equity type") self.fields['issue_price'].label = _("Issue price") self.fields['sell_price'].label = _("Sell price") self.fields['issuer'].label = _("Issuer") self.fields['owner'].label = _("Owner") self.fields['amount'].label = _("Quantity") self.fields['purchase_date'].label = _("Purchase date") self.fields['details'].label = _("Details") self.fields['owner'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['owner'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['owner'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['issuer'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['issuer'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['issuer'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) try: conf = ModuleSetting.get_for_module( 'anaf.finance', 'my_company')[0] self.fields['issuer'].initial = long(conf.value) except Exception: pass self.fields['purchase_date'].widget.attrs.update( {'class': 'datepicker'})
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(LiabilityFilterForm, self).__init__(*args, **kwargs) if 'due_date_from' in skip: del self.fields['due_date_from'] else: self.fields['due_date_from'] = forms.DateField( label=_("Due Date From:"), required=False) self.fields['due_date_from'].widget.attrs.update( {'class': 'datepicker'}) if 'due_date_to' in skip: del self.fields['due_date_to'] else: self.fields['due_date_to'] = forms.DateField( label=_("Due Date To:"), required=False) self.fields['due_date_to'].widget.attrs.update( {'class': 'datepicker'}) if 'category' in skip: del self.fields['category'] else: self.fields['category'].queryset = Object.filter_permitted( user, Category.objects) self.fields['category'].label = _("Category") self.fields['category'].help_text = "" self.fields['category'].required = False if 'source' in skip: del self.fields['source'] else: self.fields['source'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['source'].label = _("Source") self.fields['source'].help_text = "" self.fields['source'].required = False self.fields['source'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) if 'target' in skip: del self.fields['target'] else: self.fields['target'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['target'].required = False self.fields['target'].label = _("Target") self.fields['target'].help_text = "" self.fields['target'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) if 'account' in skip: del self.fields['account'] else: self.fields['account'].queryset = Object.filter_permitted( user, Account.objects) self.fields['account'].required = False self.fields['account'].label = _("Account") self.fields['account'].help_text = ""
def __init__(self, user, *args, **kwargs): "Sets allowed values" super(QueueForm, self).__init__(*args, **kwargs) manager = TicketQueue.objects if 'instance' in kwargs: instance = kwargs['instance'] manager = manager.exclude(Q(parent=instance) & Q(pk=instance.id)) self.fields['parent'].queryset = Object.filter_permitted( user, manager, mode='x') self.fields['default_service'].queryset = Object.filter_permitted( user, Service.objects, mode='x') self.fields['waiting_time'].help_text = "seconds" self.fields['name'].label = _("Name") self.fields['active'].label = _("Active") self.fields['parent'].label = _("Parent") self.fields['default_ticket_status'].label = _("Default ticket status") self.fields['default_ticket_priority'].label = _( "Default ticket priority") self.fields['default_service'].label = _("Default service") self.fields['waiting_time'].label = _("Waiting time") self.fields['next_queue'].queryset = Object.filter_permitted( user, TicketQueue.objects, mode='x') self.fields['next_queue'].label = _("Next queue") self.fields['ticket_code'].label = _("Ticket code") self.fields['message_stream'].label = _("Message stream") self.fields['message_stream'].widget.attrs.update( {'popuplink': reverse('messaging_stream_add')}) self.fields['details'].label = _("Details")
def __init__(self, user, *args, **kwargs): super(SubscriptionForm, self).__init__(*args, **kwargs) del self.fields['cycle_end'] self.fields['product'].queryset = Object.filter_permitted( user, Product.objects) self.fields['product'].label = _("Product") self.fields['client'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['client'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['client'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['client'].label = _("Client") self.fields['start'].widget.attrs.update({'class': 'datepicker'}) self.fields['start'].label = _("Start") self.fields['expiry'].widget.attrs.update({'class': 'datepicker'}) self.fields['expiry'].label = _("Expiry") if 'instance' in kwargs: self.instance = kwargs['instance'] self.fields['start'].widget.attrs['readonly'] = True del kwargs['instance'] self.fields['active'].initial = True self.fields['active'].label = _("Active") self.fields['cycle_period'].label = _("Cycle period") self.fields['details'].label = _("Details")
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(EquityFilterForm, self).__init__(*args, **kwargs) if 'purchase_date_from' in skip: del self.fields['purchase_date_from'] else: self.fields['purchase_date_from'] = forms.DateField( label="Purchase Date From:", required=False) self.fields['purchase_date_from'].widget.attrs.update( {'class': 'datepicker'}) self.fields['purchase_date_from'].label = _("Purchase Date From") if 'purchase_date_to' in skip: del self.fields['purchase_date_to'] else: self.fields['purchase_date_to'] = forms.DateField( label="Purchase Date To:", required=False) self.fields['purchase_date_to'].widget.attrs.update( {'class': 'datepicker'}) self.fields['purchase_date_to'].label = _("Purchase Date To") if 'equity_type' in skip: del self.fields['equity_type'] else: self.fields['equity_type'].label = _("Equity Type") self.fields['equity_type'].help_text = "" self.fields['equity_type'].required = False if 'issuer' in skip: del self.fields['issuer'] else: self.fields['issuer'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['issuer'].label = _("Issuer") self.fields['issuer'].help_text = "" self.fields['issuer'].required = False self.fields['issuer'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) if 'owner' in skip: del self.fields['owner'] else: self.fields['owner'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['owner'].required = False self.fields['owner'].label = _("Owner") self.fields['owner'].help_text = "" self.fields['owner'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') })
def _find_duplicates(resource_id, item, user): "Finds matching items" dups = [] item_id = None if 'id' in item.raw: item_id = item.id.raw # Finding previously syncd items if item_id: key = '#' + unicode(resource_id) + '.' + unicode(item_id) + '#' dups = Object.filter_permitted( user, Contact.objects).filter(nuvius_resource__contains=key) if dups: return dups # Finding equivalent items # If name and (email or phone) are the same - it's same person if item.name: candidates = Object.filter_permitted( user, Contact.objects).filter(name=item.name.raw).distinct() dups = [] if candidates and (item.email or item.phone): for candidate in candidates: matching_emails = [] emails = candidate.contactvalue_set.filter( field__field_type='email') if item.email.raw and emails: matching_emails = emails.filter(value__in=item.email.raw) phones = candidate.contactvalue_set.filter( field__field_type='phone') matching_phones = [] if item.phone.raw and phones: matching_phones = phones.filter(value__in=item.phone.raw) # If anything matches or if we have no emails or no phones at # all - add to duplicates if matching_emails or matching_phones or (not emails and not phones): dups.append(candidate) elif not candidates and (item.email or item.phone): query = Q() if item.email: query = query & Q(contactvalue__value__in=item.email.raw) if item.phone: query = query | Q(contactvalue__value__in=item.phone.raw) dups = Object.filter_permitted( user, Contact.objects).filter(query).distinct() else: dups = candidates elif item.email or item.phone: query = Q() if item.email: query = query & Q(contactvalue__value__in=item.email.raw) if item.phone: query = query & Q(contactvalue__value__in=item.phone.raw) dups = Object.filter_permitted(user, Contact.objects).filter(query) return dups
def _find_duplicates(resource_id, item, user): "Finds matching items" dups = [] item_id = None if 'id' in item.raw: item_id = item.id.raw # Finding previously syncd items if item_id: key = '#' + unicode(resource_id) + '.' + unicode(item_id) + '#' dups = Object.filter_permitted(user, Contact.objects).filter( nuvius_resource__contains=key) if dups: return dups # Finding equivalent items # If name and (email or phone) are the same - it's same person if item.name: candidates = Object.filter_permitted( user, Contact.objects).filter(name=item.name.raw).distinct() dups = [] if candidates and (item.email or item.phone): for candidate in candidates: matching_emails = [] emails = candidate.contactvalue_set.filter( field__field_type='email') if item.email.raw and emails: matching_emails = emails.filter(value__in=item.email.raw) phones = candidate.contactvalue_set.filter( field__field_type='phone') matching_phones = [] if item.phone.raw and phones: matching_phones = phones.filter(value__in=item.phone.raw) # If anything matches or if we have no emails or no phones at # all - add to duplicates if matching_emails or matching_phones or (not emails and not phones): dups.append(candidate) elif not candidates and (item.email or item.phone): query = Q() if item.email: query = query & Q(contactvalue__value__in=item.email.raw) if item.phone: query = query | Q(contactvalue__value__in=item.phone.raw) dups = Object.filter_permitted( user, Contact.objects).filter(query).distinct() else: dups = candidates elif item.email or item.phone: query = Q() if item.email: query = query & Q(contactvalue__value__in=item.email.raw) if item.phone: query = query & Q(contactvalue__value__in=item.phone.raw) dups = Object.filter_permitted(user, Contact.objects).filter(query) return dups
def __init__(self, user, *args, **kwargs): "Sets allowed values" super(ServiceLevelAgreementForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['response_time'].help_text = 'minutes' self.fields['response_time'].widget.attrs.update({'size': 10}) self.fields['response_time'].label = _("Response time") self.fields['uptime_rate'].help_text = 'percent' self.fields['uptime_rate'].widget.attrs.update({'size': 5}) self.fields['uptime_rate'].label = _("Uptime rate") self.fields['service'].queryset = Object.filter_permitted( user, Service.objects, mode='x') self.fields['service'].label = _("Service") self.fields['client'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['client'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) self.fields['client'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['client'].label = _("Client") self.fields['provider'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['provider'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) self.fields['provider'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['provider'].label = _("Provider") self.fields['available_from'].initial = "09:00" self.fields['available_from'].widget.attrs.update({'size': 10}) self.fields['available_from'].label = _("Available from") self.fields['available_to'].initial = "18:00" self.fields['available_to'].widget.attrs.update({'size': 10}) self.fields['available_to'].label = _("Available to") contact = user.default_group.get_contact() if contact: self.fields['provider'].initial = contact.id
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) # Translate self.fields['default_ticket_status'].label = _('Default Ticket Status') self.fields['default_ticket_queue'].label = _('Default Queue') self.fields['send_email_to_caller'].label = _( "Notify Caller By E-mail") self.fields['send_email_template'].label = _("E-mail Template") self.fields[ 'default_ticket_status'].queryset = Object.filter_permitted( user, TicketStatus.objects, mode='x') self.fields['default_ticket_queue'].queryset = Object.filter_permitted( user, TicketQueue.objects, mode='x') try: conf = ModuleSetting.get_for_module('anaf.services', 'default_ticket_status')[0] default_ticket_status = TicketStatus.objects.get( pk=long(conf.value)) self.fields[ 'default_ticket_status'].initial = default_ticket_status.id except Exception: pass try: conf = ModuleSetting.get_for_module('anaf.services', 'default_ticket_queue')[0] default_ticket_queue = TicketQueue.objects.get(pk=long(conf.value)) self.fields[ 'default_ticket_queue'].initial = default_ticket_queue.id except Exception: pass try: conf = ModuleSetting.get_for_module('anaf.services', 'send_email_to_caller')[0] self.fields['send_email_to_caller'].initial = conf.value except: self.fields[ 'send_email_to_caller'].initial = settings.ANAF_SEND_EMAIL_TO_CALLER # notification template try: conf = ModuleSetting.get_for_module('anaf.services', 'send_email_template')[0] self.fields['send_email_template'].initial = conf.value except Exception: self.fields['send_email_template'].initial = get_template_source( 'services/emails/notify_caller.html')
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(EquityFilterForm, self).__init__(*args, **kwargs) if 'purchase_date_from' in skip: del self.fields['purchase_date_from'] else: self.fields['purchase_date_from'] = forms.DateField(label="Purchase Date From:", required=False) self.fields['purchase_date_from'].widget.attrs.update( {'class': 'datepicker'}) self.fields['purchase_date_from'].label = _("Purchase Date From") if 'purchase_date_to' in skip: del self.fields['purchase_date_to'] else: self.fields['purchase_date_to'] = forms.DateField( label="Purchase Date To:", required=False) self.fields['purchase_date_to'].widget.attrs.update( {'class': 'datepicker'}) self.fields['purchase_date_to'].label = _("Purchase Date To") if 'equity_type' in skip: del self.fields['equity_type'] else: self.fields['equity_type'].label = _("Equity Type") self.fields['equity_type'].help_text = "" self.fields['equity_type'].required = False if 'issuer' in skip: del self.fields['issuer'] else: self.fields['issuer'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['issuer'].label = _("Issuer") self.fields['issuer'].help_text = "" self.fields['issuer'].required = False self.fields['issuer'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) if 'owner' in skip: del self.fields['owner'] else: self.fields['owner'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['owner'].required = False self.fields['owner'].label = _("Owner") self.fields['owner'].help_text = "" self.fields['owner'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')})
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(FilterForm, self).__init__(*args, **kwargs) if 'author' in skip: del self.fields['author'] else: self.fields['author'].required = False self.fields['author'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_user_lookup') }) self.fields['author'].label = _("Author") if 'object' in skip: del self.fields['object'] else: self.fields['object'] = ObjectModelChoiceField( label=_("Object"), queryset=Object.filter_permitted(user, Object.objects)) self.fields['object'].required = False self.fields['object'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('core_ajax_object_lookup') }) self.fields['object'].label = _("Object") if 'resolved_by' in skip: del self.fields['resolved_by'] else: self.fields['resolved_by'].required = False self.fields['resolved_by'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_user_lookup') }) self.fields['resolved_by'].label = _("Resolved by") if 'status' in skip: del self.fields['status'] else: self.fields['status'].queryset = Object.filter_permitted( user, ChangeSetStatus.objects) self.fields['status'].required = False self.fields['status'].label = _("Status")
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) # Translate self.fields['default_ticket_status'].label = _('Default Ticket Status') self.fields['default_ticket_queue'].label = _('Default Queue') self.fields['send_email_to_caller'].label = _( "Notify Caller By E-mail") self.fields['send_email_template'].label = _("E-mail Template") self.fields['default_ticket_status'].queryset = Object.filter_permitted( user, TicketStatus.objects, mode='x') self.fields['default_ticket_queue'].queryset = Object.filter_permitted( user, TicketQueue.objects, mode='x') try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_status')[0] default_ticket_status = TicketStatus.objects.get( pk=long(conf.value)) self.fields[ 'default_ticket_status'].initial = default_ticket_status.id except Exception: pass try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_queue')[0] default_ticket_queue = TicketQueue.objects.get(pk=long(conf.value)) self.fields[ 'default_ticket_queue'].initial = default_ticket_queue.id except Exception: pass try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_to_caller')[0] self.fields['send_email_to_caller'].initial = conf.value except: self.fields[ 'send_email_to_caller'].initial = settings.ANAF_SEND_EMAIL_TO_CALLER # notification template try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_template')[0] self.fields['send_email_template'].initial = conf.value except Exception: self.fields['send_email_template'].initial = get_template_source( 'services/emails/notify_caller.html')
def item_add_folder(request, folderPath, response_format='html'): "Add new knowledge item to preselected folder" items = Object.filter_permitted( manager=KnowledgeItem.objects, user=request.user.profile, mode='r') try: folder = KnowledgeFolder.by_path(folderPath) knowledgeType_id = folder.id except KnowledgeFolder.DoesNotExist: raise Http404 if request.POST: if 'cancel' not in request.POST: item = KnowledgeItem() form = KnowledgeItemForm( request.user.profile, knowledgeType_id, request.POST, instance=item) if form.is_valid(): item = form.save() item.set_user_from_request(request) return HttpResponseRedirect(reverse('knowledge_item_view', args=[item.folder.treepath, item.treepath])) else: return HttpResponseRedirect(reverse('knowledge')) else: form = KnowledgeItemForm(request.user.profile, knowledgeType_id) context = _get_default_context(request) context.update({'items': items, 'form': form, 'folder': folder}) return render_to_response('knowledge/item_add_folder', context, context_instance=RequestContext(request), response_format=response_format)
def __init__(self, user, *args, **kwargs): super(AccountForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['owner'].label = _("Owner") self.fields['owner'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['owner'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) self.fields['owner'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['balance_currency'].label = _("Currency") self.fields['balance_currency'].widget.attrs.update( {'popuplink': reverse('finance_currency_add')}) try: self.fields['balance_currency'].initial = Currency.objects.get( is_default=True) except: pass self.fields['balance_display'].label = _("Initial Balance") self.fields['details'].label = _("Details")
def item_edit(request, knowledgeItem_id, response_format='html'): "Knowledge item edit page" item = get_object_or_404(KnowledgeItem, pk=knowledgeItem_id) items = Object.filter_permitted( manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if not request.user.profile.has_permission(item, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Item") if request.POST: if 'cancel' not in request.POST: form = KnowledgeItemForm( request.user.profile, None, request.POST, instance=item) if form.is_valid(): item = form.save() return HttpResponseRedirect(reverse('knowledge_item_view', args=[item.folder.treepath, item.treepath])) else: return HttpResponseRedirect(reverse('knowledge_item_view', args=[item.folder.treepath, item.treepath])) else: form = KnowledgeItemForm( request.user.profile, None, instance=item) context = _get_default_context(request) context.update({'form': form, 'item': item, 'items': items}) return render_to_response('knowledge/item_edit', context, context_instance=RequestContext(request), response_format=response_format)
def category_delete(request, knowledgeCategory_id, response_format='html'): "Knowledge Category delete" category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id) items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if not request.user.profile.has_permission(category, mode="w"): return user_denied( request, message="You don't have access to this Knowledge Category") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: category.trash = True category.save() else: category.delete() return HttpResponseRedirect(reverse('knowledge_index')) elif 'cancel' in request.POST: return HttpResponseRedirect( reverse('knowledge_category_view', args=[category.treepath])) context = _get_default_context(request) context.update({'category': category, 'items': items}) return render_to_response('knowledge/category_delete', context, context_instance=RequestContext(request), response_format=response_format)
def item_view(request, folderPath, itemPath, response_format='html'): "Single knowledge item view page" try: item = KnowledgeItem.by_path(folderPath, itemPath) except KnowledgeItem.DoesNotExist: raise Http404 if not item: raise Http404 items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if not request.user.profile.has_permission(item): return user_denied( request, message="You don't have access to this Knowledge Item") context = _get_default_context(request) context.update({'items': items, 'item': item}) return render_to_response('knowledge/item_view', context, context_instance=RequestContext(request), response_format=response_format)
def __init__(self, user, *args, **kwargs): super(ItemTypeForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['parent'].label = _("Parent") self.fields['fields'].label = _("Fields") self.fields['details'].label = _("Details") self.fields['fields'].queryset = Object.filter_permitted( user, ItemField.objects.all(), mode='x') self.fields['fields'].help_text = '' self.fields['parent'].queryset = Object.filter_permitted( user, ItemType.objects.all().exclude(pk=self.instance.id), mode='x')
def messaging_unread(context): "Print a number of unread messages" request = context['request'] user = None if request.user.username: try: user = request.user.profile except Exception: pass unread = 0 messaging = None if user: modules = user.get_perspective().get_modules() messaging = modules.filter(name='anaf.messaging') if messaging: unread = Object.filter_permitted( user, Message.objects.filter(reply_to__isnull=True).exclude( read_by=user)).count() response_format = 'html' if 'response_format' in context: response_format = context['response_format'] return Markup( render_to_string('messaging/tags/unread', { 'messaging': messaging, 'unread': unread }, context_instance=RequestContext(request), response_format=response_format))
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
def __init__(self, user, stream_id, message=None, *args, **kwargs): super(MessageForm, self).__init__(*args, **kwargs) self.fields['title'].label = _("Subject") self.fields['title'].widget = forms.TextInput(attrs={'size': '40'}) self.fields['stream'].queryset = Object.filter_permitted( user, MessageStream.objects, mode='x') self.fields['stream'].label = _("Stream") self.fields['recipients'].label = _("To") self.fields['recipients'].help_text = "" self.fields['recipients'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_contact_lookup')}) if stream_id: self.fields['stream'].initial = stream_id self.fields['stream'].widget = forms.HiddenInput() elif self.fields['stream'].queryset: self.fields['stream'].initial = self.fields[ 'stream'].queryset[0].id self.fields['body'].label = _("Body") # signature try: conf = ModuleSetting.get_for_module('anaf.messaging', 'signature', user=user, strict=True)[0] signature = conf.value self.fields['body'].initial = signature except: pass
def save(self, *args, **kwargs): "Save override to omit empty fields" if self.instance and self.is_valid(): if self.cleaned_data['stream']: self.instance.stream = self.cleaned_data['stream'] if self.user and self.cleaned_data['mark']: if self.cleaned_data['mark'] == 'read': try: self.instance.read_by.add(self.user) except Exception: pass if self.cleaned_data['mark'] == 'unread': try: self.instance.read_by.remove(self.user) except Exception: pass self.instance.save() if self.user and self.cleaned_data['mark']: if self.cleaned_data['mark'] == 'delete': self.instance.delete() if self.cleaned_data['mark'] == 'trash': self.instance.trash = True self.instance.save() elif self.user and self.cleaned_data['markall']: query = Q(reply_to__isnull=True) & ~Q(read_by=self.user) for message in Object.filter_permitted(self.user, Message.objects.filter(query), mode='x'): try: message.read_by.add(self.user) except Exception: pass
def item_add(request, response_format='html'): "Add new knowledge item" items = Object.filter_permitted( manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if request.POST: if 'cancel' not in request.POST: item = KnowledgeItem() form = KnowledgeItemForm( request.user.profile, None, request.POST, instance=item) if form.is_valid(): item = form.save() item.set_user_from_request(request) return HttpResponseRedirect(reverse('knowledge_item_view', args=[item.folder.treepath, item.treepath])) else: return HttpResponseRedirect(reverse('knowledge')) else: form = KnowledgeItemForm(request.user.profile, None) context = _get_default_context(request) context.update({'items': items, 'form': form}) return render_to_response('knowledge/item_add', context, context_instance=RequestContext(request), response_format=response_format)
def item_add(request, response_format='html'): "Add new knowledge item" items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if request.POST: if 'cancel' not in request.POST: item = KnowledgeItem() form = KnowledgeItemForm(request.user.profile, None, request.POST, instance=item) if form.is_valid(): item = form.save() item.set_user_from_request(request) return HttpResponseRedirect( reverse('knowledge_item_view', args=[item.folder.treepath, item.treepath])) else: return HttpResponseRedirect(reverse('knowledge')) else: form = KnowledgeItemForm(request.user.profile, None) context = _get_default_context(request) context.update({'items': items, 'form': form}) return render_to_response('knowledge/item_add', context, context_instance=RequestContext(request), response_format=response_format)
def __init__(self, user, *args, **kwargs): super(UpdateRecordFilterForm, self).__init__(*args, **kwargs) self.fields['author'].label = _("Author") self.fields['about'].label = _("About") self.fields['author'].required = False self.fields['author'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_user_lookup') }) self.fields['about'].queryset = Object.filter_permitted(user, Object.objects, mode='x') self.fields['about'].required = False self.fields['about'].null = True self.fields['about'].help_text = "" self.fields['about'].widget.attrs.update({ 'class': 'multicomplete', 'callback': reverse('core_ajax_object_lookup') })
def category_edit(request, knowledgeCategory_id, response_format='html'): "Knowledge category edit page" category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id) items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if not request.user.profile.has_permission(category, mode="w"): return user_denied( request, message="You don't have access to this Knowledge Category") if request.POST: if 'cancel' not in request.POST: form = KnowledgeCategoryForm(request.POST, instance=category) if form.is_valid(): category = form.save() return HttpResponseRedirect( reverse('knowledge_category_view', args=[category.treepath])) else: return HttpResponseRedirect( reverse('knowledge_category_view', args=[category.treepath])) else: form = KnowledgeCategoryForm(instance=category) context = _get_default_context(request) context.update({'form': form, 'category': category, 'items': items}) return render_to_response('knowledge/category_edit', context, context_instance=RequestContext(request), response_format=response_format)
def category_delete(request, knowledgeCategory_id, response_format='html'): "Knowledge Category delete" category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id) items = Object.filter_permitted( manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if not request.user.profile.has_permission(category, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Category") if request.POST: if 'delete' in request.POST: if 'trash' in request.POST: category.trash = True category.save() else: category.delete() return HttpResponseRedirect(reverse('knowledge_index')) elif 'cancel' in request.POST: return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath])) context = _get_default_context(request) context.update({'category': category, 'items': items}) return render_to_response('knowledge/category_delete', context, context_instance=RequestContext(request), response_format=response_format)
def __init__(self, user, *args, **kwargs): super(ItemTypeForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['parent'].label = _("Parent") self.fields['fields'].label = _("Fields") self.fields['details'].label = _("Details") self.fields['fields'].queryset = Object.filter_permitted( user, ItemField.objects.all(), mode='x') self.fields['fields'].help_text = '' self.fields['parent'].queryset = Object.filter_permitted(user, ItemType.objects.all().exclude( pk=self.instance.id), mode='x')
def category_edit(request, knowledgeCategory_id, response_format='html'): "Knowledge category edit page" category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id) items = Object.filter_permitted( manager=KnowledgeItem.objects, user=request.user.profile, mode='r') if not request.user.profile.has_permission(category, mode="w"): return user_denied(request, message="You don't have access to this Knowledge Category") if request.POST: if 'cancel' not in request.POST: form = KnowledgeCategoryForm(request.POST, instance=category) if form.is_valid(): category = form.save() return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath])) else: return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath])) else: form = KnowledgeCategoryForm(instance=category) context = _get_default_context(request) context.update({'form': form, 'category': category, 'items': items}) return render_to_response('knowledge/category_edit', context, context_instance=RequestContext(request), response_format=response_format)
def messaging_unread(context): "Print a number of unread messages" request = context['request'] user = None if request.user.username: try: user = request.user.profile except Exception: pass unread = 0 messaging = None if user: modules = user.get_perspective().get_modules() messaging = modules.filter(name='anaf.messaging') if messaging: unread = Object.filter_permitted(user, Message.objects.filter(reply_to__isnull=True).exclude(read_by=user)).count() response_format = 'html' if 'response_format' in context: response_format = context['response_format'] return Markup(render_to_string('messaging/tags/unread', {'messaging': messaging, 'unread': unread}, context_instance=RequestContext(request), response_format=response_format))
def __init__(self, user, *args, **kwargs): super(WidgetForm, self).__init__(*args, **kwargs) self.fields['perspective'].queryset = Object.filter_permitted( user, Perspective.objects) self.fields['perspective'].label = _("Perspective") self.fields['weight'].label = _("Weight")
def __init__(self, user, *args, **kwargs): super(ChangeSetForm, self).__init__(*args, **kwargs) self.user = None if user: self.user = user self.fields['name'].label = _("Name") self.fields['name'].widget.attrs.update({'size': 50}) self.fields['object'].label = _("Object") self.fields['object'] = ObjectModelChoiceField(label=_("Object"), queryset=Object.filter_permitted(user, Object.objects)) self.fields['object'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('core_ajax_object_lookup')}) if 'object_id' in kwargs: self.fields['parent'].initial = kwargs['object_id'] del kwargs['object_id'] try: conf = ModuleSetting.get_for_module( 'anaf.changes', 'default_changeset_status')[0] default_changeset_status = ChangeSetStatus.objects.get( pk=long(conf.value)) if not default_changeset_status.trash: self.fields['status'].initial = default_changeset_status.id except Exception: pass self.fields['status'].label = _("Status") self.fields['details'].label = _("Details")
def __init__(self, user, *args, **kwargs): super(LeadForm, self).__init__(*args, **kwargs) self.fields['contact'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['contact'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['contact'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['contact'].label = _("Contact") self.fields['source'].queryset = Object.filter_permitted( user, SaleSource.objects.filter(active=True)) self.fields['source'].label = _("Source") self.fields['products_interested'].queryset = Object.filter_permitted( user, Product.objects) self.fields['products_interested'].help_text = "" self.fields['products_interested'].widget.attrs.update( {'popuplink': reverse('sales_product_add')}) self.fields['products_interested'].label = _("Products interested") self.fields['assigned'].help_text = "" self.fields['assigned'].label = _("Assigned to") self.fields['assigned'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_user_lookup')}) try: conf = ModuleSetting.get_for_module( 'anaf.sales', 'default_order_product')[0] self.fields['products_interested'].initial = [long(conf.value)] except: pass self.fields['status'].queryset = Object.filter_permitted( user, SaleStatus.objects.filter(use_leads=True)) self.fields['status'].label = _("Status") try: conf = ModuleSetting.get_for_module( 'anaf.sales', 'default_lead_status')[0] self.fields['status'].initial = long(conf.value) except: pass self.fields['contact_method'].label = _("Contact method") self.fields['details'].label = _("Details")
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(FilterForm, self).__init__(*args, **kwargs) self.fields['caller'].label = _("Caller") if 'caller' in skip: del self.fields['caller'] else: self.fields['caller'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['caller'].required = False self.fields['caller'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['status'].label = _("Status") if 'status' in skip: del self.fields['status'] else: self.fields['status'].queryset = Object.filter_permitted( user, TaskStatus.objects, mode='x') self.fields['status'].required = False self.fields['assigned'].label = _("Assigned") self.fields['assigned'].widget.attrs.update({'class': 'multicomplete', 'callback': reverse('identities_ajax_user_lookup')}) if 'assigned' in skip: del self.fields['assigned'] else: self.fields['assigned'].help_text = "" self.fields['project'].label = _("Project") if 'project' in skip: del self.fields['project'] else: self.fields['project'].queryset = Object.filter_permitted( user, Project.objects, mode='x') self.fields['project'].required = False self.fields['milestone'].label = _("Milestone") if 'milestone' in skip: del self.fields['milestone'] else: self.fields['milestone'].queryset = Object.filter_permitted( user, Milestone.objects, mode='x')
def __init__(self, user, *args, **kwargs): "Sets allowed values" super(ServiceLevelAgreementForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['response_time'].help_text = 'minutes' self.fields['response_time'].widget.attrs.update({'size': 10}) self.fields['response_time'].label = _("Response time") self.fields['uptime_rate'].help_text = 'percent' self.fields['uptime_rate'].widget.attrs.update({'size': 5}) self.fields['uptime_rate'].label = _("Uptime rate") self.fields['service'].queryset = Object.filter_permitted( user, Service.objects, mode='x') self.fields['service'].label = _("Service") self.fields['client'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['client'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['client'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['client'].label = _("Client") self.fields['provider'].queryset = Object.filter_permitted( user, Contact.objects, mode='x') self.fields['provider'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['provider'].widget.attrs.update( {'popuplink': reverse('identities_contact_add')}) self.fields['provider'].label = _("Provider") self.fields['available_from'].initial = "09:00" self.fields['available_from'].widget.attrs.update({'size': 10}) self.fields['available_from'].label = _("Available from") self.fields['available_to'].initial = "18:00" self.fields['available_to'].widget.attrs.update({'size': 10}) self.fields['available_to'].label = _("Available to") contact = user.default_group.get_contact() if contact: self.fields['provider'].initial = contact.id
def __init__(self, user, *args, **kwargs): "Sets choices and initial value" super(SettingsForm, self).__init__(*args, **kwargs) self.fields['my_company'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['my_company'].widget.attrs.update({ 'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup') }) self.fields['default_account'].queryset = Object.filter_permitted( user, Account.objects) # Translation self.fields['default_currency'].label = _('Base Currency') self.fields['my_company'].label = _('My Company') self.fields['default_account'].label = _('Default Account') try: self.fields['default_currency'].widget.attrs.update( {'popuplink': reverse('finance_currency_add')}) self.fields['default_currency'].queryset = Currency.objects.all() self.fields['default_currency'].initial = Currency.objects.get( is_default=True) except Exception: pass try: conf = ModuleSetting.get_for_module('anaf.finance', 'my_company')[0] my_company = Contact.objects.get(pk=long(conf.value)) self.fields['my_company'].initial = my_company.id except Exception: pass try: conf = ModuleSetting.get_for_module('anaf.finance', 'default_account')[0] default_account = Account.objects.get(pk=long(conf.value)) self.fields['default_account'].initial = default_account.id except Exception: pass
def __init__(self, user, folder_id, *args, **kwargs): super(FolderForm, self).__init__(*args, **kwargs) self.fields['name'].label = _("Name") self.fields['parent'].label = _("Parent") self.fields['parent'].queryset = Object.filter_permitted( user, Folder.objects, mode='x') if folder_id: self.fields['parent'].initial = folder_id
def __init__(self, user, *args, **kwargs): if 'instance' in kwargs: self.instance = kwargs['instance'] del kwargs['instance'] super(MassActionForm, self).__init__(*args, **kwargs) self.fields['status'].queryset = Object.filter_permitted( user, ItemStatus.objects, mode='x') self.fields['location'].queryset = Object.filter_permitted( user, Location.objects, mode='x') self.fields['status'].label = _('Status') self.fields['location'].label = _('Location') self.fields['delete'] = forms.ChoiceField(label=_("Delete"), choices=(('', '-----'), ('delete', _( 'Delete Completely')), ('trash', _('Move to Trash'))), required=False)
def __init__(self, user=None, date=None, hour=None, *args, **kwargs): super(EventForm, self).__init__(*args, **kwargs) self.fields['name'].label = _('Title') self.fields['name'].widget = forms.TextInput(attrs={'size': '30'}) self.fields['location'].queryset = Object.filter_permitted( user, Location.objects, mode='x') self.fields['location'].widget.attrs.update( {'popuplink': reverse('identities_location_add')}) self.fields['location'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_location_lookup')}) self.fields['location'].label = _("Location") self.fields['start'].label = _("Start") self.fields['end'].label = _("End") self.fields['details'].label = _("Details") self.fields['details'].widget.attrs.update({'class': 'full-editor'}) if date: rdate = None try: rdate = datetime.datetime.strptime(date, "%Y-%m-%d") if hour: hour = int(hour) else: hour = 12 rdate = datetime.datetime(year=rdate.year, month=rdate.month, day=rdate.day, hour=hour) self.fields['end'].initial = rdate except ValueError: pass # Set datepicker self.fields['start'].widget.attrs.update({'class': 'datetimepicker'}) self.fields['end'].widget.attrs.update({'class': 'datetimepicker'}) if self.fields['start'].initial: self.fields['start'].widget.attrs.update( {'initial': (self.fields['start'].initial - datetime.datetime(1970, 1, 1)).total_seconds()}) if self.fields['end'].initial: self.fields['end'].widget.attrs.update( {'initial': (self.fields['end'].initial - datetime.datetime(1970, 1, 1)).total_seconds()}) if 'instance' in kwargs: instance = kwargs['instance'] if instance.start: self.fields['start'].widget.attrs.update( {'initial': (instance.start - datetime.datetime(1970, 1, 1)).total_seconds()}) if instance.end: self.fields['end'].widget.attrs.update( {'initial': (instance.end - datetime.datetime(1970, 1, 1)).total_seconds()})
def __init__(self, user, skip=None, *args, **kwargs): if skip is None: skip = [] super(ProductFilterForm, self).__init__(*args, **kwargs) self.fields['product_type'].queryset = Object.filter_permitted(user, Product.objects.filter(active=True)) self.fields['product_type'].required = False self.fields['product_type'].label = _("Product type") self.fields['supplier'].queryset = Object.filter_permitted( user, Contact.objects) self.fields['supplier'].required = False self.fields['supplier'].widget.attrs.update({'class': 'autocomplete', 'callback': reverse('identities_ajax_contact_lookup')}) self.fields['supplier'].label = _("Supplier") self.fields['active'].required = False self.fields['active'].initial = True self.fields['active'].label = _("Active")