def create(request, *args, **kwargs):
    form = NewClassForm()
    if request.method == "POST":
        form = NewClassForm(request.POST)
        if form.is_valid():
            form.save()
            return render(
                request,
                "administrator/class.html",
                {
                    "form": NewClassForm(request.POST),
                    "query": Class.objects.all()
                },
            )

    return render(
        request,
        "administrator/class.html",
        {
            "form": form,
            "query": Class.objects.all(),
            "page_title": "Admin | Classes",
            "nav_title": "Classes",
        },
    )
Exemplo n.º 2
0
def index(request):
    context = {
        "courses": Course.objects.all(),
        "classes": Class.objects.all(),
        "venues": Venue.objects.all(),
        "academic_years": AcademicYear.objects.all(),
        "schedules": Schedule.objects.all(),
        "nav_title": "Schedules Setup",
        "page_title": "Schedules | Setup",
    }
    if request.method == "POST":
        template = Schedule(
            group=Class.objects.get(pk=request.POST.get("class", "")),
            academic_year=AcademicYear.objects.current(),
            lecturer=request.user,
        )
        template.save()

        for c in request.POST.get("courses[]", []):
            course = Course.objects.get(pk=int(c))
            template.courses.add(course)

        for c in request.POST.get("venues[]", []):
            venue = Venue.objects.get(pk=int(c))
            template.venues.add(venue)

        template.save()
        return redirect(reverse("staff.schedule.index"))

    return render(request, "staff/schedule/index.html", context)
Exemplo n.º 3
0
def index(request):
    form = CodeForm(request.POST or None)
    if request.POST and form.is_valid():
        return redirect(review, id=form.data['code'])
    return render(request, 'codeentry.html', {
        'form': form,
    })
def index(request, *args, **kwargs):
    results = LectureSchedule.objects.filter(
        lecturer=request.user.id,
        academic_year=AcademicYear.objects.current(),
        schedule_template__status="approved",
    )

    data = []
    for item in results:
        data.append(
            {
                "name": f"{item.course.title} @ {item.venue.name}",
                "start": str(item.start_time),
                "end": str(item.end_time),
                "day": item.day,
                "disabled": item.lecturer.id != request.user.id,
            }
        )

    context = {
        "next": request.GET.get("next"),
        "lectures": json.dumps(data),
        "nav_title": "Dashboard",
        "back_button": False,
        "page_title": f"{request.user.get_full_name()} | Dashboard",
    }
    return render(request, "staff/layout.html", context)
def index(request):
    context = {
        "courses": Course.objects.all(),
        "classes": Class.objects.all(),
        "venues": Venue.objects.all(),
        "schedules": ScheduleTemplate.objects.all(),
        "page_title": "Admin | Schedule Template",
        "nav_title": "Schedule Templates",
    }

    if request.method == "POST":
        template = ScheduleTemplate(
            group=Class.objects.get(pk=request.POST.get("class", "")),
            academic_year=AcademicYear.objects.current(),
        )
        template.save()

        for c in request.POST.get("courses[]", []):
            course = Course.objects.get(pk=int(c))
            print(c)
            template.courses.add(course)

        for c in request.POST.get("venues[]", []):
            venue = Venue.objects.get(pk=int(c))
            print(c)
            template.venues.add(venue)

        template.save()

    return render(request, "administrator/schedule/new.html", context)
Exemplo n.º 6
0
def index(request):
    form = CodeForm(request.POST or None)
    if request.POST and form.is_valid():
        return redirect(review, id=form.data['code'])
    return render(request, 'codeentry.html', {
        'form': form,
    })
Exemplo n.º 7
0
def change_user_profile(request):
    form = ProfileForm(request.POST or None, instance=request.user)
    if request.POST and form.is_valid():
        form.save()
        return redirect(user_profile)
    return render(request, 'accounts/change_profile.html', {
        'form': form,
        'title': _('Change profile'),
    })
Exemplo n.º 8
0
def change_user_profile(request):
    form = ProfileForm(request.POST or None, instance=request.user)
    if request.POST and form.is_valid():
        form.save()
        return redirect(user_profile)
    return render(request, 'accounts/change_profile.html', {
        'form': form,
        'title': _('Change profile'),
    })
Exemplo n.º 9
0
def view(request, *args, **kwargs):
    schedules = get_object_or_404(Schedule, pk=kwargs["id"])
    context = {
        "next":
        request.GET.get("next"),
        "lectures":
        LectureSchedule.objects.schedules(schedules.id, request.user.id),
    }
    return render(request, "staff/schedule/view.html", context)
Exemplo n.º 10
0
def post_detail_view(request, post_slug):
    params = dict()
    try:
        post = Post.objects.get(slug=post_slug)
    except:
        messages.warning(request, 'post with slug: %s not found' % post_slug)
        post = None

    params.update(post=post)
    return render(request, 'posts/post_detail.html', params)
Exemplo n.º 11
0
def post_detail_view(request, post_slug):
    params = dict()
    try:
        post = Post.objects.get(slug=post_slug)
    except:
        messages.warning(request, 'post with slug: %s not found' % post_slug)
        post = None

    params.update(post=post)
    return render(request, 'posts/post_detail.html', params)
Exemplo n.º 12
0
def outgoing(request):
    context = {
        "nav_title":
        "Outgoing Schedules",
        "schedules":
        Schedule.objects.filter(
            status="outgoing",
            lecturer=request.user.id,
            academic_year=AcademicYear.objects.current().id,
        ),
    }
    return render(request, "staff/schedule/outgoing.html", context)
Exemplo n.º 13
0
def user_history(request):
    user = request.user
    profile = user.profile

    events = []
    for event in ProfilePlanLog.objects.filter(profile=profile):
        events.append(event_describers[event.action](event))

    return render(request, 'accounts/history.html', {
        'profile': profile,
        'events': events,
    })
Exemplo n.º 14
0
def user_history(request):
    user = request.user
    profile = user.profile

    events = []
    for event in ProfilePlanLog.objects.filter(profile=profile):
        events.append(event_describers[event.action](event))

    return render(request, 'accounts/history.html', {
        'profile': profile,
        'events': events,
    })
Exemplo n.º 15
0
def rejected(request):
    context = {
        "nav_title":
        "Rejected Schedules",
        "schedules":
        Schedule.objects.filter(
            status="rejected",
            lecturer=request.user.id,
            academic_year=AcademicYear.objects.current().id,
        ),
    }
    return render(request, "staff/schedule/rejected.html", context)
Exemplo n.º 16
0
def paste_detail(request, paste_id):
    paste = Paste.get_or_404(paste_id)

    starred = Star.query(Star.author == request.user_email,
                         Star.paste == paste.key).get()

    context = {
        'page_title': paste.filename,
        'paste': paste,
        'starred': starred,
    }

    return render(request, 'pasty/paste_detail.html', context)
Exemplo n.º 17
0
def create(request):
    new_course = NewCourseForm(prefix="add-course")
    if request.method == "POST":
        new_course = NewCourseForm(request.POST, prefix="add-course")
        if new_course.is_valid():
            new_course.save()
    context = {
        "new_course": new_course,
        "courses": Course.objects.all(),
        "page_title": " Admin | Courses",
        "nav_title": "Courses",
    }
    return render(request, "administrator/courses.html", context)
def incoming(request):
    context = {
        "title":
        "Incoming Schedules",
        "schedules":
        Schedule.objects.filter(status="outgoing",
                                academic_year=AcademicYear.objects.current()),
        "page_title":
        "Admin | Incoming Schedules",
        "nav_title":
        "Incoming Schedules",
    }
    return render(request, "administrator/schedule/incoming.html", context)
def rejected(request):
    context = {
        "title":
        "Rejected Schedules",
        "schedules":
        Schedule.objects.filter(status="rejected",
                                academic_year=AcademicYear.objects.current()),
        "page_title":
        "Admin | Rejected Schedules",
        "nav_title":
        "Rejected Schedules",
    }
    return render(request, "administrator/schedule/rejected.html", context)
Exemplo n.º 20
0
def user_profile(request):
    user = request.user
    profile = user.profile

    quota_used = get_used_quota_of_user(user)
    user_greeting = '{} {}'.format(user.first_name, user.last_name).strip() or user.username

    return render(request, 'accounts/profile.html', {
        'user_greeting': user_greeting,
        'profile': profile,
        'block_used': quota_used,
        'block_quota': profile.plan.block_quota,
        'block_percentage': int((quota_used / profile.plan.block_quota) * 100),
    })
Exemplo n.º 21
0
def paste_create(request):
    """Make a new Paste.

    Add ?fork=xyz to a GET request and the initial form will have an existing
    Paste's contents.
    """
    fork_id = request.GET.get('fork')
    fork = Paste.get_by_id(int(fork_id)) if fork_id else None

    if request.method == 'POST':
        form = PasteForm(request.POST)

        if form.is_valid():
            author = request.user_email
            description = form.cleaned_data['description']
            filename_list = request.POST.getlist('filename')
            content_list = request.POST.getlist('content')
            files = zip(filename_list, content_list)

            paste = Paste.create_with_files(author=author,
                                            fork=fork,
                                            description=description,
                                            files=files)

            # Update the search index.
            index.add_paste(paste)

            return redirect('paste_detail', paste.key.id())
    else:
        if fork:
            with fork.files[0].open() as fh:
                content = fh.read()

            initial = {
                'filename': fork.filename,
                'description': fork.description,
                'content': content,
            }
        else:
            initial = {}
        form = PasteForm(initial=initial)

    context = {
        'page_title': u'New paste',
        'form': form,
        'section': 'paste_create',
    }

    return render(request, 'pasty/paste_form.html', context)
Exemplo n.º 22
0
def approved(request):
    context = {
        "nav_title":
        "Approved Schedules",
        "courses":
        Course.objects.all(),
        "classes":
        Class.objects.all(),
        "venues":
        Venue.objects.all(),
        "academic_years":
        AcademicYear.objects.all(),
        "schedules":
        Schedule.objects.filter(status="approved", lecturer=request.user.id),
    }
    return render(request, "staff/schedule/approved.html", context)
Exemplo n.º 23
0
def create(request):
    add = AcademicYearForm(prefix="add-year")

    if request.method == "POST":
        add = AcademicYearForm(request.POST, prefix="add-year")
        if add.is_valid():
            add.save()
            return redirect(reverse("academic.year.index"))

    context = {
        "add_year": add,
        "academic_years": AcademicYear.objects.all(),
        "page_title": "Admin | Academic Years",
        "nav_title": "Academic Years",
    }
    return render(request, "administrator/academic_year.html", context)
Exemplo n.º 24
0
def index(request, *args, **kwargs):
    form_data = AddVenueForm()
    if request.method == "POST":
        form_data = AddVenueForm(request.POST)
        if form_data.is_valid():
            form_data.save()

    return render(
        request,
        "administrator/venue.html",
        {
            "form": form_data,
            "venues": Venue.objects.all(),
            "page_title": "Admin | Venues",
            "nav_title": "Venues",
        },
    )
Exemplo n.º 25
0
def user_profile(request):
    user = request.user
    profile = user.profile

    quota_used = get_used_quota_of_user(user)
    user_greeting = '{} {}'.format(user.first_name,
                                   user.last_name).strip() or user.username

    return render(
        request, 'accounts/profile.html', {
            'user_greeting': user_greeting,
            'profile': profile,
            'block_used': quota_used,
            'block_quota': profile.plan.block_quota,
            'block_percentage': int(
                (quota_used / profile.plan.block_quota) * 100),
        })
Exemplo n.º 26
0
def admin_lexers(request):
    """Form to configure lexers for file extensions."""
    formset = AdminLexersFormSet.for_config()

    if request.method == 'POST':
        formset = AdminLexersFormSet.for_config(request.POST)

        if formset.is_valid():
            formset.save()
            messages.success(request, u'Saved configuration')

            return redirect('admin_lexers')

    context = {
        'formset': formset,
        'section': admin,
        'page_title': u'Configure highlighting',
    }

    return render(request, 'pasty/admin_lexers.html', context)
Exemplo n.º 27
0
def admin(request):
    """For firing migration tasks."""
    form = AdminForm()

    if request.method == 'POST':
        form = AdminForm(request.POST)

        if form.is_valid():
            for label, task_func in form.cleaned_data['tasks']:
                task_func()
                msg = u'Started "%s" task\u2026' % label.lower()
                messages.success(request, msg)

                return redirect('admin')

    context = {
        'form': form,
        'section': 'admin',
        'page_title': u'Administration things',
    }
    return render(request, 'pasty/admin.html', context)
Exemplo n.º 28
0
def review(request, id):
    """Request review page."""
    action = request.POST.get('action')
    if action in ('confirm', 'deny'):
        return redirect(verify, id=id, action=action)
    try:
        pending_verification = get_object_or_404(PendingVerification, id=id)
    except Http404 as http404:
        try:
            DoneVerification.objects.get(id=id)
            return redirect(verify, id=id, action='confirm')  # whatever
        except ObjectDoesNotExist:
            raise http404
    pending_request = pending_verification.request
    if pending_request.is_expired():
        pending_request.delete()
        return expired(request)
    req = pending_request.request
    return render(request, 'review.html', {
        'items': req['items'],
        'identity': req['identity'],
    })
Exemplo n.º 29
0
def review(request, id):
    """Request review page."""
    action = request.POST.get('action')
    if action in ('confirm', 'deny'):
        return redirect(verify, id=id, action=action)
    try:
        pending_verification = get_object_or_404(PendingVerification, id=id)
    except Http404 as http404:
        try:
            DoneVerification.objects.get(id=id)
            return redirect(verify, id=id, action='confirm')  # whatever
        except ObjectDoesNotExist:
            raise http404
    pending_request = pending_verification.request
    if pending_request.is_expired():
        pending_request.delete()
        return expired(request)
    req = pending_request.request
    return render(request, 'review.html', {
        'items': req['items'],
        'identity': req['identity'],
    })
Exemplo n.º 30
0
def setup(request, *args, **kwargs):
    schedules = get_object_or_404(Schedule, pk=kwargs["id"])

    if request.method == "POST":
        data = json.loads(request.body)
        # TODO: handle request processing errors
        for event in data:
            user_data = event["userData"]
            if not event["disabled"] and len(user_data) > 0:
                LectureSchedule.objects.update_or_create(
                    schedule_template=get_object_or_404(Schedule,
                                                        pk=kwargs["id"]),
                    day=event["location"],
                    course=Course.objects.get(pk=int(user_data["course_id"])),
                    group=schedules.group,
                    venue=Venue.objects.get(pk=int(user_data["venue_id"])),
                    start_time=str(arrow.get(event["start"]).time()),
                    end_time=str(arrow.get(event["end"]).time()),
                    lecturer=request.user,
                    academic_year=AcademicYear.objects.current(),
                )

        return JsonResponse({
            "status": "success",
            "message": "Timetable data saved successfully"
        })

    context = {
        "courses":
        Schedule.objects.courses(schedules.group.id),
        "venues":
        Schedule.objects.venues(schedules.group.id),
        "schedules":
        schedules,
        "lectures":
        LectureSchedule.objects.schedules(schedules.id, request.user.id),
    }
    return render(request, "staff/schedule/new.html", context)
Exemplo n.º 31
0
def paste_list(request):
    """Shows a synopsis of pastes.

    You can search for pastes by author and tag, or search the paste content.

    /[email protected] - finds pastes by [email protected]
    /?q=foo - finds pastes containing the word 'foo'
    """
    page = request.GET.get('p')
    terms = index.build_query(request.GET)
    query = u' '.join(term for term, label, param in terms).encode('utf-8')
    pastes = index.search_pastes(query, page)
    tags = [label for term, label, param in terms]
    page_title = u'Pastes ' + u', '.join(tags)

    context = {
        'page_title': page_title,
        'pastes': pastes,
        'section': 'paste_list',
        'terms': terms,
    }

    return render(request, 'pasty/paste_list.html', context)
Exemplo n.º 32
0
def home(request):
    params = dict(current_page='home')
    return render(request, 'posts/home.html', params)
Exemplo n.º 33
0
def expired(request):
    return render(request, 'request_expired.html')
Exemplo n.º 34
0
def user_mail_confirmed(request):
    return render(request, 'accounts/confirmed.html')
Exemplo n.º 35
0
def confirmed(request):
    return render(request, 'request_status.html', {
        'status': 'confirmed',
    })
Exemplo n.º 36
0
def denied(request):
    return render(request, 'request_status.html', {
        'status': 'denied',
    })
def index(request):
    return render(request, "administrator/layout.html",
                  {"nav_title": "Dashboard"})
Exemplo n.º 38
0
def posts_list_view(request):
    params = dict()
    posts = Post.objects.filter(user=request.user, is_enabled=True)
    params.update(posts=posts)
    return render(request, 'posts/posts_list.html', params)
Exemplo n.º 39
0
        if form.is_valid():
            slug = form.cleaned_data['slug']
            text = form.cleaned_data['text']
            post = Post(slug=slug, text=text)
            try:
                post.user = request.user
                post.save()
                return redirect('post_detail_view', post.slug)
            except Exception, e:
                messages.error(request, "create post errors: %s" % e)
        else:
            messages.error(request, "form errors: %s" % form.errors)
    else:
        form = PostForm(auto_id=False)
    params.update(form=form)
    return render(request, 'posts/create_post.html', params)


@login_required
def posts_list_view(request):
    params = dict()
    posts = Post.objects.filter(user=request.user, is_enabled=True)
    params.update(posts=posts)
    return render(request, 'posts/posts_list.html', params)


@login_required
def post_detail_view(request, post_slug):
    params = dict()
    try:
        post = Post.objects.get(slug=post_slug)
Exemplo n.º 40
0
def settings_view(request):
    params = dict(current_page='settings_view')
    return render(request, 'accounts/settings.html', params)
Exemplo n.º 41
0
        if form.is_valid():
            slug = form.cleaned_data['slug']
            text = form.cleaned_data['text']
            post = Post(slug=slug, text=text)
            try:
                post.user = request.user
                post.save()
                return redirect('post_detail_view', post.slug)
            except Exception, e:
                messages.error(request, "create post errors: %s" % e)
        else:
            messages.error(request, "form errors: %s" % form.errors)
    else:
        form = PostForm(auto_id=False)
    params.update(form=form)
    return render(request, 'posts/create_post.html', params)


@login_required
def posts_list_view(request):
    params = dict()
    posts = Post.objects.filter(user=request.user, is_enabled=True)
    params.update(posts=posts)
    return render(request, 'posts/posts_list.html', params)


@login_required
def post_detail_view(request, post_slug):
    params = dict()
    try:
        post = Post.objects.get(slug=post_slug)
Exemplo n.º 42
0
def home(request):
    params = dict(current_page='home')
    return render(request, 'posts/home.html', params)
Exemplo n.º 43
0
def home(request):
  template = "index.html"
  return render(request, template, {})
Exemplo n.º 44
0
def test(request, message):
  template = "test.html"

  return render(request, template, {'message':message,
    'id': 1})
Exemplo n.º 45
0
def user_mail_confirmed(request):
    return render(request, 'accounts/confirmed.html')
Exemplo n.º 46
0
def posts_list_view(request):
    params = dict()
    posts = Post.objects.filter(user=request.user, is_enabled=True)
    params.update(posts=posts)
    return render(request, 'posts/posts_list.html', params)