Beispiel #1
0
def note_detail(request, noteid):
    """
	查看笔记详情
	:param request:
	:param noteid: 笔记id
	:return:
	"""
    if request.method == 'GET':
        is_author = False
        is_fond = False
        userid = request.session.get('userid')
        data = Initialization(request, request.session.get('userid')).get_min()
        note = models.Notes.objects.get(noteid=noteid)
        if userid == note.note_user_id:
            is_author = True
        fond = models.UserFondNotes.objects.filter(noteid_id=noteid,
                                                   userid_id=userid)
        if fond:
            is_fond = True
        return render(request, 'note_detail.html', {
            'data': data,
            'note': note,
            'is_author': is_author,
            'is_fond': is_fond
        })
Beispiel #2
0
def activity_detail(request, activity_id):
    """
	查看活动详情
	:param request:
	:param groupid:
	:return:
	"""
    is_leader = False
    is_in = False
    is_end = False
    data = Initialization(request, request.session.get('userid')).get_min()
    signs = models.ActivitySign.objects.filter(
        activity_id=activity_id).order_by('-time')
    activity = models.Activities.objects.get(activity_id=activity_id)
    members = models.ActivityMembers.objects.filter(activity=activity_id)
    if members.filter(member=request.session.get('userid')):
        is_in = True
    if request.session.get('userid') == activity.leader_id:
        is_leader = True
    if activity.status == 1:
        is_end = True
    return render(
        request, 'activity_detail.html', {
            'data': data,
            'activity': activity,
            'members': members,
            'signs': signs,
            'is_leader': is_leader,
            'is_in': is_in,
            'is_end': is_end
        })
Beispiel #3
0
def sign(request, activity_id):
    """
	活动打卡
	:param request:
	:param activity_id:
	:return:
	"""
    if request.method == 'GET':
        data = Initialization(request, request.session.get('userid'))
        return render(request, 'activity_sign.html', {
            'activity': activity_id,
            'data': data
        })
    if request.method == 'POST':
        ret = {'status': 'fail', 'error': None}
        userid = request.session.get('userid')
        is_in = models.ActivityMembers.objects.filter(activity_id=activity_id,
                                                      member_id=userid)
        if userid:
            content = request.POST.get('content')
            if content == "":
                ret['error'] = '打卡内容不能为空.'
            elif is_in:
                models.ActivitySign.objects.create(activity_id=activity_id,
                                                   user_id=userid,
                                                   content=content)
                ret['status'] = 'success'
            else:
                ret['error'] = '未加入该活动.'
        else:
            ret['status'] = 'unauthorized'
        return HttpResponse(json.dumps(ret))
Beispiel #4
0
def user_fond(request, userid):
    if request.method == 'GET':
        data = Initialization(request, userid).get_all()
        notes = models.UserFondNotes.objects.filter(userid=userid)
        notes = notes.order_by('-fond_time')
        return render(request, 'note_fond.html', {
            'data': data,
            'notes': notes
        })
Beispiel #5
0
def user_activity(request, userid):
    if request.method == 'GET':
        data = Initialization(request, userid).get_all()
        activities = models.ActivityMembers.objects.filter(member=userid)
        activities = activities.order_by('-add_time')
        return render(request, 'user_activity.html', {
            'data': data,
            'activities': activities
        })
Beispiel #6
0
def user_follows(request, userid):
    if request.method == 'GET':
        data = Initialization(request, userid).get_all()
        follows = models.UserFans.objects.filter(follower=userid)
        follows = follows.order_by('-follow_time')
        return render(request, 'follows.html', {
            'data': data,
            'follows': follows
        })
Beispiel #7
0
def activity_new(request):
    """
	创建新活动
	:param request:
	:return:
	"""
    if request.method == 'GET':
        data = Initialization(request, request.session.get('userid')).get_min()
        activity_tags = models.ActivityTag.objects.all()
        return render(request, 'activity_new.html', {
            'data': data,
            'activity_tags': activity_tags
        })
    if request.method == 'POST':
        ret = {'status': 'fail', 'error': None}
        userid = request.session.get('userid')
        if userid:
            activity_dict = {
                'activity_name': request.POST.get('activity_name'),
                'activity_request': request.POST.get('activity_content'),
                'start_time': request.POST.get('start_time'),
                'end_time': request.POST.get('end_time'),
                'place': request.POST.get('activity_place'),
                'activity_tag_id': request.POST.get('activity_tag'),
                'leader_id': userid
            }
            if activity_dict['activity_name'].isspace(
            ) or activity_dict['activity_name'] == "":
                ret['error'] = '活动名称不能为空.'
            elif activity_dict['activity_request'].isspace(
            ) or activity_dict['activity_request'] == "":
                ret['error'] = '活动要求不能为空.'
            elif activity_dict['start_time'] == "":
                ret['error'] = '开始时间不能为空.'
            elif activity_dict['end_time'] == "":
                ret['error'] = '结束时间不能为空.'
            elif activity_dict['start_time'] > activity_dict['end_time']:
                ret['error'] = '活动时间不合法.'
            elif activity_dict['place'].isspace(
            ) or activity_dict['place'] == "":
                ret['error'] = '活动地点不能为空.'
            else:
                try:
                    with transaction.atomic():
                        activity = models.Activities.objects.create(
                            **activity_dict)
                        models.ActivityMembers.objects.create(
                            activity_id=activity.activity_id,
                            member_id=userid,
                            identity=1)
                        ret['status'] = 'success'
                        ret['activity'] = activity.activity_id
                except Exception as e:
                    ret['error'] = e.args
        else:
            ret['status'] = 'unauthorized'
        return HttpResponse(json.dumps(ret))
Beispiel #8
0
def user_note(request, userid):
    if request.method == 'GET':
        data = Initialization(request, userid).get_all()
        if userid == request.session.get('userid'):
            notes = models.Notes.objects.filter(note_user=userid)
        else:
            notes = models.Notes.objects.filter(note_user=userid,
                                                readlimit='1')
        notes = notes.order_by('-last_edit_time')
        return render(request, 'user_note.html', {
            'data': data,
            'notes': notes
        })
Beispiel #9
0
def note_edit(request, noteid):
    """
	编辑笔记
	:param request:
	:param noteid: 笔记id
	:return:
	"""
    if request.method == 'GET':
        data = Initialization(request, request.session.get('userid')).get_min()
        note = models.Notes.objects.get(noteid=noteid)
        tags = models.NoteTag.objects.all()
        limits = models.ReadLimit.objects.all()
        if note.note_user_id == request.session.get('userid'):
            return render(request, 'note_edit.html', {
                'data': data,
                'note': note,
                'tags': tags,
                'limits': limits
            })
        else:
            return redirect('/login/')
    if request.method == 'POST':
        ret = {'status': 'fail', 'error': None}
        userid = request.session.get('userid')
        if userid == request.POST.get('noteuser_id'):
            note_dict = {
                'title': request.POST.get('title'),
                'summary': request.POST.get('summary'),
                'notetag_id': request.POST.get('tag'),
                'readlimit_id': request.POST.get('limit'),
                'content': request.POST.get('content'),
                'note_user_id': userid,
                'last_edit_time': timezone.now()
            }
            if note_dict['title'].isspace() or note_dict['title'] == '':
                ret['error'] = '标题不能为空.'
            elif note_dict['content'] == '':
                ret['error'] = '笔记内容不能为空.'
            else:
                try:
                    with transaction.atomic():
                        models.Notes.objects.filter(
                            noteid=request.POST.get('noteid')).update(
                                **note_dict)
                        ret['status'] = 'success'
                except Exception as e:
                    ret['error'] = e.args
        else:
            ret['status'] = 'unauthorized'
        return HttpResponse(json.dumps(ret))
Beispiel #10
0
def search_activity(request):
    if request.method == 'GET':
        keyword = request.GET.get('keyword')
        kwargs = {
            'keyword': keyword,
        }
        if keyword:
            activities = models.Activities.objects.filter(
                Q(activity_name__contains=keyword)
                | Q(activity_id__contains=keyword)
                | Q(activity_request__contains=keyword)
                | Q(place__contains=keyword))
        else:
            activities = None
        data = Initialization(request, request.session.get('userid')).get_min()
        return render(request, 'search_activity.html', {
            'data': data,
            'activities': activities,
            'kwargs': kwargs
        })
Beispiel #11
0
def note_new(request):
    """
	创建新笔记
	:param request:
	:return:
	"""
    if request.method == 'GET':
        data = Initialization(request, request.session.get('userid')).get_min()
        tags = models.NoteTag.objects.all()
        limits = models.ReadLimit.objects.all()
        return render(request, 'note_new.html', {
            'data': data,
            'tags': tags,
            'limits': limits
        })
    if request.method == 'POST':
        ret = {'status': 'fail', 'error': None}
        userid = request.session.get('userid')
        if userid:
            note_dict = {
                'title': request.POST.get('title'),
                'summary': request.POST.get('summary'),
                'notetag_id': request.POST.get('tag'),
                'readlimit_id': request.POST.get('limit'),
                'content': request.POST.get('content'),
                'note_user_id': userid
            }
            if note_dict['title'].isspace() or note_dict['title'] == '':
                ret['error'] = '标题不能为空.'
            elif note_dict['content'] == '':
                ret['error'] = '笔记内容不能为空.'
            else:
                try:
                    with transaction.atomic():
                        models.Notes.objects.create(**note_dict)
                        ret['status'] = 'success'
                except Exception as e:
                    ret['error'] = e.args
        else:
            ret['status'] = 'unauthorized'
        return HttpResponse(json.dumps(ret))
Beispiel #12
0
def search_user(request):
    """
	查找用户
	:param request:
	:return:
	"""
    if request.method == 'GET':
        keyword = request.GET.get('keyword')
        kwargs = {
            'keyword': keyword,
        }
        if keyword:
            users = models.UserInfo.objects.filter(
                Q(userid__contains=keyword) | Q(username__contains=keyword))
        else:
            users = None
        data = Initialization(request, request.session.get('userid')).get_min()
        return render(request, 'search_user.html', {
            'users': users,
            'data': data,
            'kwargs': kwargs
        })
Beispiel #13
0
def search_note(request):
    """
	查找用户笔记
	:param request:
	:return:
	"""
    if request.method == 'GET':
        keyword = request.GET.get('keyword')
        tag = request.GET.get('tag', '0')
        sort = request.GET.get('sort', '0')
        sort_rule = {
            '0': 'create_time',
            '1': '-create_time',
        }
        sort_select = {
            '0': '按时间升序',
            '1': '按时间降序',
        }
        kwargs = {'keyword': keyword, 'tag': tag, 'sort': sort}
        if keyword:
            notes = models.Notes.objects.filter(
                Q(title__contains=keyword) | Q(summary__contains=keyword)
                | Q(content__contains=keyword)).filter(readlimit_id='1')
            if tag != '0':
                notes = notes.filter(notetag_id=tag)
            notes = notes.order_by(sort_rule[sort])
        else:
            notes = None
        tags = models.NoteTag.objects.all()
        data = Initialization(request, request.session.get('userid')).get_min()
        return render(
            request, 'search_note.html', {
                'data': data,
                'notes': notes,
                'tags': tags,
                'sort_select': sort_select,
                'kwargs': kwargs
            })
Beispiel #14
0
def index(request):
    if request.method == 'GET':
        data = Initialization(request, request.session.get('userid')).get_min()
        return render(request, 'index.html', {'data': data})