def nepali(value): ''' try to convert text to nepali ''' if value is not None: if value.__class__ == datetime.date: return no_to_np(to_bs(value.isoformat())) config = Globals() raw_value = value value = value.lower().replace(" ", "_") out_val = "" for _ in value: if _ in string.ascii_lowercase + string.ascii_uppercase or _ == "_": out_val += _ while len(out_val) > 1 and out_val[ 0] not in string.ascii_lowercase + string.ascii_uppercase + "".join( [unicode(_) for _ in range(0, 10)]): out_val = out_val[1:] text = config.text.get(out_val, None) if text is not None: # found the text correspondent return text else: values = raw_value.split(" ") out_val = [] for _ in values: _ = "".join([ char for char in _ if char in string.ascii_lowercase + string.ascii_uppercase + "".join([unicode(int) for int in range(0, 10)]) or _ == " " ]) config_val = config.text.get(_, None) if config_val is None: config_val = config.text.get(_.lower(), None) if config_val is None: out_val.append(_) else: out_val.append(config_val) else: out_val.append(config_val) return " ".join(out_val) else: return ""
from __future__ import unicode_literals from django import template from settings.models import Globals from pyBSDate.BSDate import convert_to_bs from settings.templatetags.nepali import nepali import datetime register = template.Library() NONE_LS = [None, "None"] config = Globals() @register.filter(name="tobs") def to_bs(value): if value.__class__ not in [unicode, str] and value is not None: try: if value.__class__ is datetime.datetime: value = value.date() value = value.isoformat() except: raise TypeError("value doesn't have isoformat method") elif value.__class__ is datetime.datetime: to_bs(value.date()) elif value is None: return ""
def home(request): config = Globals() context = {'config': config} if request.method == "POST": settings = request.POST org_long_name = settings.get("org_long_name", None) org_short_name = settings.get("org_short_name", None) org_motto = settings.get("org_motto", None) late_fees_price = settings.get("late_fees_price", None) max_books_borrow_days = settings.get("max_books_borrow_days", None) membership_valid_days = settings.get("membership_valid_days", None) config = Globals() if org_long_name is not None: config.add("alms", "org_long_name", org_long_name) if org_short_name is not None: config.add("alms", "org_short_name", org_short_name) if org_motto is not None: config.add("alms", "org_motto", org_motto) if late_fees_price is not None: config.add("misc", "late_fees_price", late_fees_price) if max_books_borrow_days is not None: config.add("books", "borrow_max_days", max_books_borrow_days) if membership_valid_days is not None: config.add("misc", "membership_valid_days", membership_valid_days) return HttpResponseRedirect(reverse("settingsHome")) return render(request, "settings/home.html", addGlobalContext(context))