Esempio n. 1
0
def publish_course(request, author, course):
	if request.method == 'POST' and request.user.is_authenticated():
		unique_id = request.POST.get('unique-id')
		try:
			course = Course.objects.get(unique_id__exact=unique_id)
			if request.user in course.author.all():
				me = request.user.get_profile()
				#post_course(me,course)
					
				msg = u'Tókst að birta áfanga'
				course.status = 2
				course.save()
			else:
				msg = u'Þú hefur ekki heimild til að birta þennan áfanga'
		except Exception as details:
			msg = u'Tókst ekki að birta áfanga. Hafið samband við kerfisstjóra'
			
		return_site = {'name':u'Samfélag', 'url':'/'}
		return render('message.html', {'msg':msg, 'return_site':return_site}, request)
	else:
		# Enough to get the first one
		user = author.split('-')[0]
		user_object = get_object_or_404(User, username=user)
		course_object = get_object_or_404(Course, author=user_object, name=course.upper())
		return render('curricula/publish_course.html', {'course':course_object}, request)
Esempio n. 2
0
def view_exemplary_course(request, id):
	try:
		exemplary = ExemplaryCourse.objects.get(course__unique_id=id)
		return render('curricula/view_exemplary_course.html', {'exemplary':exemplary}, request)
	except:
		return_site = {'name':u'Fyrirmyndaráfangar', 'url':reverse('list-exemplary-courses')}
		return render('message.html', {'msg':'Exemplary course not found', 'return_site':return_site}, request)
Esempio n. 3
0
def approve_course(request, author, course):
	if request.method == 'POST' and request.user.is_authenticated():
		unique_id = request.POST.get('unique-id')
		try:
			course = Course.objects.get(unique_id__exact=unique_id)
			if request.user.has_perm('approve_course'):
				if 'approve' in request.POST:	
					msg = u'Tókst að samþykkja áfanga'
					course.status = 3
					course.save()
				elif 'not-approved' in request.POST:
					msg = u'Áfanganum var hafnað'
					course.status = 5
					course.save()
			else:
				msg = u'Þú hefur ekki heimild til að samþykkja þennan áfanga'
		except Exception as details:
			msg = u'Tókst ekki að samþykkja áfanga. Hafið samband við kerfisstjóra'
			
		return_site = {'name':u'Samfélag', 'url':'/'}
		return render('message.html', {'msg':msg, 'return_site':return_site}, request)
	else:
		# Enough to get the first one
		user = author.split('-')[0]
		user_object = get_object_or_404(User, username=user)
		course_object = get_object_or_404(Course, author=user_object, name=course.upper())
		return render('curricula/approve_course.html', {'course':course_object}, request)
Esempio n. 4
0
def view_law(request, number=None):
	# Try to get the law based on the number (or just return the first
	# law of this site
	try:
		if number:
			law = Law.objects.get(number=number)
		else:
			law = Law.on_site.all()[1]
	except:
		return render('country/law.html', {}, request)

	# Return the law and the sections (might need to redo this rendering)
	return render('country/law.html', {'title':law.title, 'sections':law.section_set.all()}, request)
Esempio n. 5
0
def my_person(request):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/')

	profile = request.user.get_profile()
	if request.method == 'POST':
		profile_form = PersonForm(request.POST, instance=profile)
		if profile_form.is_valid():
			profile_form.save()
		else:
			print profile_form._errors
			render('community/my_person.html', {'profile':profile, 'form':profile_form}, request)	
	else:
		profile_form = PersonForm(instance=profile)

	return render('community/my_person.html', {'profile':profile, 'form':profile_form}, request)
Esempio n. 6
0
def new_stakeholder(request):
	if request.method == 'POST':
		form = StakeholderForm(request.POST)
		stakeholder = form.save()

		return HttpResponseRedirect(reverse('stakeholder', kwargs={'slug':stakeholder.slug}))

	ctx = {'title':'Nýr hagsmunaaðili', 'form': StakeholderForm()}
	return render('curricula/stakeholder_new.html', ctx, request)
Esempio n. 7
0
def group(request, group_id):
	try:
		group = Group.objects.get(atom_id=group_id)
	except:
		return list_groups(request)

	group_activities = ActivityEntry.objects.filter(target=group)[:25]

	return render('community/group.html', {'group':group, 'groupactivities':group_activities}, request)
Esempio n. 8
0
def view_course(request, id):
	course = get_object_or_404(Course, unique_id=id)
	if course.status == 1 and request.user != course.author:
		course = None
	
	if course:
		return render('curricula/course.html', {'course':course}, request)
	else:
		return HttpResponseRedirect('/')
Esempio n. 9
0
def search(request, tagstring=''):
    if request.method == 'GET':
        searchlist = []
        taglist = tagstring.split(' ')
        every_search = Search.objects.filter(tag__tag__in=taglist):
        for search in every_search:
            searchlist.extend([s for s in search.split(' ') if s != ''])

	return render('oer/search.html', {'tags':tagstring, searchcloud=cloudify(searchlist, ['tiny', 'small', 'normal', 'large', 'huge'])}, request)
Esempio n. 10
0
def new(request):
        if request.method == 'POST':
                form = EventForm(request.POST)
                event = form.save(commit=False)
		event.creator = request.user
                event.save()
                return HttpResponseRedirect('/')

	return render('community/new.html', {'title': 'Nýr viðburður', 'form':EventForm(),}, request)
Esempio n. 11
0
def search(request, tags=""):
    if request.method == "POST":
        searchstring = request.POST.get("search", "")
        searchqueries = [Q(title__icontains=s) for s in searchstring.split(" ")]
        q_query = searchqueries.pop()
        for searchquery in searchqueries:
            q_query |= searchquery

        taglist = [t.strip() for t in request.POST.get("tags", "").split(",")]
        results = ActivityConstruct.objects.filter(q_query & Q(tag_set__tag__in=taglist))
        return render("oer/search_results.html", {"search": searchstring, "tags": tags, "results": results}, request)

    else:
        searchlist = []
        taglist = [t.strip() for t in tags.split(",")]
        every_search = Search.objects.filter(tag__tag__in=taglist)

        # Create a search cloud
        for search in every_search:
            searchlist.extend([s for s in search.split(" ") if s != ""])

        sizes = ["tiny", "small", "normal", "large", "huge"]
        searchcloud = cloudify(searchlist, sizes)

        # Bottom feeders
        if request.user.is_authenticated():
            my_search = every_search.filter(searcher=request.user)[:5]
        else:
            my_search = []
        popular_search = every_search[:5]
        newest_content = ActivityEntry.objects.filter(activityobject__tag_set__tag__in=taglist).order_by("-time")[:5]
        print newest_content

        return render(
            "oer/search.html",
            {
                "tags": tags,
                "searchcloud": searchcloud,
                "personal": my_search,
                "popular": popular_search,
                "activity_entries": newest_content,
            },
            request,
        )
Esempio n. 12
0
def delete_course(request, id):
	if request.method == 'POST' and request.user.is_authenticated():
		if request.POST.get('unique-id'):
			try:
				course = Course.objects.get(unique_id__exact=id)
				if request.user in course.author.all():
					#course.delete()
					msg = _('Successfully deleted course')
				else:
					msg = _('You are not authorized to delete course')
			except:
				msg = _('Course not found')

			return_site = {'name':_('My courses'), 'url':reverse('my-courses')}
			return render('message.html', {'msg':msg, 'return_site':return_site}, request)

	else:
		course = get_object_or_404(Course, unique_id__exact=id)
		return render('curricula/delete_course.html', {'course':course}, request)
Esempio n. 13
0
def make_exemplary_course(request, id):
	if request.method == 'POST' and request.user.is_authenticated():
		try:
			course = Course.objects.get(unique_id__exact=id)
			if request.user.has_perms(['curricula.can_add_exemplarycourse']):
				form = ExemplaryCourseForm(request.POST)
				form.save()
				msg = _('Course has been made into an exemplary course')
			else:
				msg = _('User is not authorized to make this course exemplary')

		except Exception as details:
			msg = _('Course could not be made exemplary. Contact system administrator.')
			
		return_site = {'name':u'Fyrirmyndaráfangar', 'url':reverse('adminlist-exemplary-courses')}
		return render('message.html', {'msg':msg, 'return_site':return_site}, request)
	else:
		course_object = get_object_or_404(Course, unique_id__exact=id)
		return render('curricula/make_course_exemplary.html', {'course':course_object}, request)
Esempio n. 14
0
def personal(request, username):
	try:
		user = User.objects.get(username=username)
		# Why 25? - I have no idea -- need pagination?
		entries = ActivityEntry.objects.filter(actor=user.get_profile()).order_by('-time')[:25]
	except:
		entries = ActivityEntry.objects.all().order_by('-time')[:25]

	# Events - why 10? I also have no idea
	today = datetime.date.today()
	events = Event.objects.filter(start_date__gte=today).order_by('-start_date')[:10]
	return render('community/timeline.html', {'content':entries, 'events':events}, request)
Esempio n. 15
0
def list_feeds(request, area=None, level=None):
    try:
        # Try to get the specific area according to the slug
        country_area = CountryArea.objects.get(slug=area)
    except:
	# If we fail, we mark it as none (we're getting all of them)
	country_area = None

    (schools, school_level, color) = _get_schools(area, level)
    posts = Post.objects.filter(feed__schoolinformation__school__in=schools)

    return render('schools/feeds.html', {'school_feeds':posts}, request)
Esempio n. 16
0
def register(request):
        if request.method == 'POST':
                try:
                        form = RegisterForm(request.POST)
                        new_user = form.save()
                        user = auth.authenticate(username=request.POST.get('username'), password=request.POST.get('password1'))
                        if user is not None and user.is_active:
                                auth.login(request, user)
                                return HttpResponseRedirect('/')
                except:
                        pass

        return render('users/register.html', {'form':RegisterForm()}, request)
Esempio n. 17
0
def list_empty(request):
	menu_items = Menu.on_site.all().order_by('url')
	empty = []
	for menu_item in menu_items:
		try:
			match = resolve(menu_item.url)
		except:	
			try:
				FlatPage.objects.get(url=menu_item.url)
			except:
				empty.append({'title':menu_item.title,
					      'url':reverse('modify-page', kwargs={'url':menu_item.url}),})

	return render('management/url_list.html', {'title':'Efnislausar síður' ,'list':empty}, request)
Esempio n. 18
0
def create_highlight(request):
        if request.method == 'POST':
                form = HighlightForm(request.POST)
		highlight = form.save(commit=False)
		highlight.order = 0
		highlight.save()
		form.save_m2m()
		
		try:
	                return HttpResponseRedirect(highligt.pages.all()[0])
		except:
			return HttpResponseRedirect('/')
        
        return render('management/new.html', {'title':'Nýr hliðarreitur', 'form':HighlightForm(),}, request)
Esempio n. 19
0
def create_flatpage(request, url):
        if request.method == 'POST':
                form = PartialFlatPageForm(request.POST)
		page = form.save(commit=False)
		page.enable_comments = False
		page.registration_required = False
		page.content = markdown.markdown(page.content)
		page.url = url
		page.save()
		page.sites.add(Site.objects.get_current())
		form.save_m2m()

                return HttpResponseRedirect(url)
        
        return render('management/new.html', {'title':'Síðuskrif', 'form':PartialFlatPageForm(),}, request)
Esempio n. 20
0
def list_feedbacks(request):
	if request.method == 'POST':
		form = FeedbackForm(request.POST)
		if form.is_valid():
			feedback = form.save(commit=False)
			feedback.author = request.user
			feedback.save()

	feedbacks = Feedback.objects.all().order_by('-published')
	feedback_list = []
	for feedback in feedbacks:
		feedback_list.append({'feedback':feedback, 'commentform': CommentForm(initial={'feedback':feedback})})

	new_feedback = FeedbackForm()

	return render('feedback/feedback_list.html', {'feedback':feedback_list, 'form':new_feedback}, request)
Esempio n. 21
0
def list_private_messages(request, postbox='all'):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/')
	else:
		profile = request.user.get_profile()
	
	if postbox == 'outbox':
		outbox = PrivateMessage.objects.filter(sender=profile)
		inbox = None
	elif postbox == 'inbox':
		inbox = PrivateMessage.objects.filter(recipient=profile)
		outbox = None
	else:
		inbox = PrivateMessage.objects.filter(recipient=profile)
		outbox = PrivateMessage.objects.filter(sender=profile)

	return render('community/private_messages.html', {'inbox':inbox, 'outbox':outbox}, request)
Esempio n. 22
0
def create_group(request):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/')

	if request.method == 'POST':
		form = GroupForm(request.POST)
		if form.is_valid():
			group = form.save(commit=False)
			group.creator = request.user.get_profile()
			group.avatar = 'http://mrn.pagekite.me/media/icons/groups.jpg'
			group.save()
			request.user.get_profile().groups.add(group)
			return HttpResponseRedirect('/')
	else:
		form = GroupForm()

	return render('community/form.html', {'title':'Create a new group', 'form':form}, request)
Esempio n. 23
0
def join_group(request):
	if not request.user.is_authenticated() or not request.method == 'POST':
		return HttpResponseRedirect('/')

	group_id = request.POST.get('group', None)
	if group_id:
		try:
			group = Group.objects.get(atom_id=group_id)

			person = request.user.get_profile()
			person.groups.add(group)
			person.join(group)

			group_activities = ActivityEntry.objects.filter(target=group)[:25]
			return render('community/group.html', {'group':group, 'groupactivities':group_activities}, request)
		except:
			pass

	return HttpResponseRedirect('/')
Esempio n. 24
0
def index(request, username=None, construct=None):
	entries = ActivityEntry.objects.all()
	constructs = []
	if construct:
		if construct == 'notes':
			entries = entries.filter(activityobject__in=Note.objects.all())
		elif construct == 'articles':
			entries = entries.filter(activityobject__in=Article.objects.all())
		elif construct == 'photos':
			entries = entries.filter(activityobject__in=Photo.objects.all())
		if construct == 'videos':
			entries = entries.filter(activityobject__in=Video.objects.all())
		elif construct == 'audio':
			entries = entries.filter(activityobject__in=Audio.objects.all())
		elif construct == 'bookmarks':
			entries = entries.filter(activityobject__in=Bookmark.objects.all())
		elif construct == 'files':
			entries = entries.filter(activityobject__in=File.objects.all())
		else:
			pass

	vieweduser=request.user

	if username:
		try:
			vieweduser = User.objects.get(username=username)
			entries = entries.filter(actor=vieweduser.get_profile())
		except:
			pass

	# Events - why 10? I also have idea
	today = datetime.date.today()
	events = Event.objects.filter(start_date__gte=today).order_by('-start_date')[:10]

	# Nor do I have idea why 25 is the magic number
	sortable_list = [e for e in entries.exclude(verb='http://activitystrea.ms/schema/1.0/update').order_by('-time')[:25]]
	if request.user.is_authenticated():
		sortable_list.sort(lambda a,b: -1*cmp(a.activityobject.updated if a.actor == request.user.get_profile() else a.time, b.activityobject.updated if b.actor == request.user.get_profile() else b.time))

	return render('community/timeline.html', {'vieweduser':vieweduser, 'content':sortable_list, 'events':events}, request)
Esempio n. 25
0
def list_schools(request, area=None, level=None):
    # Get all areas into a variable (for the map)
    country_areas = CountryArea.objects.all()

    try:
        # Try to get the specific area according to the slug
        country_area = country_areas.get(slug=area)
    except:
	# If we fail, we mark it as none
	country_area = None

    # Get all schools within the given area (or the country if area is None)
    (schools, school_level, color) = _get_schools(country_area, level)

    # Set the title according to the school_level and area
    if country_area:
        title = _(u'%(schools)s in %(area)s') % {'schools':school_level.capitalize(), 'area':country_area.name}
    else:
        title = _(u'All %(schools)s in the country') % {'schools':school_level}

    # Render the template along with a selected area and all areas
    return render('schools/list.html', {'title':title, 'selected_area':country_area, 'areas':country_areas, 'base_color':color, 'schools':schools}, request)
Esempio n. 26
0
def school_info(request, school):
    # Base color of map
    color = None

    # Try to get the school according to the schools slug
    try:
        school = School.objects.get(slug=school)
    except:
        return render('schools/info.html', {}, request)

    # Try to find the school level to set the appropriate color
    # Django does not handle subclasses optimally so this will be ugly and
    # repetitive (I know, I know DRY)

    # Get country areas for the map
    country_areas = CountryArea.objects.all()
    selected_area = school.municipality.area

    try:
        return render('schools/info.html',
                      {'school':school.preschool,
                       'base_color':settings.PRESCHOOL_COLOR,
                       'type':'preschool',
                       'areas':country_areas,
                       'selected_area':selected_area}, request)
    except:
        pass

    try:
        return render('schools/info.html',
                      {'school':school.primaryschool,
                       'base_color':settings.PRIMARY_SCHOOL_COLOR,
                       'type':'primaryschool',
                       'areas':country_areas,
                       'selected_area':selected_area}, request)
    except:
        pass

    try:
        return render('schools/info.html',
                      {'school':school.secondaryschool,
                       'base_color':settings.SECONDARY_SCHOOL_COLOR,
                       'type':'secondaryschool',
                       'areas':country_areas,
                       'selected_area':selected_area}, request)
    except:
        pass

    try:
        return render('schools/info.html',
                      {'school':school.university,
                       'base_color':settings.UNIVERSITY_COLOR,
                       'type':'university',
                       'areas':country_areas,
                       'selected_area':selected_area}, request)
    except:
        pass

    try:
        return render('schools/info.html',
                      {'school':school.learningcenter,
                       'base_color':settings.SECONDARY_SCHOOL_COLOR,
                       'type':'learningcenter',
                       'areas':country_areas,
                       'selected_area':selected_area}, request)
    except:
        pass

    # Render the template with the areas and the school and no particular color
    return render('schools/info.html', {'areas':country_areas, 'selected_area':selected_area, 'school':school}, request)
Esempio n. 27
0
def tags(request,tag):
	return render('social.html', {}, request)
Esempio n. 28
0
def social(request):
        return render('social.html', {}, request)
Esempio n. 29
0
def list_areas(request, color=None):
    return render('country/areas.html', {'areas':CountryArea.objects.all(), 'scale_map':2, 'base_color':color}, request)
Esempio n. 30
0
def single(request, slug):
	events = Event.objects.filter(slug=slug)
	return render('community/event_list.html', event_list(events,request), request)