Ejemplo n.º 1
0
def unsubscribe(site_id):
    if not _login.current_user.is_authenticated():
        # redirect to login
        return unauthorize_response
    if FeedSite.delete_site(site_id):
        return ajax_response(success=True)
    return ajax_response(success=False)
Ejemplo n.º 2
0
def subscribe():
    if not _login.current_user.is_authenticated():
        # redirect to login
        return unauthorize_response
    url = request.form['site']
    #print request.get_json(force=True)
    print url
    try:
        FeedSite.create_site(url)
        return ajax_response(success=True)
    except:
        return ajax_response(success=False)
Ejemplo n.º 3
0
def login(request):
	from django.contrib.auth import authenticate, login
	username = request.POST['username']
	password = request.POST['password']
	user = authenticate(username=username, password=password)
	if user is not None:
		if user.is_active:
			login(request, user)
			return ajax_response(request, "success", "login success")
		else:
			return ajax_response(request, "error", "account disabled")
	else:
		return ajax_response(request, "error", "invalid username and password")
Ejemplo n.º 4
0
def login(request):
    from django.contrib.auth import authenticate, login
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            return ajax_response(request, "success", "login success")
        else:
            return ajax_response(request, "error", "account disabled")
    else:
        return ajax_response(request, "error", "invalid username and password")
Ejemplo n.º 5
0
def delete_comment(comment_id):
    u = current_user()
    c = WeiboComment.query.get(comment_id)
    is_auth, message = c.is_auth(u)
    if is_auth:
        c.delete()
    return ajax_response(is_auth, data=c.json(), message=message)
Ejemplo n.º 6
0
def delete_weibo(weibo_id):
    u = current_user()
    w = Weibo.query.get(weibo_id)
    is_auth, message = w.is_auth(u)
    if is_auth:
        w.delete()
    return ajax_response(is_auth, data=w.json(), message=message)
Ejemplo n.º 7
0
def update_weibo(weibo_id):
    u = current_user()
    w = Weibo.query.get(weibo_id)
    form = request.form
    is_auth, message = w.is_auth(u)
    if is_auth:
        w.body = form.body
        w.save()
    return ajax_response(is_auth, data=w.json(), message=message)
Ejemplo n.º 8
0
def add_weibo():
    u = current_user()
    form = request.form
    w = Weibo(form)
    valid, message = w.valid()
    if valid:
        w.author_id = u.id
        w.save()
    return ajax_response(valid=valid, data=w.json(), message=message)
Ejemplo n.º 9
0
def register():
    form = request.form
    u = Model(form)
    valid, message = u.valid()
    json = u.json()
    if valid:
        u.save()
        session['uid'] = u.id
        safe_redirect_ajax(form, json)
    return ajax_response(valid=valid, data=json, message=message)
Ejemplo n.º 10
0
def update_comment(comment_id):
    u = current_user()
    form = request.form
    c = WeiboComment.query.get(comment_id)
    is_auth, message = c.is_auth(u)
    if is_auth:
        c.body = form.get('body','')
        c.update_time = datetime.utcnow()
        c.save()
    return ajax_response(is_auth, data=c.json(), message=message)
Ejemplo n.º 11
0
def add_comment():
    u = current_user()
    form = request.form
    c = WeiboComment(form)
    valid, message = c.valid()
    if valid:
        c.weibo_id = int(form.get('weibo_id', -1))
        c.author_id = u.id
        c.save()
    return ajax_response(True, data=c.json(), message=message)
Ejemplo n.º 12
0
def login():
    form = request.form
    u = User(form)
    user = Model.query.filter_by(username=u.username).first()
    valid, message = u.valid_login(user)
    json = u.json()
    if valid:
        session['uid'] = user.id
        safe_redirect_ajax(form, json)
    return ajax_response(valid=valid, data=json, message=message)
Ejemplo n.º 13
0
def load_article(page):
    if not _login.current_user.is_authenticated():
        # redirect to login
        return unauthorize_response
    if page >= 1:
        articles = Article.query.order_by(desc(Article.updated)).offset(
                current_app.config['DEFAULT_ARTICLE_SHOW_NUM'] - 1).from_self(
                       ).paginate(page=page, per_page=current_app.config['PER_PAGE_ARTICLE_NUM']).items
        print len(articles)
        articles_info = []
        for item in articles:
            _dict = {'name': item.title, 'id': item.id, 'site': item.site.title}
            articles_info.append(_dict)
        if len(articles_info) < current_app.config['PER_PAGE_ARTICLE_NUM']:
            last_page = True
        else:
            last_page = False;
        return ajax_response(success=True, data={'last_page': last_page, 'info': articles_info})
    else:
        return ajax_response(success=True, data={'last_page': last_page, 'info': []})
Ejemplo n.º 14
0
def toggle_star_article(article_id, mode):
    if not _login.current_user.is_authenticated():
        # redirect to login
        return unauthorize_response
    if mode == 0:
        article = Article.query.get(article_id)
        if article:
            if article.is_star():
                start_article = StarArticle.get_from_article(article.title)
                start_article.unstar()
                return ajax_response(success=True, data={'star': False})
            else:
                article.star()
                return ajax_response(success=True, data={'star': True})
    elif mode == 1:
        star_article = StarArticle.query.get(article_id)
        if star_article:
            star_article.unstar()
            return ajax_response(success=True, data={'star': False})

    return ajax_response(success=False)
Ejemplo n.º 15
0
		def _func(request, *args):
			obj = {}
			data = request.POST.get("data", None)
			data = json.loads(data) if data else []
			for k, v in data.items():
				name = v.get("name", k)
				try:
					cls = globals()[name]
					if issubclass(cls, models.Model):
						if not self.permission or request.user.has_perm(full_permission_name(self.permission, cls)):
							obj[k] = func(cls, v, *args)
						else:
							raise PermissionDenied("You have not enough permission to do this operate") 
				except KeyError:
					pass
				except PermissionDenied, e:
					return ajax_response(request, "error", e.message)
Ejemplo n.º 16
0
def get_weibo(weibo_id):
    w = Weibo.query.get(weibo_id)
    return ajax_response(True, data=w.json())
Ejemplo n.º 17
0
def weibo_comment(weibo_id):
    w = Weibo.query.get(weibo_id)
    comments = [c.json() for c in w.comment]
    return ajax_response(True, data=comments)
Ejemplo n.º 18
0
		def _wrapped_view(request, *args, **kwargs):
			if test_func(request.user):
				return view_func(request, *args, **kwargs)
			return ajax_response(request, "error", "unauthorized")
Ejemplo n.º 19
0
def appdata(request):
    value = {
        "Menu": list(Menu.objects.all().values()),
    }
    return ajax_response(request, "success", "", value)
Ejemplo n.º 20
0
def get_comment(comment_id):
    c = WeiboComment.query.get(comment_id)
    return ajax_response(True, data=c.json())
Ejemplo n.º 21
0
def appdata(request):
	value = {
		"Menu": list(Menu.objects.all().values()),
	}
	return ajax_response(request, "success", "", value)
Ejemplo n.º 22
0
def check_name():
    form = request.form
    u = Model(form)
    valid, message = u.valid_username()
    return ajax_response(valid=valid, message=message)
Ejemplo n.º 23
0
def get_user(user_id):
    u = Model.query.get(user_id)
    return ajax_response(valid=True, data=u.json())