def read(request): if request.method == 'POST': unread = Notification.objects.filter(users__in=[request.user.pk], status=Notification.UNREAD).count() if unread > 0: Notification.objects.filter(users__in=[request.user.pk], status=Notification.CURRENT).update(status=Notification.READ) Notification.objects.filter(users__in=[request.user.pk], status=Notification.UNREAD).update(status=Notification.CURRENT) print json.success() return json.success() return HttpResponseNotAllowed(['POST'])
def jsonify(raw, wrap=None): expr = raw if wrap: expr = json.success(raw) if wrap.lower()[0] == 's' else json.error(raw) return mark_safe(serialize_json(expr))
def transfer(request): if request.method == "POST": transfer_form = TransferForm(request, data=request.POST) if transfer_form.is_valid(): transfer_form.save() return json.success({ 'sidebar': render_sidebar(request.user) }) return json.error(transfer_form.errors) return HttpResponseNotAllowed(['POST'])
def settings_notice(request): if request.method == "POST": notice_form = NoticeForm(request, data=request.POST) if notice_form.is_valid(): notice_form.save() return json.success() return json.error(notice_form.errors) return HttpResponseNotAllowed(['POST'])
def markup(request): if request.method == "POST": markup_form = MarkupForm(request, data=request.POST) if markup_form.is_valid(): markup_form.save() return json.success({ 'sidebar': render_sidebar(request.user) }) return json.error(markup_form.errors) return HttpResponseNotAllowed(['POST'])
def guide(request): if request.method == "POST": guide_form = GuideForm(request, data=request.POST) if guide_form.is_valid(): guide_form.save() return json.success({ 'sidebar': render_sidebar(request.user) }) return json.error(guide_form.errors) return HttpResponseNotAllowed(['POST'])
def abandon(request): if request.method == "POST": abandon_form = AbandonForm(request, data=request.POST) if abandon_form.is_valid(): abandon_form.save() return json.success({ 'sidebar': render_sidebar(request.user) }) return json.error(abandon_form.errors) return HttpResponseNotAllowed(['POST'])
def invite(request): if request.method == "POST": invite_form = InviteForm(request, data=request.POST) if invite_form.is_valid(): invite_form.save() return json.success() return json.error(invite_form.errors) return HttpResponseNotAllowed(['POST'])
def resign(request): if request.method == "POST": form = LeadResignForm(request, data=request.POST) if form.is_valid(): form.save() return json.success({}) return json.error(form.errors) return HttpResponseNotAllowed(["POST"])
def invite(request): if request.method == 'POST': form = InviteForm(request, data=request.POST) if form.is_valid(): code = form.save() return json.success({ "code": code }) return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def invite(request): if request.method == 'POST': form = NewInvitation(data=request.POST) if form.is_valid(): form.save() return json.success() return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def promote_bulletin(request): if request.method == 'POST': form = PromoteForm(request, data=request.POST) if form.is_valid(): form.save() return json.success() return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def follow_bulletin(request): if request.method == 'POST': form = FollowForm(request, data=request.POST) if form.is_valid(): followed = form.save() return json.success({'followed': followed, 'id': request.user.pk, 'username': request.user.username, 'url': render_to_string('account/gravatar_img.jade', {'user': request.user})}) return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def guide(request): if request.method == 'POST': data = request.POST if int(data['remove']) == 1: request.user.get_profile().show_guide = False else: request.user.get_profile().show_guide = True request.user.get_profile().save() return json.success() return HttpResponseNotAllowed(['POST'])
def add_comment(request): if request.method == 'POST': form = CommentForm(request, data=request.POST) if form.is_valid(): form.save() comments = request.bulletin.comment_set.all().order_by('-created_at') return json.success({'feed': render_to_string('comment/comments.jade', {'comments': comments, 'current_user': request.user, 'current_chapter': request.chapter})}) return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def add_pending(request): if request.method == 'POST' and request.user.get_profile().chapter: form = PendingForm(request, data=request.POST) if form.is_valid(): form.save() pending = Pending.objects.filter(chapter=request.chapter).order_by('-created') contextDict = {'pendings': pending} context = Context(contextDict) template = get_template('pending/pendings.jade') return json.success({'feed': template.render(context)}) return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def edit_talk(request): if request.method == 'POST': form = TalkForm(request, data=request.POST) if form.is_valid(): form.save(request.bulletin) talks = Talk.objects.filter(chapter=request.chapter).order_by('-created') contextDict = {'talks': talks, 'current_user': request.user} context = Context(contextDict) template = get_template('talk/talks.jade') return json.success({'feed': template.render(context)}) return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def add_intro(request): if request.method == 'POST': form = IntroductionForm(request, data=request.POST) if form.is_valid(): form.save() intros = Introduction.objects.filter(chapter=request.chapter).order_by('-created') contextDict = {'intros': intros, 'current_user': request.user} context = Context(contextDict) template = get_template('introduction/intros.jade') return json.success({'feed': template.render(context)}) return json.error(form.errors) return HttpResponseNotAllowed(['POST'])
def _inner(request): if request.method == "POST": form = formcls(request, data=request.POST) if form.is_valid(): form.save() contextDict = {"current_user": request.user} mentees = request.user.get_profile().get_mentees() if request.is_insider else [] if request.user.get_profile().is_leader: pending_requests = [] else: pending_requests = Leadership.objects.filter( owner=request.user, response=Leadership.PENDING ).order_by("-created") mentee_chunks = [] if mentees: mentee_chunks = chunks(mentees, 3) count = 0 for chunk in mentee_chunks: count += 3 for i in range(0, 3 - len(chunk)): chunk.append({"mentee": None}) for i in range(0, (settings.MAX_MENTEES - count) / 3): mentee_chunks.append([{"mentee": None} for j in range(0, 3)]) my_mentee_string = ",".join([mentee.user.username for mentee in mentees]) contextDict["mentee_chunks"] = mentee_chunks contextDict["my_mentee_string"] = my_mentee_string contextDict["pending_requests"] = pending_requests contextDict["current_chapter"] = request.chapter context = Context(contextDict) template = get_template("chapter/sidebar.jade") return json.success({"sidebar": template.render(context)}) return json.error(form.errors) return HttpResponseNotAllowed(["POST"])
def message(request): if request.method == 'POST': data = request.POST valid = True recipients = [] for recipient in data.getlist("to"): try: user = User.objects.get(username=recipient) except User.DoesNotExist: continue if not request.user.is_authenticated() or not request.user.is_active: if not user.get_profile().is_leader: valid = False if not valid: return json.errors({"Message": "You are not Allowed to do that!"}) recipients.append(user) notification_type = NotificationType.objects.get(name="message") if request.user.is_authenticated() and request.user.is_active: notification = Notification(notification_type=notification_type, sender=request.user.get_profile().get_email()) else: notification = Notification(notification_type=notification_type, sender=data.get("from")) notification.save() for recipient in recipients: notification.users.add(recipient) if request.user.is_authenticated() and request.user.is_active: notification.add_dictionary({"message": data['message'], "sender_display_name": request.user.get_profile().display_name, "sender_username": request.user.username}) else: notification.add_dictionary({"message": data['message'], "sender_display_name": data.get('from'), "sender_username": request.user.username}) notification.save() notification.dispatch() return json.success() return HttpResponseNotAllowed(['POST'])
def get(request): if request.method == 'GET': notifications = Notification.objects.filter(users__in=[request.user.pk], status=Notification.UNREAD) chapter_id = request.user.get_profile().chapter.pk notification_array = [] for notification in notifications.all(): notification_dict = {} notification_values = NotificationDict.objects.filter(notification=notification) bulletin_id = getNDVal(notification_values, 'bulletin') bulletin_id = bulletin_id if bulletin_id is None else int(bulletin_id) if bulletin_id is None: continue comment_id = getNDVal(notification_values, 'comment') comment_id = comment_id if comment_id is None else int(comment_id) bulletin = Bulletin.objects.filter(id=bulletin_id)[0] bulletin_title = bulletin.title if comment_id is not None: raw_comment = Comment.objects.filter(id=comment_id).values('content')[0]['content'] safe_comment = strip_tags(raw_comment)[0:30] notification_dict['comment_id'] = comment_id notification_dict['comment_str'] = safe_comment notification_dict['bulletin_id'] = bulletin_id notification_dict['bulletin_title'] = bulletin_title notification_dict['notif_id'] = notification.id notification_array.append(notification_dict) chapter = Chapter.objects.filter(id=chapter_id).values('slug')[0]['slug'] retDict = {'notifs': notification_array, 'chapter': chapter} return json.success(retDict) return HttpResponseNotAllowed(['POST'])