def postStatu(text, ipaddr='127.0.0.1'): """ Post status, start with '#xxx', saving to db""" new_content = ContentModel(ip=ipaddr, time=datetime.now(), content=text) new_content.save() number = ContentModel.objects.count() text = '#' + str(number) + ' ' + text postRawStatu(text)
def postStatu(text, ipaddr=''): """ Post status, start with '#xxx', saving to db""" new_content = ContentModel(ip=ipaddr, time=datetime.now(), content=text) new_content.save() number = ContentModel.objects.count() text = '#' + str(number) + ' ' + text postRawStatu(text)
def postRenrenStatu(text): """ Post status, start with '#xxx', saving to db""" timenow = datetime.now() new_content = ContentModel(ip='127.0.0.1', time=timenow, content=text) new_content.save() number = ContentModel.objects.count() text = text + ' ----#' + str(number) + ' post'# + ', at ' + str(timenow) postRawStatu(text)
def index(req): ipaddr = req.META.get("REMOTE_ADDR", "") if req.method == "POST": _content = req.POST.get("content", "") if not checkIP(ipaddr): messages.error(req, MSG["IP_NOT_VALID"]) elif not (len(_content) < 120 and len(_content) > 5): messages.error(req, MSG["CONTENT_TOO_LONG"]) elif ( ContentModel.objects.filter( ip=ipaddr, time__range=(datetime.now() - timedelta(minutes=30), datetime.now()) ).count() > 0 ): messages.error(req, MSG["TOO_MANY_TIMES"]) else: new_content = ContentModel(ip=ipaddr, time=datetime.now(), content=_content) new_content.save() try: postStatu(_content, ContentModel.objects.count()) except RuntimeError: messages.error(req, MSG["PUBLISH_ERROR"]) logging.error("Error in " + str(ContentModel.objects.count())) else: messages.success(req, MSG["PUBLISH_OK"]) # for doreamon icon try: icon = int(req.path[1:]) except ValueError: icon = 0 tourl = "" if icon == 0 or req.session.get("redirect", 0) == 0: req.session["redirect"] = 1 tourl = "/" + str(random.randint(1, 16)) else: req.session["redirect"] = 0 isIphone = "iPhone" in req.META.get("HTTP_USER_AGENT", "") and req.method == "GET" return render_to_response( "index.html", {"ICO_NUM": icon, "TOURL": tourl, "ISIPHONE": isIphone, "LINKS": LINKS}, context_instance=RequestContext(req), )
def index(req): ipaddr = req.META.get('REMOTE_ADDR', '') if req.method == 'POST': _content = req.POST.get('content', '') if not checkIP(ipaddr): messages.error(req, MSG['IP_NOT_VALID']) elif not (len(_content) < 120 and len(_content) > 5): messages.error(req, MSG['CONTENT_TOO_LONG']) elif ContentModel.objects.filter(ip=ipaddr, time__range=\ (datetime.now()-timedelta(minutes=30), datetime.now())).count() > 0: messages.error(req, MSG['TOO_MANY_TIMES']) else: new_content = ContentModel(ip=ipaddr, time=datetime.now(), content=_content) new_content.save() try: postStatu(_content, ContentModel.objects.count()) except RuntimeError: messages.error(req, MSG['PUBLISH_ERROR']) logging.error('Error in ' + str(ContentModel.objects.count())) else: messages.success(req, MSG['PUBLISH_OK']) # for doreamon icon try: icon = int(req.path[1:]) except ValueError: icon = 0 tourl = '' if icon == 0 or req.session.get('redirect', 0) == 0: req.session['redirect'] = 1 tourl = '/' + str(random.randint(1, 16)) else: req.session['redirect'] = 0 isIphone = ('iPhone' in req.META.get('HTTP_USER_AGENT', '') and req.method == 'GET') return render_to_response('index.html', \ {'ICO_NUM': icon, 'TOURL': tourl, 'ISIPHONE': isIphone, 'LINKS': LINKS, 'PLACEHOLER': PlaceholderModel.objects.order_by('?')[0].content }, context_instance=RequestContext(req))
def index(req): ipaddr = req.META.get('REMOTE_ADDR', '') if req.method == 'POST': _content = req.POST.get('content', '') if not checkIP(ipaddr): messages.error(req, MSG['IP_NOT_VALID']) elif not (len(_content) < 120 and len(_content) > 5): messages.error(req, MSG['CONTENT_TOO_LONG']) elif ContentModel.objects.filter(ip=ipaddr, time__range=\ (datetime.now()-timedelta(minutes=30), datetime.now())).count() > 0: messages.error(req, MSG['TOO_MANY_TIMES']) else: new_content = ContentModel(ip=ipaddr, time=datetime.now(), content=_content) new_content.save() try: postStatu(_content, ContentModel.objects.count()) except RuntimeError: messages.error(req, MSG['PUBLISH_ERROR']) logging.error('Error in ' + str(ContentModel.objects.count())) else: messages.success(req, MSG['PUBLISH_OK']) # for doreamon icon try: icon = int(req.path[1:]) except ValueError: icon = 0 tourl = '' if icon == 0 or req.session.get('redirect', 0) == 0: req.session['redirect'] = 1 tourl = '/' + str(random.randint(1, 16)) else: req.session['redirect'] = 0 isIphone = ('iPhone' in req.META.get('HTTP_USER_AGENT', '') and req.method == 'GET') return render_to_response('index.html', \ {'ICO_NUM': icon, 'TOURL': tourl, 'ISIPHONE': isIphone, 'LINKS': LINKS}, context_instance=RequestContext(req))