Python django.utils.translation.ugettext_lazy() Examples
The following are 30
code examples of django.utils.translation.ugettext_lazy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.translation
, or try the search function
.
Example #1
Source File: customer.py From Servo with BSD 2-Clause "Simplified" License | 8 votes |
def clean(self): cd = super(CustomerForm, self).clean() phone = cd.get('phone') country = cd.get('country') if len(phone) < 1: return cd try: phonenumbers.parse(phone, country) except phonenumbers.NumberParseException: msg = _('Enter a valid phone number') self._errors["phone"] = self.error_class([msg]) return cd
Example #2
Source File: mixins.py From openwisp-users with BSD 3-Clause "New" or "Revised" License | 7 votes |
def _validate_org_relation(self, rel, field_error='organization'): """ if the relation is owned by a specific organization this object must be related to the same organization """ # avoid exceptions caused by the relation not being set if not hasattr(self, rel): return rel = getattr(self, rel) if ( rel and rel.organization_id and str(self.organization_id) != str(rel.organization_id) ): message = _( 'Please ensure that the organization of this {object_label} ' 'and the organization of the related {related_object_label} match.' ) message = message.format( object_label=self._meta.verbose_name, related_object_label=rel._meta.verbose_name, ) raise ValidationError({field_error: message})
Example #3
Source File: account.py From Servo with BSD 2-Clause "Simplified" License | 7 votes |
def activate_locale(self): """ Activates this user's locale """ try: lc = self.locale.split('.') region = self.region.split('.') locale.setlocale(locale.LC_TIME, region) locale.setlocale(locale.LC_MESSAGES, lc) locale.setlocale(locale.LC_NUMERIC, region) locale.setlocale(locale.LC_MONETARY, region) except Exception as e: locale.setlocale(locale.LC_ALL, None) # Return the language code return self.locale.split('_', 1)[0]
Example #4
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def save(self, *args, **kwargs): location = self.created_by.location if self.location_id is None: self.location = location if self.checkin_location is None: self.checkin_location = location if self.checkout_location is None: self.checkout_location = location if self.customer and self.customer_name == '': self.customer_name = self.customer.fullname super(Order, self).save(*args, **kwargs) if self.code is None: self.url_code = encode_url(self.id).upper() self.code = settings.INSTALL_ID + str(self.id).rjust(6, '0') event = _('Order %s created') % self.code self.notify('created', event, self.created_by) self.save()
Example #5
Source File: parts.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def update_sn(self): # CTS parts not eligible for SN update if self.return_status == 'Convert To Stock': return if not self.repair.confirmation: raise ValueError(_('GSX repair has no dispatch ID')) product = self.order_item.product if not product.is_serialized: return if product.part_type == "MODULE": self.update_module_sn() elif product.part_type == "REPLACEMENT": self.update_replacement_sn()
Example #6
Source File: repair.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def create_from_gsx(cls, confirmation, order, device, user): """Creates a new Repair for order with confirmation number.""" try: repair = cls.objects.get(confirmation=confirmation) msg = {'repair': repair.confirmation, 'order': repair.order} raise ValueError(_('Repair %(repair)s already exists for order %(order)s') % msg) except cls.DoesNotExist: pass repair = cls(order=order, created_by=user) repair.device = device repair.confirmation = confirmation repair.gsx_account = GsxAccount.default(user, order.queue) repair.submitted_at = timezone.now() # RepairDetails doesn't have this! repair.save() try: repair.get_details() repair.update_status(user) except gsxws.GsxError as e: if e.code == 'RPR.LKP.01': # repair not found repair.delete() raise ValueError(_('Repair %s not found in GSX') % confirmation) return repair
Example #7
Source File: purchases.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def trigger_purchase_order_created(sender, instance, created, **kwargs): sales_order = instance.sales_order if sales_order is None: return if not sales_order.is_editable: return if created: msg = _("Purchase Order %d created") % instance.id sales_order.notify("po_created", msg, instance.created_by) # Trigger status change for GSX repair submit (if defined) if instance.submitted_at: if sales_order.queue: queue = sales_order.queue if queue.status_products_ordered: # Queue has a status for product_ordered - trigger it new_status = queue.status_products_ordered sales_order.set_status(new_status, instance.created_by)
Example #8
Source File: widgets.py From django-places with MIT License | 6 votes |
def __init__(self, attrs=None): _widgets = ( widgets.TextInput( attrs={'data-geo': 'formatted_address', 'data-id': 'map_place'} ), widgets.TextInput( attrs={ 'data-geo': 'lat', 'data-id': 'map_latitude', 'placeholder': _('Latitude'), } ), widgets.TextInput( attrs={ 'data-geo': 'lng', 'data-id': 'map_longitude', 'placeholder': _('Longitude'), } ), ) super(PlacesWidget, self).__init__(_widgets, attrs)
Example #9
Source File: note.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def send_sms_builtin(self, recipient, sender=None): """ Sends SMS through built-in gateway """ if not settings.SMS_HTTP_URL: raise ValueError(_('System is not configured for built-in SMS support.')) if sender is None: location = self.created_by.location sender = location.title data = urllib.urlencode({ 'username' : settings.SMS_HTTP_USERNAME, 'password' : settings.SMS_HTTP_PASSWORD, 'numberto' : recipient.replace(' ', ''), 'numberfrom': sender.encode(SMS_ENCODING), 'message' : self.body.encode(SMS_ENCODING), }) from ssl import _create_unverified_context f = urllib.urlopen(settings.SMS_HTTP_URL, data, context=_create_unverified_context()) return f.read()
Example #10
Source File: notes.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def __init__(self, *args, **kwargs): super(NoteForm, self).__init__(*args, **kwargs) note = kwargs['instance'] self.fields['sender'] = forms.ChoiceField( label=_('From'), choices=note.get_sender_choices(), widget=forms.Select(attrs={'class': 'span12'}) ) self.fields['body'].widget = AutocompleteTextarea( rows=20, choices=Template.templates() ) if note.order: url = reverse('notes-render_template', args=[note.order.pk]) self.fields['body'].widget.attrs['data-url'] = url
Example #11
Source File: checkin.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def __init__(self, *args, **kwargs): super(DeviceForm, self).__init__(*args, **kwargs) if Configuration.false('checkin_require_password'): self.fields['password'].required = False if Configuration.true('checkin_require_condition'): self.fields['condition'].required = True if kwargs.get('instance'): prod = gsxws.Product('') prod.description = self.instance.description if prod.is_ios: self.fields['password'].label = _('Passcode') if not prod.is_ios: del(self.fields['imei']) if not prod.is_mac: del(self.fields['username']) if Configuration.true('checkin_password'): self.fields['password'].widget = forms.TextInput(attrs={'class': 'span12'})
Example #12
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def get_print_dict(self, kind='confirmation'): """ Return context dict for printing this order """ r = {} r['order'] = self r['conf'] = Configuration.conf() r['title'] = _(u"Service Order #%s") % self.code r['notes'] = self.note_set.filter(is_reported=True) if kind == 'receipt': try: # Include the latest invoice data for receipts r['invoice'] = self.invoice_set.latest() except Exception as e: pass return r
Example #13
Source File: product.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def sell(self, amount, location): """ Deduct product from inventory with specified location """ if not self.track_inventory(): return try: inventory = Inventory.objects.get(product=self, location=location) try: inventory.amount_stocked = inventory.amount_stocked - amount inventory.amount_reserved = inventory.amount_reserved - amount except Exception as e: # @TODO: Would be nice to trigger a warning pass inventory.save() except Inventory.DoesNotExist: raise ValueError(_(u"Product %s not found in inventory.") % self.code)
Example #14
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def add_product(self, product, amount, user): """ Adds this product to the Service Order with stock price """ oi = ServiceOrderItem(order=self, created_by=user) oi.product = product oi.code = product.code oi.title = product.title oi.description = product.description oi.amount = amount oi.price_category = 'stock' oi.price = product.price_sales_stock oi.save() self.notify("product_added", _('Product %s added') % oi.title, user) return oi
Example #15
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def set_location(self, new_location, user): """ Moves order to new location """ # move the products too for soi in self.serviceorderitem_set.all(): product = soi.product try: source = Inventory.objects.get(location=self.location, product=product) source.move(new_location, soi.amount) except Inventory.DoesNotExist: pass # @TODO: Is this OK? self.location = new_location msg = _(u"Order %s moved to %s") % (self.code, new_location.title) self.notify("set_location", msg, user) self.save() return msg
Example #16
Source File: email.py From djreservation with GNU General Public License v3.0 | 5 votes |
def send_html_email(subject, template, context=None): if context is None: context = {} reservation = context['reservation'] message = render_to_string(template, context) send_mail( subject=subject, message=_('Please, use an email with html support'), from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=[reservation.user.email], fail_silently=True, html_message=message )
Example #17
Source File: note.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_read_title(self): return _("As Unread") if self.is_read else _("As Read")
Example #18
Source File: note.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_reported_title(self): return _("As Unreported") if self.is_reported else _("As Reported")
Example #19
Source File: routes.py From puput with MIT License | 5 votes |
def entries_search(self, request, *args, **kwargs): search_query = request.GET.get('q', None) self.entries = self.get_entries() if search_query: self.entries = self.entries.search(search_query) self.search_term = search_query self.search_type = _('search') Query.get(search_query).add_hit() return Page.serve(self, request, *args, **kwargs)
Example #20
Source File: email.py From djreservation with GNU General Public License v3.0 | 5 votes |
def email_requested(reservation, user): send_html_email( _('Reservation requested: reserv-%d') % (reservation.pk), 'djreservation/mail/requested.txt', context={ 'reservation': reservation, 'user': user })
Example #21
Source File: note.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def get_flagged_title(self, user): if user.pk in self.flagged_by: return _('Mark as unflagged') return _('Mark as flagged')
Example #22
Source File: note.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def validate_phone_number(number): match = re.match(r'([\+\d]+$)', number) if match: return match.group(1).strip() else: raise ValidationError(_(u'%s is not a valid phone number') % number)
Example #23
Source File: purchases.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def trigger_product_received(sender, instance, created, **kwargs): if instance.received_at is None: return product = instance.product po = instance.purchase_order location = po.created_by.get_location() inventory = Inventory.objects.get_or_create(location=location, product=product)[0] # Receiving an incoming item if Configuration.track_inventory(): try: inventory.amount_ordered -= instance.amount inventory.amount_stocked += instance.amount inventory.save() except Exception: ref = po.reference or po.confirmation ed = {'prod': product.code, 'ref': ref} raise ValueError(_('Cannot receive item %(prod)s (%(ref)s)') % ed) sales_order = instance.purchase_order.sales_order if sales_order is None: return # Trigger status change for parts receive if sales_order.queue: new_status = sales_order.queue.status_products_received if new_status and sales_order.is_editable: user = instance.received_by or instance.created_by sales_order.set_status(new_status, user)
Example #24
Source File: purchases.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def receive(self, user): if self.received_at is not None: raise ValueError(_("Product has already been received")) self.received_at = timezone.now() self.received_by = user self.save()
Example #25
Source File: purchases.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def delete(self, *args, **kwargs): if self.submitted_at: raise ValueError(_('Submitted orders cannot be deleted')) return super(PurchaseOrder, self).delete(*args, **kwargs)
Example #26
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def remove_product(self, oi, user): oi.delete() msg = _('Product %s removed from order') % oi.title self.notify("product_removed", msg, user) return msg
Example #27
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def set_user(self, new_user, current_user): """ Sets the assignee of this order to new_user """ if self.state == self.STATE_CLOSED: raise ValueError(_('Closed orders cannot be modified')) state = self.STATE_OPEN if new_user is None: state = self.STATE_QUEUED event = _("Order unassigned") self.remove_follower(self.user) else: data = {'order': self.code, 'user': new_user.get_full_name()} event = _(u"Order %(order)s assigned to %(user)s") % data # The assignee should also be a follower self.add_follower(new_user) self.user = new_user self.state = state self.notify("set_user", event, current_user) if self.user is not None: self.location = new_user.location if self.started_by is None: self.started_by = new_user self.started_at = timezone.now() queue = self.queue if queue and queue.status_assigned: self.set_status(queue.status_assigned, current_user) self.save()
Example #28
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def remove_follower(self, follower): if self.state == self.STATE_CLOSED: raise ValueError(_('Closed orders cannot be modified')) self.followed_by.remove(follower)
Example #29
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def unset_status(self, user): if self.is_closed: return # fail silently self.status = None self.status_started_at = None self.status_limit_green = None self.status_limit_yellow = None self.save() self.notify("set_status", _('Status unassigned'), user)
Example #30
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def set_status(self, new_status, user): """ Sets status of this order to new_status Status can only be set if order belongs to a queue! """ if self.is_closed: return # fail silently if self.queue is None: raise ValueError(_('Order must belong to a queue to set status')) if isinstance(new_status, QueueStatus): status = new_status else: if int(new_status) == 0: return self.unset_status(user) status = QueueStatus.objects.get(pk=new_status) self.status = status self.status_name = status.status.title self.status_started_at = timezone.now() self.status_limit_green = status.get_green_limit() self.status_limit_yellow = status.get_yellow_limit() self.save() # Set up the OrderStatus OrderStatus.create(self, status, user) # trigger the notification self.notify("set_status", self.status_name, user)