Пример #1
0
def status(request):
    ipaddr = request.META.get('REMOTE_ADDR', '')
    if request.method == 'POST':
        _content = request.POST.get('content', '')
        if not checkIP(ipaddr):
            messages.error(request, 'IP_NOT_VALID')
        elif not (len(_content) < 120 and len(_content) > 1):
            messages.error(request, u'字数超出限制,请精简')
        elif ContentModel.objects.filter(ip=ipaddr, time__range=\
                (datetime.datetime.now() - datetime.timedelta(minutes=5), datetime.datetime.now())).count() > 0:
            messages.error(request, u'你刚刚发过,请稍后')
        else:
            new_content = ContentModel(ip=ipaddr, 
                    time=datetime.datetime.now())
            new_content.save()
            try:
                #postStatu(_content, ContentModel.objects.count())
                _content = _content + u"(发送自 http://bithelper.sinaapp.com/status/ )"
                renren.renren_status(_content)
            except RuntimeError:
                messages.error(request, u'出错了,请稍后再试')
                logging.error('Error in ' + str(ContentModel.objects.count()))
            else:
                messages.success(request, u'状态发送成功')
    return render_to_response('status.html', 
            context_instance=RequestContext(request))
Пример #2
0
def index(request):
    template = loader.get_template('treeholeapp/index.html')
    ipaddr = request.META.get('REMOTE_ADDR', '')
    if request.method == 'POST':
        _content = request.POST.get('content', '')
        if not checkIP(ipaddr):
            messages.error(request, MSG['IP_NOT_VALID'])
        elif not (len(_content) < 120 and len(_content) > 5):
            messages.error(request, MSG['CONTENT_TOO_LONG'])
#        elif ContentModel.objects.filter(ip=ipaddr, time__range=\
#                (datetime.now()-timedelta(minutes=30), datetime.now())).count() > 0:
#            messages.error(request, MSG['TOO_MANY_TIMES'])
        else:
            new_content = ContentModel(ip=ipaddr, 
                    time=datetime.now(),
		contentstr=_content)
            new_content.save()
            try:
                pass;
                #postStatus(_content, ContentModel.objects.count())
            except RuntimeError:
                messages.error(request, MSG['PUBLISH_ERROR'])
                logging.error('Error in ' + str(ContentModel.objects.count()))
            else:
                messages.success(request, MSG['PUBLISH_OK']);
		return HttpResponseRedirect(reverse('treeholeapp:result'));
#		return HttpResponseRedirect("result.html");

    return render_to_response('treeholeapp/index.html', \
          # {'messages':messages}, \
            context_instance=RequestContext(request))
Пример #3
0
    def delete(self, content_id):
        post = ContentModel.find_by_id(content_id)
        current_user = get_jwt_identity()

        if current_user == post.user_id:
            return ContentModel.delete_one(content_id, post)
        else:
            return {'message': 'This is not your data!'}
	def addHandler(self, request):
		model = ContentModel()
		model.title = request.form['title']
		model.content = request.form['content']

		try:
			model.put()
			return redirect('/admin')
		except Exception, e:
			return e
Пример #5
0
    def post(self):
        data = parser.parse_args()
        current_user = get_jwt_identity()

        new_post = ContentModel(text=data['text'], user_id=current_user)
        try:
            new_post.save_to_db()
            return {'message': 'Post was created'}
        except:
            return {'message': 'Something went wrong'}, 500
Пример #6
0
    def put(self, content_id):
        data = parser.parse_args()

        post = ContentModel.find_by_id(content_id)
        current_user = get_jwt_identity()

        if current_user == post.user_id:
            return ContentModel.edit_content(data, content_id, post)
        else:
            return {'message': 'This is not your data!'}
	def deleteHandler(self, request, id):
		model = ContentModel.get_by_id(id)
		if model:
			try:
				model.delete()
			except:
				return e
		return redirect('/admin')
	def showHandler(self, request, id):
		if 'X-Requested-With' in request.headers:
			entry = ContentModel.get_by_id(id)
			if entry:
				data = {'id':entry.key().id(), 'title':entry.title, 'content':entry.content}
				data = json.dumps(data)
			else:
				data = json.dumps({'id':0,'title':'not found', 'content':'not found'})
			return Response(data,mimetype="application/json")
		else:
			return self.indexHandler(request)	
	def adminHandler(self, request):
		dbs = ContentModel.all().fetch(limit=5)
		contents = []
		for entry in dbs:
			contents.append({'id':entry.key().id(), 'title':entry.title, 'content':entry.content})
		return self.renderTemplate('admin.html', contents=contents)
Пример #10
0
	def indexHandler(self, request):
		mds = ContentModel.all().fetch(limit=5)
		entries = [{'id': ent.key().id()} for ent in mds]

		return self.renderTemplate('index.html', entries=entries)
Пример #11
0
 def get(self, content_id):
     return ContentModel.return_one(content_id)
Пример #12
0
 def delete(self):
     return ContentModel.delete_all()
Пример #13
0
 def get(self):
     return ContentModel.return_all()