status=403
)
- comment = MediaComment(author=request.user.id)
+ comment = MediaComment(actor=request.user.id)
comment.unserialize(data["object"], request)
comment.save()
status=404
)
- if media.uploader != request.user.id:
+ if media.actor != request.user.id:
return json_error(
"Privilege 'commenter' required to comment.",
status=403
# Check that the person trying to update the comment is
# the author of the comment.
- if comment.author != request.user.id:
+ if comment.actor != request.user.id:
return json_error(
"Only author of comment is able to update comment.",
status=403
# Check that the person trying to update the comment is
# the author of the comment.
- if image.uploader != request.user.id:
+ if image.actor != request.user.id:
return json_error(
"Only uploader of image is able to update image.",
status=403
# Find the comment asked for
comment = MediaComment.query.filter_by(
id=obj_id,
- author=request.user.id
+ actor=request.user.id
).first()
if comment is None:
# Find the image
entry = MediaEntry.query.filter_by(
id=obj_id,
- uploader=request.user.id
+ actor=request.user.id
).first()
if entry is None:
)
return redirect(request, location=profile)
-
-
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
# Commit the changes
db.commit()
+
+@RegisterMigration(37, MIGRATIONS)
+def federation_collection_schema(db):
+ """ Converts the Collection and CollectionItem """
+ metadata = MetaData(bind=db.bind)
+ collection_table = inspect_table(metadata, "core__collections")
+ collection_items_table = inspect_table(metadata, "core__collection_items")
+ media_entry_table = inspect_table(metadata, "core__media_entries")
+ gmr_table = inspect_table(metadata, "core__generic_model_reference")
+
+ ##
+ # Collection Table
+ ##
+
+ # Add the fields onto the Collection model, we need to set these as
+ # not null to avoid DB integreity errors. We will add the not null
+ # constraint later.
+ updated_column = Column(
+ "updated",
+ DateTime,
+ default=datetime.datetime.utcnow
+ )
+ updated_column.create(collection_table)
+
+ type_column = Column(
+ "type",
+ Unicode,
+ )
+ type_column.create(collection_table)
+
+ db.commit()
+
+ # Iterate over the items and set the updated and type fields
+ for collection in db.execute(collection_table.select()):
+ db.execute(collection_table.update().where(
+ collection_table.c.id==collection.id
+ ).values(
+ updated=collection.created,
+ type="core-user-defined"
+ ))
+
+ db.commit()
+
+ # Add the not null constraint onto the fields
+ updated_column = collection_table.columns["updated"]
+ updated_column.alter(nullable=False)
+
+ type_column = collection_table.columns["type"]
+ type_column.alter(nullable=False)
+
+ db.commit()
+
+ # Rename the "items" to "num_items" as per the TODO
+ num_items_field = collection_table.columns["items"]
+ num_items_field.alter(name="num_items")
+ db.commit()
+
+ ##
+ # CollectionItem
+ ##
+ # Adding the object ID column, this again will have not null added later.
+ object_id = Column(
+ "object_id",
+ Integer,
+ ForeignKey(GenericModelReference_V0.id),
+ )
+ object_id.create(
+ collection_items_table,
+ )
+
+ db.commit()
+
+ # Iterate through and convert the Media reference to object_id
+ for item in db.execute(collection_items_table.select()):
+ # Check if there is a GMR for the MediaEntry
+ object_gmr = db.execute(gmr_table.select(
+ and_(
+ gmr_table.c.obj_pk == item.media_entry,
+ gmr_table.c.model_type == "core__media_entries"
+ )
+ )).first()
+
+ if object_gmr:
+ object_gmr = object_gmr[0]
+ else:
+ # Create a GenericModelReference
+ object_gmr = db.execute(gmr_table.insert().values(
+ obj_pk=item.media_entry,
+ model_type="core__media_entries"
+ )).inserted_primary_key[0]
+
+ # Now set the object_id column to the ID of the GMR
+ db.execute(collection_items_table.update().where(
+ collection_items_table.c.id==item.id
+ ).values(
+ object_id=object_gmr
+ ))
+
+ db.commit()
+
+ # Add not null constraint
+ object_id = collection_items_table.columns["object_id"]
+ object_id.alter(nullable=False)
+
+ db.commit()
+
+ # Now remove the old media_entry column
+ media_entry_column = collection_items_table.columns["media_entry"]
+ media_entry_column.drop()
+
+ db.commit()
+
+@RegisterMigration(38, MIGRATIONS)
+def federation_actor(db):
+ """ Renames refereces to the user to actor """
+ metadata = MetaData(bind=db.bind)
+
+ # RequestToken: user -> actor
+ request_token_table = inspect_table(metadata, "core__request_tokens")
+ rt_user_column = request_token_table.columns["user"]
+ rt_user_column.alter(name="actor")
+
+ # AccessToken: user -> actor
+ access_token_table = inspect_table(metadata, "core__access_tokens")
+ at_user_column = access_token_table.columns["user"]
+ at_user_column.alter(name="actor")
+
+ # MediaEntry: uploader -> actor
+ media_entry_table = inspect_table(metadata, "core__media_entries")
+ me_user_column = media_entry_table.columns["uploader"]
+ me_user_column.alter(name="actor")
+
+ # MediaComment: author -> actor
+ media_comment_table = inspect_table(metadata, "core__media_comments")
+ mc_user_column = media_comment_table.columns["author"]
+ mc_user_column.alter(name="actor")
+
+ # Collection: creator -> actor
+ collection_table = inspect_table(metadata, "core__collections")
+ mc_user_column = collection_table.columns["creator"]
+ mc_user_column.alter(name="actor")
+
+ # commit changes to db.
+ db.commit()
# (db.models -> db.mixin -> db.util -> db.models)
from mediagoblin.db.util import check_media_slug_used
- return check_media_slug_used(self.uploader, slug, self.id)
+ return check_media_slug_used(self.actor, slug, self.id)
@property
def object_type(self):
Use a slug if we have one, else use our 'id'.
"""
- uploader = self.get_uploader
+ uploader = self.get_actor
return urlgen(
'mediagoblin.user_pages.media_home',
return cleaned_markdown_conversion(self.content)
def __unicode__(self):
- return u'<{klass} #{id} {author} "{comment}">'.format(
+ return u'<{klass} #{id} {actor} "{comment}">'.format(
klass=self.__class__.__name__,
id=self.id,
- author=self.get_author,
+ actor=self.get_actor,
comment=self.content)
def __repr__(self):
- return '<{klass} #{id} {author} "{comment}">'.format(
+ return '<{klass} #{id} {actor} "{comment}">'.format(
klass=self.__class__.__name__,
id=self.id,
- author=self.get_author,
+ actor=self.get_actor,
comment=self.content)
# (db.models -> db.mixin -> db.util -> db.models)
from mediagoblin.db.util import check_collection_slug_used
- return check_collection_slug_used(self.creator, slug, self.id)
+ return check_collection_slug_used(self.actor, slug, self.id)
@property
def description_html(self):
Use a slug if we have one, else use our 'id'.
"""
- creator = self.get_creator
+ creator = self.get_actor
return urlgen(
'mediagoblin.user_pages.user_collection',
from sqlalchemy.orm import relationship, backref, with_polymorphic, validates, \
class_mapper
from sqlalchemy.orm.collections import attribute_mapped_collection
+from sqlalchemy.sql import and_
from sqlalchemy.sql.expression import desc
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.util import memoized_property
"""Deletes a User and all related entries/comments/files/..."""
# Collections get deleted by relationships.
- media_entries = MediaEntry.query.filter(MediaEntry.uploader == self.id)
+ media_entries = MediaEntry.query.filter(MediaEntry.actor == self.id)
for media in media_entries:
# TODO: Make sure that "MediaEntry.delete()" also deletes
# all related files/Comments
token = Column(Unicode, primary_key=True)
secret = Column(Unicode, nullable=False)
client = Column(Unicode, ForeignKey(Client.id))
- user = Column(Integer, ForeignKey(User.id), nullable=True)
+ actor = Column(Integer, ForeignKey(User.id), nullable=True)
used = Column(Boolean, default=False)
authenticated = Column(Boolean, default=False)
verifier = Column(Unicode, nullable=True)
token = Column(Unicode, nullable=False, primary_key=True)
secret = Column(Unicode, nullable=False)
- user = Column(Integer, ForeignKey(User.id))
+ actor = Column(Integer, ForeignKey(User.id))
request_token = Column(Unicode, ForeignKey(RequestToken.token))
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
public_id = Column(Unicode, unique=True, nullable=True)
remote = Column(Boolean, default=False)
- uploader = Column(Integer, ForeignKey(User.id), nullable=False, index=True)
+ actor = Column(Integer, ForeignKey(User.id), nullable=False, index=True)
title = Column(Unicode, nullable=False)
slug = Column(Unicode)
description = Column(UnicodeText) # ??
queued_task_id = Column(Unicode)
__table_args__ = (
- UniqueConstraint('uploader', 'slug'),
+ UniqueConstraint('actor', 'slug'),
{})
- get_uploader = relationship(User)
+ get_actor = relationship(User)
media_files_helper = relationship("MediaFile",
collection_class=attribute_mapped_collection("name"),
creator=lambda v: MediaTag(name=v["name"], slug=v["slug"])
)
- collections_helper = relationship("CollectionItem",
- cascade="all, delete-orphan"
- )
- collections = association_proxy("collections_helper", "in_collection")
media_metadata = Column(MutationDict.as_mutable(JSONEncoded),
default=MutationDict())
## TODO
# fail_error
+ @property
+ def collections(self):
+ """ Get any collections that this MediaEntry is in """
+ return list(Collection.query.join(Collection.collection_items).join(
+ CollectionItem.object_helper
+ ).filter(
+ and_(
+ GenericModelReference.model_type == self.__tablename__,
+ GenericModelReference.obj_pk == self.id
+ )
+ ))
+
def get_comments(self, ascending=False):
order_col = MediaComment.created
if not ascending:
def url_to_prev(self, urlgen):
"""get the next 'newer' entry by this user"""
media = MediaEntry.query.filter(
- (MediaEntry.uploader == self.uploader)
+ (MediaEntry.actor == self.actor)
& (MediaEntry.state == u'processed')
& (MediaEntry.id > self.id)).order_by(MediaEntry.id).first()
def url_to_next(self, urlgen):
"""get the next 'older' entry by this user"""
media = MediaEntry.query.filter(
- (MediaEntry.uploader == self.uploader)
+ (MediaEntry.actor == self.actor)
& (MediaEntry.state == u'processed')
& (MediaEntry.id < self.id)).order_by(desc(MediaEntry.id)).first()
except OSError as error:
# Returns list of files we failed to delete
_log.error('No such files from the user "{1}" to delete: '
- '{0}'.format(str(error), self.get_uploader))
+ '{0}'.format(str(error), self.get_actor))
_log.info('Deleted Media entry id "{0}"'.format(self.id))
# Related MediaTag's are automatically cleaned, but we might
# want to clean out unused Tag's too.
def serialize(self, request, show_comments=True):
""" Unserialize MediaEntry to object """
- author = self.get_uploader
+ author = self.get_actor
published = UTC.localize(self.created)
updated = UTC.localize(self.updated)
public_id = self.get_public_id(request)
id = Column(Integer, primary_key=True)
media_entry = Column(
Integer, ForeignKey(MediaEntry.id), nullable=False, index=True)
- author = Column(Integer, ForeignKey(User.id), nullable=False)
+ actor = Column(Integer, ForeignKey(User.id), nullable=False)
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
content = Column(UnicodeText, nullable=False)
location = Column(Integer, ForeignKey("core__locations.id"))
# Cascade: Comments are owned by their creator. So do the full thing.
# lazy=dynamic: People might post a *lot* of comments,
# so make the "posted_comments" a query-like thing.
- get_author = relationship(User,
+ get_actor = relationship(User,
backref=backref("posted_comments",
lazy="dynamic",
cascade="all, delete-orphan"))
qualified=True
)
media = MediaEntry.query.filter_by(id=self.media_entry).first()
- author = self.get_author
+ author = self.get_actor
published = UTC.localize(self.created)
context = {
"id": href,
class Collection(Base, CollectionMixin):
- """An 'album' or 'set' of media by a user.
+ """A representation of a collection of objects.
+
+ This holds a group/collection of objects that could be a user defined album
+ or their inbox, outbox, followers, etc. These are always ordered and accessable
+ via the API and web.
+
+ The collection has a number of types which determine what kind of collection
+ it is, for example the users inbox will be of `Collection.INBOX_TYPE` that will
+ be stored on the `Collection.type` field. It's important to set the correct type.
On deletion, contained CollectionItems get automatically reaped via
SQL cascade"""
slug = Column(Unicode)
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow,
index=True)
+ updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
description = Column(UnicodeText)
- creator = Column(Integer, ForeignKey(User.id), nullable=False)
+ actor = Column(Integer, ForeignKey(User.id), nullable=False)
+ num_items = Column(Integer, default=0)
+
+ # There are lots of different special types of collections in the pump.io API
+ # for example: followers, following, inbox, outbox, etc. See type constants
+ # below the fields on this model.
+ type = Column(Unicode, nullable=False)
+
+ # Location
location = Column(Integer, ForeignKey("core__locations.id"))
get_location = relationship("Location", lazy="joined")
- # TODO: No of items in Collection. Badly named, can we migrate to num_items?
- items = Column(Integer, default=0)
-
# Cascade: Collections are owned by their creator. So do the full thing.
- get_creator = relationship(User,
+ get_actor = relationship(User,
backref=backref("collections",
cascade="all, delete-orphan"))
-
__table_args__ = (
- UniqueConstraint('creator', 'slug'),
+ UniqueConstraint('actor', 'slug'),
{})
+ # These are the types, It's strongly suggested if new ones are invented they
+ # are prefixed to ensure they're unique from other types. Any types used in
+ # the main mediagoblin should be prefixed "core-"
+ INBOX_TYPE = "core-inbox"
+ OUTBOX_TYPE = "core-outbox"
+ FOLLOWER_TYPE = "core-followers"
+ FOLLOWING_TYPE = "core-following"
+ USER_DEFINED_TYPE = "core-user-defined"
+
def get_collection_items(self, ascending=False):
#TODO, is this still needed with self.collection_items being available?
order_col = CollectionItem.position
def __repr__(self):
safe_title = self.title.encode('ascii', 'replace')
- return '<{classname} #{id}: {title} by {creator}>'.format(
+ return '<{classname} #{id}: {title} by {actor}>'.format(
id=self.id,
classname=self.__class__.__name__,
- creator=self.creator,
+ actor=self.actor,
title=safe_title)
def serialize(self, request):
# Get all serialized output in a list
- items = []
- for item in self.get_collection_items():
- items.append(item.serialize(request))
-
+ items = [i.serialize(request) for i in self.get_collection_items()]
return {
"totalItems": self.items,
"url": self.url_for_self(request.urlgen, qualified=True),
__tablename__ = "core__collection_items"
id = Column(Integer, primary_key=True)
- media_entry = Column(
- Integer, ForeignKey(MediaEntry.id), nullable=False, index=True)
+
collection = Column(Integer, ForeignKey(Collection.id), nullable=False)
note = Column(UnicodeText, nullable=True)
added = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
position = Column(Integer)
-
# Cascade: CollectionItems are owned by their Collection. So do the full thing.
in_collection = relationship(Collection,
backref=backref(
"collection_items",
cascade="all, delete-orphan"))
- get_media_entry = relationship(MediaEntry)
+ # Link to the object (could be anything.
+ object_id = Column(
+ Integer,
+ ForeignKey(GenericModelReference.id),
+ nullable=False,
+ index=True
+ )
+ object_helper = relationship(
+ GenericModelReference,
+ foreign_keys=[object_id]
+ )
+ get_object = association_proxy(
+ "object_helper",
+ "get_object",
+ creator=GenericModelReference.find_or_new
+ )
__table_args__ = (
- UniqueConstraint('collection', 'media_entry'),
+ UniqueConstraint('collection', 'object_id'),
{})
@property
return DictReadAttrProxy(self)
def __repr__(self):
- return '<{classname} #{id}: Entry {entry} in {collection}>'.format(
+ return '<{classname} #{id}: Object {obj} in {collection}>'.format(
id=self.id,
classname=self.__class__.__name__,
collection=self.collection,
- entry=self.media_entry)
+ obj=self.get_object()
+ )
def serialize(self, request):
- return self.get_media_entry.serialize(request)
+ return self.get_object().serialize(request)
class ProcessingMetaData(Base):
def check_media_slug_used(uploader_id, slug, ignore_m_id):
- query = MediaEntry.query.filter_by(uploader=uploader_id, slug=slug)
+ query = MediaEntry.query.filter_by(actor=uploader_id, slug=slug)
if ignore_m_id is not None:
query = query.filter(MediaEntry.id != ignore_m_id)
does_exist = query.first() is not None
def check_collection_slug_used(creator_id, slug, ignore_c_id):
- filt = (Collection.creator == creator_id) \
+ filt = (Collection.actor == creator_id) \
& (Collection.slug == slug)
if ignore_c_id is not None:
filt = filt & (Collection.id != ignore_c_id)
"""
@wraps(controller)
def wrapper(request, *args, **kwargs):
- uploader_id = kwargs['media'].uploader
+ uploader_id = kwargs['media'].actor
if not (request.user.has_privilege(u'admin') or
request.user.id == uploader_id):
raise Forbidden()
media = MediaEntry.query.filter_by(
id=int(media_slug[3:]),
state=u'processed',
- uploader=user.id).first()
+ actor=user.id).first()
except ValueError:
raise NotFound()
else:
media = MediaEntry.query.filter_by(
slug=media_slug,
state=u'processed',
- uploader=user.id).first()
+ actor=user.id).first()
if not media:
# Didn't find anything? Okay, 404.
collection = request.db.Collection.query.filter_by(
slug=request.matchdict['collection'],
- creator=user.id).first()
+ actor=user.id).first()
# Still no collection? Okay, 404.
if not collection:
return render_404(request)
given_username = request.matchdict.get('user')
- if given_username and (given_username != media.get_uploader.username):
+ if given_username and (given_username != media.get_actor.username):
return render_404(request)
return controller(request, media=media, *args, **kwargs)
def may_edit_media(request, media):
"""Check, if the request's user may edit the media details"""
- if media.uploader == request.user.id:
+ if media.actor == request.user.id:
return True
if request.user.has_privilege(u'admin'):
return True
# Make sure there isn't already a MediaEntry with such a slug
# and userid.
slug = slugify(form.slug.data)
- slug_used = check_media_slug_used(media.uploader, slug, media.id)
+ slug_used = check_media_slug_used(media.actor, slug, media.id)
if slug_used:
form.slug.errors.append(
if request.method == 'POST' and form.validate():
# Make sure there isn't already a Collection with such a slug
# and userid.
- slug_used = check_collection_slug_used(collection.creator,
+ slug_used = check_collection_slug_used(collection.actor,
form.slug.data, collection.id)
# Make sure there isn't already a Collection with this title
existing_collection = request.db.Collection.query.filter_by(
- creator=request.user.id,
+ actor=request.user.id,
title=form.title.data).first()
if existing_collection and existing_collection.id != collection.id:
return redirect_obj(request, collection)
if request.user.has_privilege(u'admin') \
- and collection.creator != request.user.id \
+ and collection.actor != request.user.id \
and request.method != 'POST':
messages.add_message(
request, messages.WARNING,
objects_dict[media_id] = (line_dict)
return objects_dict
-
entry.description_html,
id=entry.url_for_self(request.urlgen,qualified=True),
content_type='html',
- author={'name': entry.get_uploader.username,
+ author={'name': entry.get_actor.username,
'uri': request.urlgen(
'mediagoblin.user_pages.user_home',
- qualified=True, user=entry.get_uploader.username)},
+ qualified=True, user=entry.get_actor.username)},
updated=entry.get('created'),
links=[{
'href':entry.url_for_self(
@require_active_login
def blog_edit(request):
"""
- View for editing an existing blog or creating a new blog
+ View for editing an existing blog or creating a new blog
if user have not exceeded maximum allowed acount of blogs.
"""
url_user = request.matchdict.get('user', None)
@require_active_login
def blogpost_edit(request):
-
+
blog_slug = request.matchdict.get('blog_slug', None)
blog_post_slug = request.matchdict.get('blog_post_slug', None)
'blog_owner': url_user,
'blog':blog
})
-
+
@require_active_login
def draft_view(request):
_("The blog was not deleted because you have no rights."))
return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
user=request.user.username)
-
-
+
+
def blog_about_view(request):
"""
Page containing blog description and statistics
"""
blog_slug = request.matchdict.get('blog_slug', None)
url_user = request.matchdict.get('user', None)
-
+
user = request.db.User.query.filter(
LocalUser.username=url_user
- ).first()
+ ).first()
blog = get_blog_by_slug(request, blog_slug, author=user.id)
-
+
if not user or not blog:
return render_404(request)
-
+
else:
blog_posts_processed = blog.get_all_blog_posts(u'processed').count()
return render_to_response(
'blog': blog,
'blogpost_count': blog_posts_processed
})
-
-
-
-
-
-
-
-
if not subscription.notify:
continue
- if comment.get_author == subscription.user:
+ if comment.get_actor == subscription.user:
continue
cn = CommentNotification(
comment_url = request.urlgen(
'mediagoblin.user_pages.media_home.view_comment',
comment=comment.id,
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id,
qualified=True) + '#comment'
- comment_author = comment.get_author.username
+ comment_author = comment.get_actor.username
rendered_email = render_template(
request, 'mediagoblin/user_pages/comment_email.txt',
to views.
'''
return {
- 'user': entry.get_uploader.username,
- 'user_id': entry.get_uploader.id,
- 'user_bio': entry.get_uploader.bio,
- 'user_bio_html': entry.get_uploader.bio_html,
+ 'user': entry.get_actor.username,
+ 'user_id': entry.get_actor.id,
+ 'user_bio': entry.get_actor.bio,
+ 'user_bio_html': entry.get_actor.bio_html,
'user_permalink': urlgen('mediagoblin.user_pages.user_home',
- user=entry.get_uploader.username,
+ user=entry.get_actor.username,
qualified=True),
'id': entry.id,
'created': entry.created.isoformat(),
{% if not media_feature %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.media_feature',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}"
class="button_action" id="button_featuremedia" title="{% trans %}
Feature Media {% endtrans %}">
{% else %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.media_unfeature',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}"
class="button_action" id="button_unfeaturemedia" title="{% trans %}
Unfeature Media {% endtrans %}">
{% if not media_feature.display_type == 'primary' %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.feature_promote',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}"
class="button_action" id="button_promotefeature" title="{% trans %}
Promote Feature {% endtrans %}">
{% endif %}{% if not media_feature.display_type == 'tertiary' %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.feature_demote',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}"
class="button_action" id="button_demotefeature" title="{% trans %}
Demote Feature {% endtrans %}">
LocalUser.username==uploader_username
).first()
media = MediaEntry.query.filter(
- MediaEntry.get_uploader == uploader ).filter(
+ MediaEntry.get_actor == uploader ).filter(
MediaEntry.slug == slug).first()
return media
for feature in feature_list:
media_entry = feature.media_entry
output_text += u'/u/{uploader_username}/m/{media_slug}/\n'.format(
- uploader_username = media_entry.get_uploader.username,
+ uploader_username = media_entry.get_actor.username,
media_slug = media_entry.slug)
{% endif %}
{% if request.user and request.user.has_privilege('admin') %}
<a href="{{ request.urlgen('mediagoblin.edit.metadata',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media_id=media.id) }}">
{% trans %}Edit Metadata{% endtrans %}</a>
{% endif %}
if request.user:
collections = Collection.query.filter_by(
- get_creator=request.user).order_by(Collection.title)
+ get_actor=request.user).order_by(Collection.title)
for c in collections:
catlist.append({'id': c.id,
collection_id = form.category.data
if collection_id > 0:
collection = Collection.query.get(collection_id)
- if collection is not None and collection.creator == request.user.id:
+ if collection is not None and collection.actor == request.user.id:
add_media_to_collection(collection, entry, "")
return {
Create a new MediaEntry for uploading
"""
entry = MediaEntry()
- entry.uploader = user.id
+ entry.actor = user.id
entry.license = user.license_preference
return entry
add_comment_subscription(user, entry)
# Create activity
- create_activity("post", entry, entry.uploader)
+ create_activity("post", entry, entry.actor)
entry.save()
# Pass off to processing
activity = create_activity(
verb="post",
obj=entry,
- actor=entry.uploader,
+ actor=entry.actor,
generator=create_generator(request)
)
entry.save()
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.edit.attachments',
- user= media.get_uploader.username,
+ user= media.get_actor.username,
media_id=media.id) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box">
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.edit.edit_media',
- user= media.get_uploader.username,
+ user= media.get_actor.username,
media_id=media.id) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box_xl edit_box">
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.edit.edit_collection',
- user= collection.get_creator.username,
+ user= collection.get_actor.username,
collection= collection.slug) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box_xl edit_box">
</div>
</form>
-{% endblock %}
+{% endblock %}
<ul>
{% for notification in notifications %}
{% set comment = notification.subject %}
- {% set comment_author = comment.get_author %}
+ {% set comment_author = comment.get_actor %}
{% set media = comment.get_entry %}
<li class="comment_wrapper">
<div class="comment_author">
</a>
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
comment=comment.id,
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}#comment"
class="comment_whenlink">
<span title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
</li>
{% endfor %}
</ul>
- <a href="{{ request.urlgen('mediagoblin.notifications.mark_all_comment_notifications_seen') }}?next={{
+ <a href="{{ request.urlgen('mediagoblin.notifications.mark_all_comment_notifications_seen') }}?next={{
request.base_url|urlencode }}" id="mark_all_comments_seen">
{% trans %}Mark all read{% endtrans %}
</a>
{% for media_entry in processing_entries %}
<tr>
<td>{{ media_entry.id }}</td>
- <td>{{ media_entry.get_uploader.username }}</td>
+ <td>{{ media_entry.get_actor.username }}</td>
<td>{{ media_entry.title }}</td>
<td>{{ media_entry.created.strftime("%F %R") }}</td>
{% if media_entry.transcoding_progress %}
{% for media_entry in failed_entries %}
<tr>
<td>{{ media_entry.id }}</td>
- <td>{{ media_entry.get_uploader.username }}</td>
+ <td>{{ media_entry.get_actor.username }}</td>
<td>{{ media_entry.title }}</td>
<td>{{ media_entry.created.strftime("%F %R") }}</td>
{% if media_entry.get_fail_exception() %}
{% for media_entry in processed_entries %}
<tr>
<td>{{ media_entry.id }}</td>
- <td>{{ media_entry.get_uploader.username }}</td>
+ <td>{{ media_entry.get_actor.username }}</td>
<td><a href="{{ media_entry.url_for_self(request.urlgen) }}">{{ media_entry.title }}</a></td>
<td><span title='{{ media_entry.created.strftime("%F %R") }}'>{{ timesince(media_entry.created) }}</span></td>
</tr>
{% trans %}Reported comment{% endtrans %}:
{% set comment = report.comment %}
- {% set reported_user = comment.get_author %}
+ {% set reported_user = comment.get_actor %}
<div id="comment-{{ comment.id }}"
class="comment_wrapper">
<div class="comment_author">
<img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
<a href="{{ request.urlgen('mediagoblin.moderation.users_detail',
- user=comment.get_author.username) }}"
+ user=comment.get_actor.username) }}"
class="comment_authorlink">
{{- reported_user.username -}}
</a>
<a href="{{ request.urlgen(
'mediagoblin.user_pages.media_home.view_comment',
comment=comment.id,
- user=comment.get_media_entry.get_uploader.username,
+ user=comment.get_media_entry.get_actor.username,
media=comment.get_media_entry.slug_or_id) }}#comment"
class="comment_whenlink">
<span title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
{% set media_entry = report.media_entry %}
<div class="three columns media_thumbnail">
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
- user=media_entry.get_uploader.username,
+ user=media_entry.get_actor.username,
media=media_entry.slug_or_id) }}">
<img src="{{ media_entry.thumb_url}}"/></a>
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
- user=media_entry.get_uploader.username,
+ user=media_entry.get_actor.username,
media=media_entry.slug_or_id) }}" class=thumb_entry_title>
{{ media_entry.title }}</a>
</div>
{{ report.report_content }}
</div>
</div>
- {% if not report.is_archived_report() and
- not (report.reported_user.has_privilege('admin') and
+ {% if not report.is_archived_report() and
+ not (report.reported_user.has_privilege('admin') and
not request.user.has_privilege('admin')) %}
<input type=button class="button_action" value="{% trans %}Resolve{% endtrans %}" id=open_resolution_form />
<form action="" method="POST" id=resolution_form>
{% if request.user and
(media.uploader == request.user.id or
request.user.has_privilege('admin')) %}
- {% set edit_url = request.urlgen('mediagoblin.media_types.blog.blogpost.edit',
- blog_slug=media.media_manager.get_blog_by_blogpost().slug,
+ {% set edit_url = request.urlgen('mediagoblin.media_types.blog.blogpost.edit',
+ blog_slug=media.media_manager.get_blog_by_blogpost().slug,
user=request.user.username, blog_post_slug=media.slug) %}
<a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
{% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
{% endif %}
<ul style="list-style:none">
{% for comment in comments %}
- {% set comment_author = comment.get_author %}
+ {% set comment_author = comment.get_actor %}
<li id="comment-{{ comment.id }}"
{%- if pagination.active_id == comment.id %}
class="comment_wrapper comment_active">
<div class="media_sidebar">
<h3>{% trans %}Added{% endtrans %}</h3>
<p><span title="{{ media.created.strftime("%I:%M%p %Y-%m-%d") }}">
- {%- trans formatted_time=timesince(media.created) -%}
+ {%- trans formatted_time=timesince(media.created) -%}
{{ formatted_time }} ago
{%- endtrans -%}
</span></p>
{{ collection_title }} by <a href="{{ user_url }}">{{ username }}</a>
{%- endtrans %}
</h1>
- {% if request.user and (collection.creator == request.user.id or
+ {% if request.user and (collection.actor == request.user.id or
request.user.has_privilege('admin')) %}
{% set edit_url = request.urlgen('mediagoblin.edit.edit_collection',
- user=collection.get_creator.username,
+ user=collection.get_actor.username,
collection=collection.slug) %}
<a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
{% set delete_url = request.urlgen('mediagoblin.user_pages.collection_confirm_delete',
- user=collection.get_creator.username,
+ user=collection.get_actor.username,
collection=collection.slug) %}
<a class="button_action" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.user_pages.collection_confirm_delete',
- user=collection.get_creator.username,
+ user=collection.get_actor.username,
collection=collection.slug) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box">
Really delete collection: {{ title }}?
{%- endtrans %}
</h1>
-
+
<br />
-
+
<p class="delete_checkbox_box">
{{ form.confirm }}
{{ wtforms_util.render_label(form.confirm) }}
</div>
</div>
</form>
-{% endblock %}
+{% endblock %}
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
{% block title %}
- {%- trans media_title=collection_item.get_media_entry.title,
+ {%- trans media_title=collection_item.get_object().title,
collection_title=collection_item.in_collection.title -%}
Remove {{ media_title }} from {{ collection_title }}
{%- endtrans %} — {{ super() }}
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.user_pages.collection_item_confirm_remove',
- user=collection_item.in_collection.get_creator.username,
+ user=collection_item.in_collection.get_actor.username,
collection=collection_item.in_collection.slug,
collection_item=collection_item.id) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box">
<h1>
- {%- trans media_title=collection_item.get_media_entry.title,
+ {%- trans media_title=collection_item.get_object().title,
collection_title=collection_item.in_collection.title -%}
Really remove {{ media_title }} from {{ collection_title }}?
{%- endtrans %}
</h1>
<div style="text-align: center;" >
- <img src="{{ collection_item.get_media_entry.thumb_url }}" />
+ <img src="{{ collection_item.get_object().thumb_url }}" />
</div>
<br />
</div>
</div>
</form>
-{% endblock %}
+{% endblock %}
<p class="eleven columns context">
{%- trans user_url=request.urlgen(
'mediagoblin.user_pages.user_home',
- user=media.get_uploader.username),
- username=media.get_uploader.username -%}
+ user=media.get_actor.username),
+ username=media.get_actor.username -%}
❖ Browsing media by <a href="{{user_url}}">{{username}}</a>
{%- endtrans -%}
</p>
{{ media.title }}
</h2>
{% if request.user and
- (media.uploader == request.user.id or
+ (media.actor == request.user.id or
request.user.has_privilege('admin')) %}
<div class="pull-right" style="padding-top:20px;">
{% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
- user= media.get_uploader.username,
+ user= media.get_actor.username,
media_id=media.id) %}
<a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
{% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
- user= media.get_uploader.username,
+ user= media.get_actor.username,
media_id=media.id) %}
<a class="button_action button_warning" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
</div>
{% endif %}
{% if request.user %}
<form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment',
- user= media.get_uploader.username,
+ user= media.get_actor.username,
media_id=media.id) }}" method="POST" id="form_comment">
{{ wtforms_util.render_divs(comment_form) }}
<div class="form_submit_buttons">
{% endif %}
<ul style="list-style:none">
{% for comment in comments %}
- {% set comment_author = comment.get_author %}
+ {% set comment_author = comment.get_actor %}
<li id="comment-{{ comment.id }}"
{%- if pagination.active_id == comment.id %}
class="comment_wrapper comment_active">
</a>
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
comment=comment.id,
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}#comment"
class="comment_whenlink">
<span title='{{- comment.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
<div>
{% if app_config.allow_reporting %}
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.report_comment',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id,
comment=comment.id) }}">
{% trans %}Report{% endtrans %}</a>
{%- endif %}
{%- if app_config['allow_attachments']
and request.user
- and (media.uploader == request.user.id
+ and (media.actor == request.user.id
or request.user.has_privilege('admin')) %}
{%- if not media.attachment_files|count %}
<h3>{% trans %}Attachments{% endtrans %}</h3>
{%- endif %}
<p>
<a href="{{ request.urlgen('mediagoblin.edit.attachments',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media_id=media.id) }}">
{%- trans %}Add attachment{% endtrans -%}
</a>
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.user_pages.media_collect',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media_id=media.id) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box">
</div>
</div>
</form>
-{% endblock %}
+{% endblock %}
{% block mediagoblin_content %}
<form action="{{ request.urlgen('mediagoblin.user_pages.media_confirm_delete',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media_id=media.id) }}"
method="POST" enctype="multipart/form-data">
<div class="form_box">
</div>
</div>
</form>
-{% endblock %}
+{% endblock %}
<form action="" method=POST >
{% if comment is defined %}
<h3>{% trans %}Reporting this Comment{% endtrans %}</h3>
- {%- set comment_author = comment.get_author %}
+ {%- set comment_author = comment.get_actor %}
{%- set comment_author_url = request.urlgen(
'mediagoblin.user_pages.user_home',
user=comment_author.username) %}
{%- set comment_url = request.urlgen(
'mediagoblin.user_pages.media_home.view_comment',
comment=comment.id,
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) %}
<div id="comment-{{ comment.id }}"
class="comment_wrapper">
<h3>{% trans %}Reporting this Media Entry{% endtrans %}</h3>
<div class="media_thumbnail">
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}">
<img src="{{ media.thumb_url }}"/></a>
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}"
class=thumb_entry_title>{{ media.title }}</a>
</div>
<div class=clear></div>
- {%- trans user_url = request.urlgen('mediagoblin.user_pages.user_home', user=media.get_uploader.username),
- username = media.get_uploader.username %}
+ {%- trans user_url = request.urlgen('mediagoblin.user_pages.user_home', user=media.get_actor.username),
+ username = media.get_actor.username %}
❖ Published by <a href="{{ user_url }}"
class="comment_authorlink">{{ username }}</a>
{% endtrans %}
{%- if loop.first %} thumb_row_first
{%- elif loop.last %} thumb_row_last{% endif %}">
{% for item in row %}
- {% set media_entry = item.get_media_entry %}
- {% set entry_url = media_entry.url_for_self(request.urlgen) %}
+ {% set obj = item.get_object() %}
+ {% set obj_url = obj.url_for_self(request.urlgen) %}
<div class="three columns media_thumbnail thumb_entry
{%- if loop.first %} thumb_entry_first
{%- elif loop.last %} thumb_entry_last{% endif %}">
- <a href="{{ entry_url }}">
- <img src="{{ media_entry.thumb_url }}" />
+ <a href="{{ obj_url }}">
+ <img src="{{ obj.thumb_url }}" />
</a>
{% if item.note %}
- <a href="{{ entry_url }}">{{ item.note }}</a>
+ <a href="{{ obj_url }}">{{ item.note }}</a>
{% endif %}
{% if request.user and
- (item.in_collection.creator == request.user.id or
+ (item.in_collection.actor == request.user.id or
request.user.has_privilege('admin')) %}
{%- set remove_url=request.urlgen(
'mediagoblin.user_pages.collection_item_confirm_remove',
- user=item.in_collection.get_creator.username,
+ user=item.in_collection.get_actor.username,
collection=item.in_collection.slug,
collection_item=item.id) -%}
<a href="{{ remove_url }}" class="remove">
{%- endif %}
<a href="{{ collection.url_for_self(request.urlgen) }}">
{{- collection.title }} (
- {{- collection.get_creator.username -}}
+ {{- collection.get_actor.username -}}
)</a>
{%- endfor %}
</p>
{%- endif %}
{%- if request.user %}
<p>
- <a type="submit" href="{{ request.urlgen('mediagoblin.user_pages.media_collect',
- user=media.get_uploader.username,
+ <a type="submit" href="{{ request.urlgen('mediagoblin.user_pages.media_collect',
+ user=media.get_actor.username,
media_id=media.id) }}"
class="button_action">
{% trans %}Add to a collection{% endtrans %}
{% set subscription = get_comment_subscription(request.user.id, media.id) %}
{% if not subscription or not subscription.notify %}
<a type="submit" href="{{ request.urlgen('mediagoblin.notifications.subscribe_comments',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id)}}"
class="button_action">{% trans %}Subscribe to comments{% endtrans %}
</a>
{% else %}
<a type="submit" href="{{ request.urlgen('mediagoblin.notifications.silence_comments',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id)}}"
class="button_action">{% trans %}Silence comments{% endtrans %}
</a>
{% block report_content -%}
<p>
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.report_media',
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id) }}"
class="button_action" id="button_reportmedia" title="Report media">
{% trans %}Report media{% endtrans %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.user_tag_gallery',
tag=tag['slug'],
- user=media.get_uploader.username) }}">{{ tag['name'] }}</a>
+ user=media.get_actor.username) }}">{{ tag['name'] }}</a>
{% elif loop.revindex == 2 %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.user_tag_gallery',
tag=tag['slug'],
- user=media.get_uploader.username) }}">{{ tag['name'] }}</a>
+ user=media.get_actor.username) }}">{{ tag['name'] }}</a>
{% else %}
<a href="{{ request.urlgen(
'mediagoblin.user_pages.user_tag_gallery',
tag=tag['slug'],
- user=media.get_uploader.username) }}">{{ tag['name'] }}</a>
+ user=media.get_actor.username) }}">{{ tag['name'] }}</a>
·
{% endif %}
{% endfor %}
# and self._upload_image.
id = int(data["object"]["id"].split("/")[-2])
media = MediaEntry.query.filter_by(id=id).first()
- media.uploader = self.other_user.id
+ media.actor = self.other_user.id
media.save()
# Now lets try and edit the image as self.user, this should produce a 403 error.
comment = media.get_comments()[0]
# Tests that it matches in the database
- assert comment.author == self.user.id
+ assert comment.actor == self.user.id
assert comment.content == content
# Test that the response is what we should be given
# change who uploaded the comment as it's easier than changing
comment_id = int(comment_data["object"]["id"].split("/")[-2])
comment = MediaComment.query.filter_by(id=comment_id).first()
- comment.author = self.other_user.id
+ comment.actor = self.other_user.id
comment.save()
# Update the comment as someone else.
model = MediaComment.query.filter_by(id=comment_id).first()
assert model.content == activity["object"]["content"]
-
for m_id in (media_a.id, media_b.id):
cmt = MediaComment()
cmt.media_entry = m_id
- cmt.author = u_id
+ cmt.actor = u_id
cmt.content = u"Some Comment"
Session.add(cmt)
entry.title = title or u"Some title"
entry.slug = slug
entry.id = this_id
- entry.uploader = uploader or self.chris_user.id
+ entry.actor = uploader or self.chris_user.id
entry.media_type = u'image'
if save:
fixture_add_comment(author=self.user.id,
comment=u'Comment will be removed')
test_comment = MediaComment.query.filter(
- MediaComment.author==self.user.id).first()
+ MediaComment.actor==self.user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=self.user)
comment_report = CommentReport.query.filter(
UserBan.user_id == self.user.id).first()
assert test_user_ban is not None
test_comment = MediaComment.query.filter(
- MediaComment.author==self.user.id).first()
+ MediaComment.actor==self.user.id).first()
assert test_comment is None
# Then, test what happens when a moderator attempts to punish an admin
assert type(notification) == CommentNotification
assert notification.seen == False
assert notification.user_id == user.id
- assert notification.subject.get_author.id == self.test_user.id
+ assert notification.subject.get_actor.id == self.test_user.id
assert notification.subject.content == u'Test comment #42'
if wants_email == True:
fixture_add_comment(author=allie_user.id,
comment=u'Comment will be removed')
test_comment = MediaComment.query.filter(
- MediaComment.author==allie_user.id).first()
+ MediaComment.actor==allie_user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=allie_user,
report_content=u'Testing Archived Reports #1',
natalie banned user allie indefinitely.
natalie deleted the comment.'''
assert archived_report.discriminator == 'comment_report'
-
def fixture_comment_subscription(entry, notify=True, send_email=None):
if send_email is None:
- uploader = LocalUser.query.filter_by(id=entry.uploader).first()
- send_email = uploader.wants_comment_notification
+ actor = LocalUser.query.filter_by(id=entry.actor).first()
+ send_email = actor.wants_comment_notification
cs = CommentSubscription(
media_entry_id=entry.id,
- user_id=entry.uploader,
+ user_id=entry.actor,
notify=notify,
send_email=send_email)
entry = MediaEntry()
entry.title = title
entry.slug = slug
- entry.uploader = uploader
+ entry.actor = uploader
entry.media_type = u'image'
entry.state = state
return entry
-def fixture_add_collection(name=u"My first Collection", user=None):
+def fixture_add_collection(name=u"My first Collection", user=None,
+ collection_type=Collection.USER_DEFINED_TYPE):
if user is None:
user = fixture_add_user()
- coll = Collection.query.filter_by(creator=user.id, title=name).first()
+ coll = Collection.query.filter_by(
+ actor=user.id,
+ title=name,
+ type=collection_type
+ ).first()
if coll is not None:
return coll
coll = Collection()
- coll.creator = user.id
+ coll.actor = user.id
coll.title = name
+ coll.type = collection_type
coll.generate_slug()
coll.save()
'Auto-generated test comment by user #{0} on media #{0}'.format(
author, media_entry)
- comment = MediaComment(author=author,
+ comment = MediaComment(actor=author,
media_entry=media_entry,
content=comment)
activity.set_target(target)
activity.save()
- return activity
\ No newline at end of file
+ return activity
comment_url = request.urlgen(
'mediagoblin.user_pages.media_home.view_comment',
comment=comment.id,
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id,
qualified=True) + '#comment'
- comment_author = comment.get_author.username
+ comment_author = comment.get_actor.username
rendered_email = render_template(
request, 'mediagoblin/user_pages/comment_email.txt',
def add_media_to_collection(collection, media, note=None, commit=True):
collection_item = CollectionItem()
collection_item.collection = collection.id
- collection_item.media_entry = media.id
+ collection_item.get_object = media
if note:
collection_item.note = note
Session.add(collection_item)
- collection.items = collection.items + 1
+ collection.num_items = collection.num_items + 1
Session.add(collection)
Session.add(media)
report_object = CommentReport()
report_object.comment_id = comment.id
report_object.reported_user_id = MediaComment.query.get(
- comment.id).get_author.id
+ comment.id).get_actor.id
elif report_form.validate() and media_entry is not None:
report_object = MediaReport()
report_object.media_entry_id = media_entry.id
report_object.reported_user_id = MediaEntry.query.get(
- media_entry.id).get_uploader.id
+ media_entry.id).get_actor.id
else:
return None
{'user': user})
cursor = MediaEntry.query.\
- filter_by(uploader = user.id,
+ filter_by(actor = user.id,
state = u'processed').order_by(MediaEntry.created.desc())
pagination = Pagination(page, cursor)
"""'Gallery' of a LocalUser()"""
tag = request.matchdict.get('tag', None)
cursor = MediaEntry.query.filter_by(
- uploader=url_user.id,
+ actor=url_user.id,
state=u'processed').order_by(MediaEntry.created.desc())
# Filter potentially by tag too:
comment = request.db.MediaComment()
comment.media_entry = media.id
- comment.author = request.user.id
+ comment.actor = request.user.id
comment.content = six.text_type(request.form['comment_content'])
# Show error message if commenting is disabled.
messages.ERROR,
_("Oops, your comment was empty."))
else:
- create_activity("post", comment, comment.author, target=media)
+ create_activity("post", comment, comment.actor, target=media)
add_comment_subscription(request.user, media)
comment.save()
form = user_forms.MediaCollectForm(request.form)
# A user's own collections:
form.collection.query = Collection.query.filter_by(
- creator = request.user.id).order_by(Collection.title)
+ actor=request.user.id,
+ type=Collection.USER_DEFINED_TYPE
+ ).order_by(Collection.title)
if request.method != 'POST' or not form.validate():
# No POST submission, or invalid form
if form.collection_title.data:
# Make sure this user isn't duplicating an existing collection
existing_collection = Collection.query.filter_by(
- creator=request.user.id,
- title=form.collection_title.data).first()
+ actor=request.user.id,
+ title=form.collection_title.data,
+ type=Collection.USER_DEFINED_TYPE
+ ).first()
if existing_collection:
messages.add_message(request, messages.ERROR,
_('You already have a collection called "%s"!')
% existing_collection.title)
return redirect(request, "mediagoblin.user_pages.media_home",
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media=media.slug_or_id)
collection = Collection()
collection.title = form.collection_title.data
collection.description = form.collection_description.data
- collection.creator = request.user.id
+ collection.actor = request.user.id
+ collection.type = Collection.USER_DEFINED_TYPE
collection.generate_slug()
- create_activity("create", collection, collection.creator)
+ create_activity("create", collection, collection.actor)
collection.save()
# Otherwise, use the collection selected from the drop-down
else:
collection = form.collection.data
- if collection and collection.creator != request.user.id:
+ if collection and collection.actor != request.user.id:
collection = None
# Make sure the user actually selected a collection
+ item = CollectionItem.query.filter_by(collection=collection.id)
+ item = item.join(CollectionItem.object_helper).filter_by(
+ model_type=media.__tablename__,
+ obj_pk=media.id
+ ).first()
+
if not collection:
messages.add_message(
request, messages.ERROR,
_('You have to select or add a collection'))
return redirect(request, "mediagoblin.user_pages.media_collect",
- user=media.get_uploader.username,
+ user=media.get_actor.username,
media_id=media.id)
-
# Check whether media already exists in collection
- elif CollectionItem.query.filter_by(
- media_entry=media.id,
- collection=collection.id).first():
+ elif item is not None:
messages.add_message(request, messages.ERROR,
_('"%s" already in collection "%s"')
% (media.title, collection.title))
if request.method == 'POST' and form.validate():
if form.confirm.data is True:
- username = media.get_uploader.username
+ username = media.get_actor.username
- media.get_uploader.uploaded = media.get_uploader.uploaded - \
+ media.get_actor.uploaded = media.get_actor.uploaded - \
media.file_size
- media.get_uploader.save()
+ media.get_actor.save()
# Delete MediaEntry and all related files, comments etc.
media.delete()
return redirect_obj(request, media)
if ((request.user.has_privilege(u'admin') and
- request.user.id != media.uploader)):
+ request.user.id != media.actor)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete another user's media. "
def user_collection(request, page, url_user=None):
"""A User-defined Collection"""
collection = Collection.query.filter_by(
- get_creator=url_user,
+ get_actor=url_user,
slug=request.matchdict['collection']).first()
if not collection:
def collection_list(request, url_user=None):
"""A User-defined Collection"""
collections = Collection.query.filter_by(
- get_creator=url_user)
+ get_actor=url_user)
return render_to_response(
request,
form = user_forms.ConfirmCollectionItemRemoveForm(request.form)
if request.method == 'POST' and form.validate():
- username = collection_item.in_collection.get_creator.username
+ username = collection_item.in_collection.get_actor.username
collection = collection_item.in_collection
if form.confirm.data is True:
- entry = collection_item.get_media_entry
- entry.save()
+ obj = collection_item.get_object()
+ obj.save()
collection_item.delete()
- collection.items = collection.items - 1
+ collection.num_items = collection.num_items - 1
collection.save()
messages.add_message(
return redirect_obj(request, collection)
if ((request.user.has_privilege(u'admin') and
- request.user.id != collection_item.in_collection.creator)):
+ request.user.id != collection_item.in_collection.actor)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete an item from another user's collection. "
if request.method == 'POST' and form.validate():
- username = collection.get_creator.username
+ username = collection.get_actor.username
if form.confirm.data is True:
collection_title = collection.title
# Delete all the associated collection items
for item in collection.get_collection_items():
- entry = item.get_media_entry
- entry.save()
+ obj = item.get_object()
+ obj.save()
item.delete()
collection.delete()
return redirect_obj(request, collection)
if ((request.user.has_privilege(u'admin') and
- request.user.id != collection.creator)):
+ request.user.id != collection.actor)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete another user's collection. "
return render_404(request)
cursor = MediaEntry.query.filter_by(
- uploader = user.id,
+ actor = user.id,
state = u'processed').\
order_by(MediaEntry.created.desc()).\
limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
links=atomlinks)
for entry in cursor:
- feed.add(entry.get('title'),
+ feed.add(
+ entry.get('title'),
entry.description_html,
id=entry.url_for_self(request.urlgen, qualified=True),
content_type='html',
author={
- 'name': entry.get_uploader.username,
+ 'name': entry.get_actor.username,
'uri': request.urlgen(
'mediagoblin.user_pages.user_home',
- qualified=True, user=entry.get_uploader.username)},
+ qualified=True, user=entry.get_actor.username)},
updated=entry.get('created'),
links=[{
'href': entry.url_for_self(
return render_404(request)
collection = Collection.query.filter_by(
- creator=user.id,
+ actor=user.id,
slug=request.matchdict['collection']).first()
if not collection:
return render_404(request)
links=atomlinks)
for item in cursor:
- entry = item.get_media_entry
- feed.add(entry.get('title'),
+ obj = item.get_object()
+ feed.add(
+ obj.get('title'),
item.note_html,
- id=entry.url_for_self(request.urlgen, qualified=True),
+ id=obj.url_for_self(request.urlgen, qualified=True),
content_type='html',
author={
- 'name': entry.get_uploader.username,
+ 'name': obj.get_actor().username,
'uri': request.urlgen(
'mediagoblin.user_pages.user_home',
- qualified=True, user=entry.get_uploader.username)},
+ qualified=True, user=obj.get_actor().username)},
updated=item.get('added'),
links=[{
- 'href': entry.url_for_self(
+ 'href': obj.url_for_self(
request.urlgen,
qualified=True),
'rel': 'alternate',
# Get media entries which are in-processing
processing_entries = MediaEntry.query.\
- filter_by(uploader = user.id,
+ filter_by(actor = user.id,
state = u'processing').\
order_by(MediaEntry.created.desc())
# Get media entries which have failed to process
failed_entries = MediaEntry.query.\
- filter_by(uploader = user.id,
+ filter_by(actor = user.id,
state = u'failed').\
order_by(MediaEntry.created.desc())
processed_entries = MediaEntry.query.\
- filter_by(uploader = user.id,
+ filter_by(actor = user.id,
state = u'processed').\
order_by(MediaEntry.created.desc()).\
limit(10)
"mediagoblin/api/activity.html",
{"activity": activity}
)
-