Esempio n. 1
0
def invite(request, host_b36):
    host_id = base36_to_int(host_b36) 
    host_class = get_object_or_404(HostClass, pk=host_id)
    
    if host_class.is_member(request.user):
        contacts = request.user.contact.all()
        class_creater = request.GET.get('next', '') == '1'
        if request.method == 'POST':
            message = request.POST['message']
            from models import send_invite_letters
            invitee_list = []
            for key in request.POST:
                if key.startswith('inv'):
                    _inv, usrnm = key.split('-')
                    invitee = User.objects.get(username=usrnm)
                    if invitee in [c.to_contact for c in contacts]:
                        invitee_list.append(invitee)
            emails = request.POST['emails']
            if emails:
                email_list = emails.split(',')
            else:
                email_list = []
	    from CoClass.invite.models import PseudoUser
            for email in email_list:
                # regex validate email
                #invitee = create_pseudouser_or_get_user(email)
                print email
                invitee = PseudoUser.objects.create(email)
                host_class_to = ','.join([int_to_base36(host_class.pk), request.user.username])
                #req = Request(host_class_to_from=host_class_to_from)
                #req.save()
                invitee.host_class_to = host_class_to
                html_content = message
                html_content += "\n\nClick the link below to learn about taking %s.\n\n\nhttp://www.coclass.com/accounts/signup/?key=%s " % (host_class.course.title, invitee.activation_key)
                send_mail("%s wants you to take %s on CoClass" % (request.user.get_full_name(), host_class.course.title), html_content, '*****@*****.**', [email])
            print invitee_list
            send_invite_letters(to_users=invitee_list, from_user=request.user, host_class=host_class, body=message)
            return HttpResponseRedirect('/h/v/%s/' % (int_to_base36(host_class.pk)))
        message_initial = "Starting %s, I will be studying %s. We will meet %s at %s to watch video lectures.  You should join!" % (host_class.disp_start_date, host_class.course.title, host_class.render_days(), host_class.place.name )
        if not class_creater:
            ext_template = "host/base_edit.html"
        else:
            ext_template = "host/base.html"
        return render_to_response('host/invite.html', {
            'host_class':host_class, 
            'course':host_class.course, 
            'class_creater': class_creater, 
            'message': message_initial, 
            'contacts': contacts,
            'ext_template':ext_template
            }, context_instance=RequestContext(request))
Esempio n. 2
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
Esempio n. 3
0
def edit_calendar(request, host_b36):
    host_id = base36_to_int(host_b36) 
    host_class = HostClass.objects.get(pk=host_id)
    host_sessions = host_class.dates.all()
    if host_class.is_admin(request.user):
        #created = host_class.created
        class_creater = request.REQUEST.get('next', '') == '1'
        print class_creater
        if request.method == 'POST':
            post_data = request.POST
            host_class_sessions = []
            hour = host_class.meeting_time.hour
            min = host_class.meeting_time.minute
            #if class_creater: #created:
            #    host_class.created = True
            #    host_class.save()
            for key in post_data:
                value = post_data[key]
                if key.startswith('h_'):
                    h_, session_id = key.split('_')
                    session = host_class.dates.get(pk=session_id)
                    trans_date = datetime.strptime(value, "%a_%b_%d_%Y %H:%M:%S")
                    if session.date != trans_date:
                        session.date = trans_date
                        session.save()
            next = request.POST.get('next', '')
            if not class_creater:
                return HttpResponseRedirect('/h/meetings/%s' % (int_to_base36(host_class.pk)))
            elif next == '1':
                return HttpResponseRedirect('/h/invite/%s/?next=1' % (int_to_base36(host_class.pk)))
            else:
                return HttpResponseRedirect('/h/v/%s/' % (int_to_base36(host_class.pk)))

        if not class_creater:
            ext_template = "host/base_edit.html"
        else:
            ext_template = "host/base.html"

        return render_to_response('host/edit_calendar.html', {
            'host_class': host_class, 'course': host_class.course, 'host_sessions':host_sessions, 'class_creater':class_creater,
            'ext_template': ext_template
            }, context_instance=RequestContext(request))
    else:
        return Http404
Esempio n. 4
0
 def create(self, host_class, sender, recipient, subject, body):
     from auxiliary import int_to_base36
     print 'creating ', host_class, sender, recipient, subject, body
     host_class_to_from = ','.join([int_to_base36(host_class.pk), sender.username, recipient.username])
     m, c = self.get_or_create(host_class_to_from=host_class_to_from)
     if c:
         message = Message(sender=sender,recipient=recipient,subject=subject,body=body)
         message.save()
         m.message=message
         m.save()
         print 'created', m
     return m
Esempio n. 5
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))
Esempio n. 6
0
def host_search(request):
    from classes.course_miners import youtube_playlist_to_data
    details = None
    if request.GET.has_key('q'):
        additional_vars = search_form(request.GET)
    if request.method == 'POST':
        course_form = MakeCourseForm(request.POST)
        if course_form.is_valid():
            clean_form = course_form.cleaned_data
            ci = CourseInfo(title=clean_form['title'], 
                    description=clean_form['description'], 
                    prereqs=clean_form['prerequisites'],
                    #from_date = course_form.cleaned_data['from_date'],
                    #course_number = course_form.cleaned_data['course_number'],
                    url = course_form.cleaned_data['url'])
            ci.save()
            try:
                if int(request.POST.get('links','0')) > 0:
                    course_data = youtube_playlist_to_data(clean_form['url'])
                    for i, entry in enumerate(course_data['links']):
                        title = entry.title.text    
                        if entry.location:
                            location = entry.location.text
                        content = entry.content.text
                        link = entry.link[0].href
                        session = Session(title=title, description=content, video_url=link)
                        session.save()
                        cis = CourseInfoSession(course_info=ci, session=session, session_number=i+1)
                        cis.save()
                        print 'session', session
            except: pass 
            ceditor = CourseInfoEditor(course_info=ci, editor=request.user, creator=True)
            ceditor.save()
            return HttpResponseRedirect('/h/create/%s/' % int_to_base36(ci.id))
    else:
        if request.GET.has_key('playlist_url'):
            course_data = youtube_playlist_to_data(request.GET.get('playlist_url', ''))
            course_form = MakeCourseForm(course_data)
            lenlinks = len(course_data['links'])
            details = mark_safe('This course has %d video lectures.  You can modify these in step 3.<input type="hidden" name="links" value="%s" />' % (lenlinks, lenlinks))
            if request.GET.has_key('a'):
                return render_to_response('host/incl/make_form.html', {'details': details, 'course_form': course_form}, context_instance=RequestContext(request))
        else:
            course_form = MakeCourseForm()
    render_vars = {'course_form': course_form, 
            'class_creater': True, 
            'playlist_url': request.GET.get('playlist_url', 'http://www.youtube.com/view_play_list?p=....')}
    if details:
        render_vars['details'] = details
    return render_to_response('host/make.html', render_vars, context_instance=RequestContext(request))
Esempio n. 7
0
def create_class(request):
    if request.method == 'POST':
        form = MakeCourseForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            description = form.cleaned_data['description']
            prereqs = form.cleaned_data['prerequisites']
            #from_date = form.cleaned_data['from_date']
            #institution = form.cleaned_data['institution']
            url = form.cleaned_data['url']
            #instructors = form.cleaned_data['instructors']
            new_ci = CourseInfo(title=title, description=description, prereqs=prereqs, url=url) 
            new_ci.save()
            ci_admin = CourseInfoEditor(editor=request.user, course_info=new_ci, creator=True)
            ci_admin.save()
            return HttpResponseRedirect('/c/edit/%s/' % (int_to_base36(new_ci.pk)))
    else:
        form = MakeCourseForm()
    #editors = course.editor.all()
    #editors = [editor.editor for editor in editors]
    return render_to_response('classes/edit.html', {'form': form, 'creating': True, }
        , context_instance=RequestContext(request))
Esempio n. 8
0
def create_class_from_playlist(request):
    course_info = youtube_playlist_to_course(request.GET['playlistbox'])
    return HttpResponseRedirect('/h/create/%s/' % (int_to_base36(course_info.pk)))
Esempio n. 9
0
 def b36(self):
     return int_to_base36(self.id)
Esempio n. 10
0
 def get_absolute_url(self):
     return "/h/v/%s/" % (int_to_base36(self.id))