def __init__(self, *args, **kwargs): self.request = get_request() if self.request.POST: super(BaseForm, self).__init__(self.request.POST, *args, **kwargs) else: super(BaseForm, self).__init__(*args, **kwargs) if 'photo' in self.fields: del self.fields['photo'] self.fields['publish'].choices = publish_choices()
def allowed(self): request = get_request() return self.publish or get_request().user == self.user or self.publish is None
def before_save(self, is_insert=True): self.is_insert = is_insert self.updated = datetime.now() if is_insert: self.user = get_request().user
def geo_pos(form): request = get_request() return hasattr(form.instance, 'geo_pos') and form.instance.geo_pos or \ (hasattr(request, 'POST') and 'geo_pos' in request.POST and \ request.POST['geo_pos']) or \ ', '.join(map(lambda x: str(x), DEFAULT_LOCATION))
def tr(kalimat, request=None): request = request or get_request() to = request.session.get('lang', 'id') return translate(kalimat, to=to)
def tr(kalimat, request=None): request = request or get_request() to = request.session.get('lang','id') return translate(kalimat, to=to)
def save(self, *args, **kwargs): request = get_request() self.instance.category = request.POST.getlist('category') super(LivelihoodForm, self).save(*args, **kwargs)
def t_(text, request=None): request = request or get_request() return html2text(translate(text, to=request.session.get('lang', 'id')))
def t_(text, request=None): request = request or get_request() return html2text(translate(text, to=request.session.get('lang','id')))
def allowed(self): request = get_request() return self.publish or get_request( ).user == self.user or self.publish is None