Ejemplo n.º 1
0
def edit_class(request, host_b36):
    host_id = base36_to_int(host_b36) 
    host_class = HostClass.objects.get(pk=host_id)
    user = request.user

    places = None
    if request.user.is_authenticated():
        places = user.place.all()

    if host_class.is_admin(user):
        course = host_class.course
        if request.method == 'POST':
            post_data = request.POST
            course_form = MakeCourseForm(request.POST)
            session_form = CourseSessionForm(request.POST)
            place_form = VenueForm(post_data)
            if post_data['place'] == '-1':
                if place_form.is_valid():
                    place = place_form.save(request)
                else:
                    raise Exception("place not valid")
            else:
                place = Place.objects.get(pk=int(post_data["place"]))
            if course_form.is_valid() and session_form.is_valid():
                if not course.published: # and course.is_editor(request.user):
                    course.title = course_form.cleaned_data['title']
                    course.description = course_form.cleaned_data['description']
                    course.prereqs = course_form.cleaned_data['prerequisites']
                    #course.from_date = course_form.cleaned_data['from_date']
                    #course.course_number = course_form.cleaned_data['course_number']
                    course.url = course_form.cleaned_data['url']
                    course.save()
                hc = session_form.save(course, place, host_class)
                return HttpResponseRedirect('/h/e/%s/' % int_to_base36(hc.pk))
        else:
            course_form = MakeCourseForm({'title':course.title, 
                'description':course.description,
                'prerequisites':course.prereqs,
                #'from_date':course.from_date,
                #'course_number':course.course_number,
                'url':course.url })
            session_form = CourseSessionForm({'starting_date':host_class.disp_start_date, 
                'time':host_class.meeting_time, 
                'check_sunday': host_class.sunday,
                'check_monday': host_class.monday,
                'check_tuesday': host_class.tuesday,
                'check_wednesday': host_class.wednesday,
                'check_thursday': host_class.thursday,
                'check_friday': host_class.friday,
                'check_saturday': host_class.saturday,
                'privacy':host_class.privacy})

        return render_to_response('host/edit.html', {
            'host_class': host_class, 'course_form': course_form,
            'places': places, 'session_form': session_form
            }, context_instance=RequestContext(request))
    else:
        raise Http404
Ejemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        forms = {
            'venue_form':
            VenueForm(),
            'event_form':
            EventForm(),
            'venue_bookmark_form':
            VenueBookmarkForm(choices=[(o.id, str(o.name))
                                       for o in Venue.objects.all()]),
            'event_bookmark_form':
            EventBookmarkForm(choices=[(o.id, str(o.name))
                                       for o in Event.objects.all()]),
        }
        context = {}
        current_user = request.user
        if current_user.is_authenticated:  # retrieve the user's info to display
            current_user_profile = UserProfile.objects.get(
                user=current_user.id)
            context['profile'] = current_user_profile

            venue_bookmarks = current_user_profile.bookmarked_venues.all()
            event_bookmarks = current_user_profile.bookmarked_event.all()
            owned_venues = current_user_profile.owned_venues.all()
            info = {
                'event_bookmarks': event_bookmarks,
                'venue_bookmarks': venue_bookmarks,
                'owned_venues': owned_venues
            }

            context = {**context, **forms, **info}
            return render(request, 'profile.html', context)
        else:
            return redirect('login')
Ejemplo n.º 3
0
def host_create(request, course_b36=None, additional_vars={}):
    course_id = base36_to_int(course_b36) 
    user = request.user
    places = None
    if request.user.is_authenticated():
        places = user.place.all()
    course = CourseInfo.objects.get(pk=course_id)
    if request.method == 'POST':
        post_data = request.POST
        session_form = CourseSessionForm(post_data) # this form captures basic info, MWF, start date, meeting time
        place_fm = VenueForm(post_data)
        if session_form.is_valid():
            if post_data['place'] == '-1':
                if place_fm.is_valid():
                    place = place_fm.save(request)
                else:
                    raise Exception("place not valid?")
            else:
                place = Place.objects.get(pk=int(post_data["place"]))
            hc = session_form.save(course, place)
            hc_member = HostClassMember(host_class=hc, user=request.user, editor=True)
            hc_member.save()
            sessions = course.course_info_session.all()
            if len(sessions) > 0:
                for course_info_session in sessions:
                    session = course_info_session.session
                    next_date = hc.next_available_date()
                    hcs = HostClassSession(host_class=hc, course_session=session, date=datetime.combine(next_date, hc.meeting_time))
                    hcs.save()
            next = request.POST.get('next', '')
            if next == '1':
                return HttpResponseRedirect('/h/meetings/%s/?next=1' % (int_to_base36(hc.id)))
            else:
                return HttpResponseRedirect('/h/v/%s/' % (int_to_base36(hc.pk)))
    else:
        session_form = CourseSessionForm()

    render_vars = {'course': course, 'places': places, 'session_form':session_form, 'class_creater': True}
    return render_to_response('host/make2.html', render_vars
        , context_instance=RequestContext(request))
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        context = {}
        current_user = request.user
        current_user_profile = UserProfile.objects.get(user=current_user.id)
        if 'addVenueBookmark' in request.POST:
            chosen_venue = request.POST['venue']
            #this is horrible but I couldn't figure out how to reinstate the form
            #with the post data as I've added a constructor argument to the form
            #see addVenueForm/addEventForm to see how it should be done
            venue_obj = Venue.objects.get(id=chosen_venue)
            try:
                current_user_profile.bookmarked_venues.add(venue_obj)
            except IntegrityError:
                pass  # in case it's already a bookmark: do nothing
            current_user_profile.save()
            return redirect('profile')
        if 'addEventBookmark' in request.POST:
            chosen_event = request.POST['event']
            event_obj = Event.objects.get(id=chosen_event)
            #see addVenueBookmark
            try:
                current_user_profile.bookmarked_event.add(chosen_event)
            except IntegrityError:
                pass  # in case it's already a bookmark: do nothing
            current_user_profile.save()
            return redirect('profile')
        if 'addVenueForm' in request.POST:
            a_v_form = VenueForm(request.POST, request.FILES)
            if a_v_form.is_valid():
                address = a_v_form.cleaned_data['address']
                address_fr, address_nl, point = Geocoder().geocode(address)

                venue = Venue(
                    name=a_v_form.cleaned_data['name'],
                    point=point,
                    address_fr=address_fr,
                    address_nl=address_nl,
                    description=a_v_form.cleaned_data['description'],
                    image=a_v_form.cleaned_data['image'],
                )
                venue.save()
                current_user_profile.owned_venues.add(venue)

                return redirect('profile')
            else:
                return redirect('profile')
        if 'addEventForm' in request.POST:
            a_e_form = EventForm(request.POST, request.FILES)
            if a_e_form.is_valid():
                price_input = a_e_form.cleaned_data['price']
                venue_object = a_e_form.cleaned_data['venue']
                artists = a_e_form.cleaned_data['artists']
                genres_text = a_e_form.cleaned_data['genres']
                previews = a_e_form.cleaned_data['previews']

                event = Event(
                    name=a_e_form.cleaned_data['name'],
                    venue=venue_object,
                    description=a_e_form.cleaned_data['description'],
                    price=a_e_form.cleaned_data['price'],
                    official_page=a_e_form.cleaned_data['official_page'],
                    datetime=a_e_form.cleaned_data['date'],
                    image=a_e_form.cleaned_data['image'],
                )
                # todo: solve it not saving the time

                # order of saving objects is important here
                # id needs to be created (is done on save) etc..
                event.save()
                for artist in artists.split(','):
                    last_fm_exists = is_artist_on_lastfm(artist)
                    artist_instance = Artist(
                        name=artist, last_fm_entry_exists=last_fm_exists)
                    artist_instance.save()
                    artist_instance.events.add(event)
                for genre in genres_text.split(','):
                    genre_instance = Genre(name=genre[:19])
                    genre_instance.save()
                    event.genres.add(genre_instance)
                for preview in previews.split(','):
                    yt_check = check_preview_for_youtube(preview)
                    if yt_check is None:
                        # preview_instance = Preview(youtube_video_id=preview,type="")
                        pass
                    else:
                        preview_instance = Preview(youtube_video_id=yt_check,
                                                   type="youtube")
                    preview_instance.save()
                    event.previews.add(preview_instance)

                return redirect('profile')

            else:
                return redirect('profile')
        else:
            return redirect('profile')