예제 #1
0
파일: views.py 프로젝트: exp-repos/GeoPort
def create(request, slug):
    try:
        group = Group.objects.get(slug=slug)
    except:
        raise Http404
    if request.user not in group.staff:
        return PermissionDenied
    context = {}
    context['group'] = group
    if request.method == 'POST':
        form = EventForm(request.POST)
        d = get_post_data(request, *form.fields)
        print d
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = request.user
            event.group = group
            event.tags = form.cleaned_data['tags']
            event.location = form.cleaned_data['location']
            event.save()
            return HttpResponseRedirect(event.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
    else:
        form = EventForm()
    context['form'] = form
    return render(request, 'events/create.html', context)
예제 #2
0
파일: views.py 프로젝트: exp-repos/GeoPort
def participate(request, group_slug, event_id):
    try:
        group = Group.objects.get(slug=group_slug)
    except:
        raise Http404
    try:
        event = Event.objects.get(group=group, id=event_id)
    except:
        raise Http404
    if request.user == event.creator:
        return HttpResponseRedirect(event.get_absolute_url())
    context = {}
    context['group'] = group
    context['event'] = event
    if request.method == 'POST':
        form = ParticipateForm(request.POST)
        if form.is_valid():
            visible = form.cleaned_data['visible']
            event.add_participant(request.user, visible)
            event.save()
            return HttpResponseRedirect(event.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
    else:
        form = ParticipateForm()
    context['form'] = form
    return render(request, 'events/participate.html', context)
예제 #3
0
파일: views.py 프로젝트: exp-repos/GeoPort
def group_settings(request, slug):
    context = {}
    try:
        group = Group.objects.get(slug=slug)
    except:
        raise Http404
    if request.user not in group.staff:
        raise PermissionDenied

    context['group'] = group
    if request.method == 'POST':
        form = GroupForm(request.POST, request.FILES, instance=group)
        if form.is_valid():
            group = form.save(commit=False)
            group.creator = request.user
            group.tags = form.cleaned_data['tags']
            if form.cleaned_data['logo']:
                path = handle_uploaded_file(request.FILES['logo'], 'uploads')
                old_path = group.logo
                if old_path:
                    delete_file(old_path)
                group.logo = path
            group.save()
            return HttpResponseRedirect(group.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
            #context['form'] = form
    else:
        form = GroupForm(instance=group)
        form.initial = get_initial_data(group, *form.fields)
        form.initial['tags'] = ','.join(form.initial['tags'])
    context['form'] = form
    return render(request, 'groups/group_settings.html', context)
예제 #4
0
파일: views.py 프로젝트: exp-repos/GeoPort
def create(request):
    context = {}
    if request.method == 'POST':
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save(commit=False)
            group.creator = request.user
            group.tags = form.cleaned_data['tags']
            if form.cleaned_data['logo']:
                path = handle_uploaded_file(request.FILES['logo'], 'uploads')
                group.logo = path
            group.save()
            return HttpResponseRedirect(group.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
            #context['form'] = form
    else:
        form = GroupForm()
    context['form'] = form
    return render(request, 'groups/create.html', context)
예제 #5
0
파일: views.py 프로젝트: exp-repos/GeoPort
def edit(request, group_slug, event_id):
    try:
        group = Group.objects.get(slug=group_slug)
    except:
        raise Http404
    try:
        event = Event.objects.get(group=group, id=event_id)
    except:
        raise Http404
    if request.user not in group.staff:
        return PermissionDenied
    context = {}
    context['group'] = group
    context['event'] = event
    if request.method == 'POST':
        form = EventForm(request.POST, request.FILES, instance=event)
        #d = get_post_data(request, *form.fields)
        #print d
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = request.user
            event.group = group
            event.tags = form.cleaned_data['tags']
            event.location = form.cleaned_data['location']
            event.save()
            return HttpResponseRedirect(event.get_absolute_url())
        else:
            # Retain POST data if invalid
            data = get_post_data(request, *form.fields)
            form.initial = data
    else:
        form = EventForm(instance=event)
        form.initial = get_initial_data(event, *form.fields)
        form.initial['tags'] = ','.join(form.initial['tags'])
    context['form'] = form
    return render(request, 'events/edit.html', context)